File tree Expand file tree Collapse file tree 5 files changed +25
-16
lines changed Expand file tree Collapse file tree 5 files changed +25
-16
lines changed Original file line number Diff line number Diff line change @@ -27,10 +27,10 @@ public async Task<bool> Open(MediaTrackConstraints constraints)
2727 return await module . InvokeAsync < bool > ( "open" , constraints ) ;
2828 }
2929
30- public async Task Close ( string ? videoSelector )
30+ public async Task < bool > Close ( string ? videoSelector )
3131 {
3232 var module = await LoadModule ( ) ;
33- await module . InvokeVoidAsync ( "close" , videoSelector ) ;
33+ return await module . InvokeAsync < bool > ( "close" , videoSelector ) ;
3434 }
3535
3636 public async Task Capture ( )
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public Task<bool> Open(MediaTrackConstraints constraints)
2727 return deviceService . Open ( constraints ) ;
2828 }
2929
30- public Task Close ( string ? videoSelector )
30+ public Task < bool > Close ( string ? videoSelector )
3131 {
3232 return deviceService . Close ( videoSelector ) ;
3333 }
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public interface IMediaDevices
2828 /// </summary>
2929 /// <param name="videoSelector"></param>
3030 /// <returns></returns>
31- Task Close ( string ? videoSelector ) ;
31+ Task < bool > Close ( string ? videoSelector ) ;
3232
3333 /// <summary>
3434 /// The capture() method of the MediaDevices interface captures a still image from the specified video stream and saves it to the specified location.
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public interface IVideoDevice
2828 /// </summary>
2929 /// <param name="videoSelector"></param>
3030 /// <returns></returns>
31- Task Close ( string ? videoSelector ) ;
31+ Task < bool > Close ( string ? videoSelector ) ;
3232
3333 /// <summary>
3434 /// Capture a still image from the video stream.
Original file line number Diff line number Diff line change @@ -51,21 +51,30 @@ export async function open(options) {
5151}
5252
5353export async function close ( videoSelector ) {
54- if ( videoSelector ) {
55- const video = document . querySelector ( videoSelector ) ;
56- if ( video ) {
57- video . pause ( ) ;
58- const stream = video . srcObject ;
54+ let ret = false ;
55+
56+ try {
57+ if ( videoSelector ) {
58+ const video = document . querySelector ( videoSelector ) ;
59+ if ( video ) {
60+ video . pause ( ) ;
61+ const stream = video . srcObject ;
62+ closeStream ( stream ) ;
63+ video . srcObject = null ;
64+ }
65+ }
66+ const media = registerBootstrapBlazorModule ( "MediaDevices" ) ;
67+ const { stream } = media ;
68+ if ( stream && stream . active ) {
5969 closeStream ( stream ) ;
60- video . srcObject = null ;
6170 }
71+ media . stream = null ;
72+ ret = true ;
6273 }
63- const media = registerBootstrapBlazorModule ( "MediaDevices" ) ;
64- const { stream } = media ;
65- if ( stream && stream . active ) {
66- closeStream ( stream ) ;
74+ catch ( err ) {
75+ console . error ( "Error closing media devices." , err ) ;
6776 }
68- media . stream = null ;
77+ return ret ;
6978}
7079
7180export async function getPreviewUrl ( ) {
You can’t perform that action at this time.
0 commit comments