|
@@ -1,4 +1,5 @@
|
|
|
-using System;
|
|
|
+using RtcUtil;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
@@ -11,12 +12,14 @@ using WebRtc.NET;
|
|
|
namespace VRTC.WpfClient
|
|
|
{
|
|
|
class MainWindowViewModel : ViewModel
|
|
|
- {
|
|
|
+ {
|
|
|
private string _hostUrl;
|
|
|
private uint _roomId;
|
|
|
private string _userId;
|
|
|
private VRTCClient _client;
|
|
|
private readonly Action<Action> _runOnMainDispatcher;
|
|
|
+ private bool _audioEnabled;
|
|
|
+ private string _defaultVideoDevice;
|
|
|
|
|
|
public ButtonCommand ConnectCommand { get; set; }
|
|
|
|
|
@@ -60,7 +63,7 @@ namespace VRTC.WpfClient
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
//private List<SequenceExecutor<int>> _sequenceExecutors = new List<SequenceExecutor<int>>();
|
|
|
/// <summary>
|
|
|
/// Request window close
|
|
@@ -93,6 +96,34 @@ namespace VRTC.WpfClient
|
|
|
|
|
|
public ObservableCollection<VideoViewModel> RemoteVideos { get; }
|
|
|
|
|
|
+ public IList<string> VideoDevices { get; }
|
|
|
+
|
|
|
+ public string DefaultVideoDevice
|
|
|
+ {
|
|
|
+ get => _defaultVideoDevice;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (_defaultVideoDevice != value)
|
|
|
+ {
|
|
|
+ _defaultVideoDevice = value;
|
|
|
+ OnPropertyChanged(()=>DefaultVideoDevice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool AudioEnabled
|
|
|
+ {
|
|
|
+ get { return _audioEnabled; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if (_audioEnabled != value)
|
|
|
+ {
|
|
|
+ _audioEnabled = value;
|
|
|
+ OnPropertyChanged(() => AudioEnabled);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public MainWindowViewModel(Action<Action> runOnMainDispatcher)
|
|
|
{
|
|
|
LogItems = new ObservableCollection<LogItem>();
|
|
@@ -111,40 +142,43 @@ namespace VRTC.WpfClient
|
|
|
LocalVideo = new VideoViewModel();
|
|
|
RemoteVideos = new ObservableCollection<VideoViewModel>();
|
|
|
this._runOnMainDispatcher = runOnMainDispatcher;
|
|
|
+ VideoDevices = MediaDevices.EnumerateVideoDevices();
|
|
|
+ DefaultVideoDevice = VideoDevices.FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
private void OnExit(object obj)
|
|
|
{
|
|
|
- if(_client!= null)
|
|
|
+ if (_client != null)
|
|
|
{
|
|
|
_client.LocalVideoFrameReceived -= OnRenderLocal;
|
|
|
_client.RemoteVieoFrameReceived -= OnRendRemote;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
_client?.Dispose();
|
|
|
_client = null;
|
|
|
}
|
|
|
|
|
|
private async void OnConnect(object obj)
|
|
|
{
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
var device = ManagedConductor.GetVideoDevices().First();
|
|
|
_client = new VRTCClient(device);
|
|
|
-
|
|
|
+
|
|
|
await _client.Connect(HostUrl, RoomId, UserId, false);
|
|
|
_client.LocalVideoFrameReceived += OnRenderLocal;
|
|
|
_client.RemoteVieoFrameReceived += OnRendRemote;
|
|
|
}
|
|
|
catch (Exception ex) { Logger.WriteLineError($"OnConnect ex:{ex}"); }
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void OnRendRemote(object? sender, VideoFrameData e)
|
|
|
{
|
|
|
- var videoVm = RemoteVideos.FirstOrDefault(x=>x.Id == e.ClientId);
|
|
|
+ var videoVm = RemoteVideos.FirstOrDefault(x => x.Id == e.ClientId);
|
|
|
if (videoVm == null)
|
|
|
{
|
|
|
- videoVm = new VideoViewModel() { Id = e.ClientId};
|
|
|
+ videoVm = new VideoViewModel() { Id = e.ClientId };
|
|
|
_runOnMainDispatcher?.Invoke(() => { RemoteVideos.Add(videoVm); });
|
|
|
}
|
|
|
videoVm.OnFrameReceived(this, e);
|
|
@@ -170,7 +204,7 @@ namespace VRTC.WpfClient
|
|
|
|
|
|
|
|
|
private void OnCloseCommand(object obj)
|
|
|
- {
|
|
|
+ {
|
|
|
OnRequestClosed();
|
|
|
}
|
|
|
|