| | 1 | | using System; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Interface; |
| | 4 | | using JetBrains.Annotations; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Services |
| | 8 | | { |
| | 9 | | public class WebBrowserAudioDevicesBridge : MonoBehaviour, IAudioDevicesBridge |
| | 10 | | { |
| | 11 | | public event Action<AudioDevicesResponse> OnAudioDevicesRecieved; |
| | 12 | |
|
| | 13 | | public static WebBrowserAudioDevicesBridge GetOrCreate() |
| | 14 | | { |
| 425 | 15 | | GameObject brigeGO = SceneReferences.i?.bridgeGameObject; |
| 425 | 16 | | if (SceneReferences.i?.bridgeGameObject == null) |
| 424 | 17 | | return new GameObject("Bridge").AddComponent<WebBrowserAudioDevicesBridge>(); |
| | 18 | |
|
| 1 | 19 | | return brigeGO.GetOrCreateComponent<WebBrowserAudioDevicesBridge>(); |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public void RequestAudioDevices() => |
| 0 | 23 | | WebInterface.RequestAudioDevices(); |
| | 24 | |
|
| | 25 | | [PublicAPI] |
| | 26 | | public void SetAudioDevices(string payload) |
| | 27 | | { |
| 0 | 28 | | AudioDevicesResponse response = null; |
| | 29 | |
|
| | 30 | | try |
| | 31 | | { |
| 0 | 32 | | response = JsonUtility.FromJson<AudioDevicesResponse>(payload); |
| 0 | 33 | | } |
| 0 | 34 | | catch (Exception e) |
| | 35 | | { |
| 0 | 36 | | Debug.LogError($"Fail to parse audio devices json {e}"); |
| 0 | 37 | | } |
| | 38 | |
|
| 0 | 39 | | if (response == null) |
| 0 | 40 | | return; |
| | 41 | |
|
| 0 | 42 | | OnAudioDevicesRecieved?.Invoke(response); |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | | } |