-
-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathDefaultMediaDevices.cs
More file actions
53 lines (44 loc) · 1.53 KB
/
DefaultMediaDevices.cs
File metadata and controls
53 lines (44 loc) · 1.53 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
44
45
46
47
48
49
50
51
52
53
// 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 JSModule? _module = null;
private async Task<JSModule> LoadModule()
{
_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? videoSelector)
{
var module = await LoadModule();
await module.InvokeVoidAsync("close", videoSelector);
}
public async Task Capture()
{
var module = await LoadModule();
await module.InvokeVoidAsync("capture");
}
public async Task<string?> GetPreviewUrl()
{
var module = await LoadModule();
return await module.InvokeAsync<string?>("getPreviewUrl");
}
public async Task Flip()
{
var module = await LoadModule();
await module.InvokeAsync<string?>("flip");
}
}