116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using Agora.Rtc;
|
|
using Demo.Common.Events;
|
|
using Demo.Common.Helpers;
|
|
using Demo.Common.Models;
|
|
using Masuit.Tools;
|
|
using Meeting.V2.Demo.Core.Mvvm;
|
|
using Meeting.V2.Demo.Views;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Meeting.V2.Demo.ViewModels
|
|
{
|
|
public class VideoViewModel : ViewModelBase
|
|
{
|
|
|
|
private VideoView _view;
|
|
|
|
public VideoViewModel(IEventAggregator aggregator)
|
|
{
|
|
aggregator.GetEvent<AudioVolumeIndicationEvent>().Subscribe(SetUserVolume,
|
|
arg =>
|
|
{
|
|
return UserInfo != null && UserInfo.Id > 0 && arg.uid > 0 && arg.uid == UserInfo.Id;
|
|
});
|
|
}
|
|
|
|
public DelegateCommand<VideoView> LoadedCommand => new DelegateCommand<VideoView>((u) =>
|
|
{
|
|
if (u == null)
|
|
return;
|
|
Console.WriteLine($@"LoadedCoommand 被执行了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
this._view = u;
|
|
RenderVideoView();
|
|
});
|
|
|
|
/// <summary>
|
|
/// 上一次渲染的用户信息
|
|
/// </summary>
|
|
private User oldUserInfo;
|
|
private User userInfo;
|
|
/// <summary>
|
|
/// 用户信息
|
|
/// </summary>
|
|
public User UserInfo
|
|
{
|
|
get { return userInfo; }
|
|
set
|
|
{
|
|
oldUserInfo = userInfo.DeepClone();
|
|
SetProperty(ref userInfo, value);
|
|
RenderVideoView();
|
|
}
|
|
}
|
|
|
|
private uint microphoneVolume;
|
|
/// <summary>
|
|
/// 用户麦克风音量
|
|
/// </summary>
|
|
public uint MicrophoneVolume
|
|
{
|
|
get { return microphoneVolume; }
|
|
set { SetProperty(ref microphoneVolume, value); }
|
|
}
|
|
|
|
private void SetUserVolume(AudioVolumeInfo volumeInfo)
|
|
{
|
|
MicrophoneVolume = volumeInfo.volume;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DelegateCommand OperClickCommand => new DelegateCommand(() =>
|
|
{
|
|
Console.WriteLine($@"id:{UserInfo.Id} userName:{UserInfo.UserName} isManager:{UserInfo.IsManager}");
|
|
UserInfo.IsManager = !UserInfo.IsManager;
|
|
userInfo.UserName = DateTime.Now.ToString();
|
|
Console.WriteLine($@"id:{UserInfo.Id} userName:{UserInfo.UserName} isManager:{UserInfo.IsManager}");
|
|
//MessageBox.Show($@"id:{Id} userName:{UserName} isManager:{IsManager}");
|
|
});
|
|
|
|
|
|
public void RenderVideoView()
|
|
{
|
|
if (_view == null || UserInfo == null || UserInfo.Id <= 0)
|
|
{
|
|
if (_view != null)
|
|
{
|
|
//_view.pic_frame.Invoke(() =>
|
|
//{
|
|
// _view.pic_frame.Refresh();
|
|
//});
|
|
|
|
if (oldUserInfo != null)
|
|
{
|
|
AgoraHelper.ClearUserVideo((uint)(oldUserInfo.Id), (long)_view.pic_frame.Handle);
|
|
_view.pic_frame.Invoke(() =>
|
|
{
|
|
_view.pic_frame.Refresh();
|
|
});
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
AgoraHelper.SetupUserVideo((uint)UserInfo.Id, (long)_view.pic_frame.Handle, (uint)(oldUserInfo == null ? 0 : oldUserInfo.Id));
|
|
}
|
|
|
|
}
|
|
}
|