| | 1 | | using System; |
| | 2 | | using DCL.Interface; |
| | 3 | |
|
| | 4 | | namespace DCL.Services |
| | 5 | | { |
| | 6 | | public class WebBrowserAudioDevicesService : IAudioDevicesService |
| | 7 | | { |
| | 8 | | private readonly IAudioDevicesBridge bridge; |
| | 9 | |
|
| 850 | 10 | | public WebBrowserAudioDevicesService (IAudioDevicesBridge bridge) => this.bridge = bridge; |
| | 11 | | public event Action AudioDeviceCached; |
| | 12 | |
|
| 1 | 13 | | public bool HasReceivedKernelMessage { get; private set; } |
| 0 | 14 | | public AudioDevice[] InputDevices { get; private set; } |
| | 15 | |
|
| 425 | 16 | | public void Initialize() => bridge.OnAudioDevicesRecieved += CacheAudioDevices; |
| 425 | 17 | | public void Dispose() => bridge.OnAudioDevicesRecieved -= CacheAudioDevices; |
| | 18 | |
|
| | 19 | | private void CacheAudioDevices(AudioDevicesResponse devices) |
| | 20 | | { |
| 0 | 21 | | HasReceivedKernelMessage = true; |
| | 22 | |
|
| 0 | 23 | | InputDevices = devices.inputDevices; |
| | 24 | |
|
| 0 | 25 | | AudioDeviceCached?.Invoke(); |
| 0 | 26 | | } |
| | 27 | |
|
| 0 | 28 | | public void RequestAudioDevices() => bridge.RequestAudioDevices(); |
| | 29 | |
|
| | 30 | | public void SetInputDevice(int deviceId) |
| | 31 | | { |
| 0 | 32 | | if (HasReceivedKernelMessage && deviceId <= InputDevices.Length) |
| 0 | 33 | | WebInterface.SetInputAudioDevice(InputDevices[deviceId].deviceId); |
| 0 | 34 | | } |
| | 35 | | } |
| | 36 | | } |