File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ private async Task<JSModule> LoadModule()
2121 return await module . InvokeAsync < List < MediaDeviceInfo > ? > ( "enumerateDevices" ) ;
2222 }
2323
24- public async Task Open ( MediaTrackConstraints constraints )
24+ public async Task < bool > Open ( MediaTrackConstraints constraints )
2525 {
2626 var module = await LoadModule ( ) ;
27- await module . InvokeVoidAsync ( "open" , constraints ) ;
27+ return await module . InvokeAsync < bool > ( "open" , constraints ) ;
2828 }
2929
3030 public async Task Close ( string ? videoSelector )
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class DefaultVideoDevice(IMediaDevices deviceService) : IVideoDevice
2222 return ret ;
2323 }
2424
25- public Task Open ( MediaTrackConstraints constraints )
25+ public Task < bool > Open ( MediaTrackConstraints constraints )
2626 {
2727 return deviceService . Open ( constraints ) ;
2828 }
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public interface IMediaDevices
2121 /// </summary>
2222 /// <param name="constraints"></param>
2323 /// <returns></returns>
24- Task Open ( MediaTrackConstraints constraints ) ;
24+ Task < bool > Open ( MediaTrackConstraints constraints ) ;
2525
2626 /// <summary>
2727 /// The close() method of the MediaDevices interface stops capturing media from the specified device and closes the MediaStream object.
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public interface IVideoDevice
2121 /// </summary>
2222 /// <param name="constraints"></param>
2323 /// <returns></returns>
24- Task Open ( MediaTrackConstraints constraints ) ;
24+ Task < bool > Open ( MediaTrackConstraints constraints ) ;
2525
2626 /// <summary>
2727 /// Close the video device with the specified selector.
Original file line number Diff line number Diff line change @@ -29,16 +29,25 @@ export async function open(options) {
2929 if ( height ) {
3030 constrains . video . height = { ideal : height } ;
3131 }
32- const stream = await navigator . mediaDevices . getUserMedia ( constrains ) ;
33- const media = registerBootstrapBlazorModule ( "MediaDevices" ) ;
34- media . stream = stream ;
3532
36- if ( videoSelector ) {
37- const video = document . querySelector ( videoSelector ) ;
38- if ( video ) {
39- video . srcObject = stream ;
33+ let ret = false ;
34+ try {
35+ const stream = await navigator . mediaDevices . getUserMedia ( constrains ) ;
36+ const media = registerBootstrapBlazorModule ( "MediaDevices" ) ;
37+ media . stream = stream ;
38+
39+ if ( videoSelector ) {
40+ const video = document . querySelector ( videoSelector ) ;
41+ if ( video ) {
42+ video . srcObject = stream ;
43+ }
4044 }
45+ ret = true ;
46+ }
47+ catch ( err ) {
48+ console . error ( "Error accessing media devices." , err ) ;
4149 }
50+ return ret ;
4251}
4352
4453export async function close ( videoSelector ) {
You can’t perform that action at this time.
0 commit comments