-
-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathDefaultMediaDevices.cs
More file actions
43 lines (36 loc) · 1.38 KB
/
DefaultMediaDevices.cs
File metadata and controls
43 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
namespace BootstrapBlazor.Components;
class DefaultMediaDevices(IJSRuntime jsRuntime) : IMediaDevices
{
private DotNetObjectReference<DefaultMediaDevices>? _interop = null;
private JSModule? _module = null;
private async Task<JSModule> LoadModule()
{
_interop ??= DotNetObjectReference.Create(this);
_module ??= await jsRuntime.LoadModuleByName("media");
return _module;
}
public async Task<IEnumerable<IMediaDeviceInfo>?> EnumerateDevices()
{
var module = await LoadModule();
return await module.InvokeAsync<List<MediaDeviceInfo>?>("enumerateDevices");
}
public async Task Open(MediaTrackConstraints constraints)
{
var module = await LoadModule();
await module.InvokeVoidAsync("open", constraints);
}
public async Task Close(string selector)
{
var module = await LoadModule();
await module.InvokeVoidAsync("close", selector);
}
public async Task Capture(string selector)
{
var module = await LoadModule();
await module.InvokeVoidAsync("capture", selector);
}
}