12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Runtime.InteropServices.JavaScript;
- using System.Runtime.Versioning;
- namespace SimpleWebChat.BlazorWasm.Modules
- {
- [SupportedOSPlatform("browser")]
- public static partial class AudioCaptureModule
- {
- public static Action OnInit;
- public static Action<byte[]> ChunkArrive;
- private static JSObject _jsModule;
- public static async Task<bool> Init()
- {
- _jsModule ??= await JSHost.ImportAsync("AudioCaptureModule", $"{GlobalModule.BasePath ?? "/"}audio-capture-module.js");
- return await JsInit();
- }
- public static async Task Start() => await JsStart();
- public static async Task Stop() => await JsStop();
- [JSImport("init", "AudioCaptureModule")]
- private static partial Task<bool> JsInit();
- [JSImport("start", "AudioCaptureModule")]
- private static partial Task JsStart();
- [JSImport("stop", "AudioCaptureModule")]
- private static partial Task JsStop();
- [JSExport]
- private static void JsFeedChunk(byte[] chunk)
- {
- Console.WriteLine("chunk");
- if (ChunkArrive != null) ChunkArrive(chunk);
- }
- [JSExport]
- private static void JsInitCallBack(bool value)
- {
- if (OnInit != null) OnInit();
- }
- }
- }
|