|
1 | 1 | using System.Collections.Generic;
|
| 2 | +using System.Windows; |
2 | 3 | using XRSharp.Components;
|
3 | 4 | using XRSharp.Controls;
|
4 | 5 | using XRSharp.Primitives;
|
@@ -70,6 +71,40 @@ public class NetworkedScene : RootComponent
|
70 | 71 | /// </summary>
|
71 | 72 | public FrameworkElement3D Avatar { get; set; } = new Box { SizeX = 0.3, SizeY = 0.5, SizeZ = 0.3, Color = RandomColor.Generate() };
|
72 | 73 |
|
| 74 | + #region IsMicrophoneEnabled |
| 75 | + public bool IsMicrophoneEnabled |
| 76 | + { |
| 77 | + get => (bool)GetValue(IsMicrophoneEnabledProperty); |
| 78 | + set => SetValue(IsMicrophoneEnabledProperty, value); |
| 79 | + } |
| 80 | + |
| 81 | + public static readonly DependencyProperty IsMicrophoneEnabledProperty = |
| 82 | + DependencyProperty.Register(nameof(IsMicrophoneEnabled), typeof(bool), typeof(NetworkedScene), new PropertyMetadata(true, OnIsMicrophoneEnabledChanged)); |
| 83 | + |
| 84 | + private static void OnIsMicrophoneEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 85 | + { |
| 86 | + var component = (NetworkedScene)d; |
| 87 | + |
| 88 | + if (component.Audio && component.IsInitialized) |
| 89 | + { |
| 90 | + component.UpdateMicState(); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + private void UpdateMicState() |
| 95 | + { |
| 96 | + Interop.ExecuteJavaScriptVoid($@" |
| 97 | +if (NAF.connection.isConnected()) {{ |
| 98 | + NAF.connection.adapter.enableMicrophone({IsMicrophoneEnabled.ToLowerString()}); |
| 99 | +}} |
| 100 | +else {{ |
| 101 | + document.body.addEventListener('clientConnected', function (evt) {{ |
| 102 | + NAF.connection.adapter.enableMicrophone({IsMicrophoneEnabled.ToLowerString()}) |
| 103 | + }}); |
| 104 | +}}"); |
| 105 | + } |
| 106 | + #endregion |
| 107 | + |
73 | 108 | // todo: add onConnect, events
|
74 | 109 |
|
75 | 110 | protected override void Init()
|
@@ -120,6 +155,11 @@ protected override void Init()
|
120 | 155 | SetAvatarToCamera();
|
121 | 156 | }
|
122 | 157 | }
|
| 158 | + |
| 159 | + if (Audio) |
| 160 | + { |
| 161 | + UpdateMicState(); |
| 162 | + } |
123 | 163 | }
|
124 | 164 |
|
125 | 165 | private void SetAvatarToCamera()
|
|
0 commit comments