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 ChunkArrive; private static JSObject _jsModule; public static async Task 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 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(); } } }