379 lines
12 KiB
C#
379 lines
12 KiB
C#
using JianGongYun.TRTC.Models;
|
||
using JianGongYun.TRTC.Utils;
|
||
using ManageLiteAV;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.ComponentModel;
|
||
using System.Text;
|
||
using System.Linq;
|
||
using System.Windows.Media;
|
||
using System.Windows.Media.Imaging;
|
||
using System.Windows.Threading;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
|
||
namespace JianGongYun.TRTC.ViewModels
|
||
{
|
||
public class LiveWindowViewModel : INotifyPropertyChanged
|
||
{
|
||
public event PropertyChangedEventHandler PropertyChanged;
|
||
|
||
#region 直播窗口
|
||
/// <summary>
|
||
/// 教室信息
|
||
/// </summary>
|
||
public Models.ClassroomEntity ClassroomEntity { get { return LiveClassroom.CurrentClassroomEntity; } }
|
||
|
||
/// <summary>
|
||
/// 学生总数
|
||
/// </summary>
|
||
private int _StudentCount = 1;
|
||
public int StudentCount
|
||
{
|
||
set
|
||
{
|
||
_StudentCount = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("StudentCount"));//对StudentCount进行监听
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _StudentCount;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否在直播中
|
||
/// </summary>
|
||
private bool _IsLive = false;
|
||
public bool IsLive
|
||
{
|
||
set
|
||
{
|
||
_IsLive = value;
|
||
if (value)//开始直播,清空时间并开始计时
|
||
{
|
||
_LiveTimeCount = new DateTime(1970, 1, 1, 0, 0, 0);
|
||
timer.Start();
|
||
}
|
||
else
|
||
{
|
||
timer.Stop();
|
||
}
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("IsLive"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _IsLive;
|
||
}
|
||
}
|
||
|
||
public LiveWindowViewModel()
|
||
{
|
||
timer = new DispatcherTimer(DispatcherPriority.Render);
|
||
timer.Interval = TimeSpan.FromSeconds(1);
|
||
timer.Tick += new EventHandler((a, b) => LiveTimeCount = "");
|
||
}
|
||
/// <summary>
|
||
/// 直播计时器
|
||
/// </summary>
|
||
private DispatcherTimer timer = null;
|
||
private DateTime _LiveTimeCount;
|
||
public string LiveTimeCount
|
||
{
|
||
get
|
||
{
|
||
return _LiveTimeCount.ToString("HH:mm:ss");
|
||
}
|
||
set
|
||
{
|
||
_LiveTimeCount = _LiveTimeCount.AddSeconds(1);
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("LiveTimeCount"));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 直播类型
|
||
/// </summary>
|
||
private LiveTypeEnum _LiveType = LiveTypeEnum.OnlyAudio;
|
||
public LiveTypeEnum LiveType
|
||
{
|
||
set
|
||
{
|
||
_LiveType = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("LiveType"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _LiveType;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 摄像头采集中
|
||
/// </summary>
|
||
private bool _CameraRunning = false;
|
||
public bool CameraRunning
|
||
{
|
||
set
|
||
{
|
||
_CameraRunning = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("CameraRunning"));
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle"));
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _CameraRunning;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 屏幕分享中
|
||
/// </summary>
|
||
private bool _ScreenRunning = false;
|
||
public bool ScreenRunning
|
||
{
|
||
set
|
||
{
|
||
_ScreenRunning = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("ScreenRunning"));
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MainSmallWrapStyle"));
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MainBigWrapStyle"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _ScreenRunning;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 麦克风使用中
|
||
/// </summary>
|
||
private bool _MicRunning = false;
|
||
public bool MicRunning
|
||
{
|
||
set
|
||
{
|
||
_MicRunning = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MicRunning"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _MicRunning;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 麦克风录音中
|
||
/// </summary>
|
||
private bool _AudioRecordRunning = false;
|
||
public bool AudioRecordRunning
|
||
{
|
||
set
|
||
{
|
||
_AudioRecordRunning = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("AudioRecordRunning"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _AudioRecordRunning;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 麦克风静音
|
||
/// </summary>
|
||
private bool _MicMute = false;
|
||
public bool MicMute
|
||
{
|
||
set
|
||
{
|
||
_MicMute = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("MicMute"));
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _MicMute;
|
||
}
|
||
}
|
||
|
||
|
||
private ObservableCollection<TRTCScreenEntity> _LiveScreens = new ObservableCollection<TRTCScreenEntity>();
|
||
/// <summary>
|
||
/// 可分享桌面
|
||
/// </summary>
|
||
public ObservableCollection<TRTCScreenEntity> LiveScreens
|
||
{
|
||
get
|
||
{
|
||
return _LiveScreens;
|
||
}
|
||
}
|
||
|
||
string[] excluded = new string[] { "Notifiaction" };
|
||
private SIZE thumbSize = new SIZE { cx = 300, cy = 200 };
|
||
private SIZE iconSize = new SIZE { cx = 50, cy = 50 };
|
||
/// <summary>
|
||
/// 获取所有桌面列表
|
||
/// </summary>
|
||
public void LoadAllScreen()
|
||
{
|
||
LiveClassroom.WillGetScreens(() =>
|
||
{
|
||
//Console.WriteLine("get LiveScreens");
|
||
_LiveScreens.Clear();
|
||
LiveClassroom.lTRTCCloud.removeAllExcludedShareWindow();
|
||
//Console.WriteLine("get LiveScreens Clear");
|
||
var temp = LiveClassroom.lTRTCCloud.getScreenCaptureSources(ref thumbSize, ref iconSize);
|
||
var count = temp.getCount();
|
||
//Console.WriteLine($"get LiveScreens {count}");
|
||
for (uint i = 0; i < count; i++)
|
||
{
|
||
var info = temp.getSourceInfo(i);
|
||
if (string.IsNullOrWhiteSpace(info.sourceName) || excluded.Contains(info.sourceName))
|
||
{
|
||
LiveClassroom.lTRTCCloud.addExcludedShareWindow(info.sourceId);
|
||
continue;
|
||
}
|
||
//var icon = Util.ToWriteableBitmap(ref info.iconBGRA);
|
||
//Console.WriteLine($"get LiveScreens {i} {info.sourceId}");
|
||
var thumb = info.thumbBGRA.ToWriteableBitmap();
|
||
_LiveScreens.Add(new TRTCScreenEntity { SourceId = info.sourceId, SourceName = info.sourceName, Type = info.type, Thumb = thumb, Info = info });
|
||
}
|
||
temp.release();
|
||
});
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 当前分享的桌面列表
|
||
/// </summary>
|
||
private bool _ShowShareScreenList = false;
|
||
public bool ShowShareScreenList
|
||
{
|
||
get
|
||
{
|
||
return _ShowShareScreenList;
|
||
}
|
||
set
|
||
{
|
||
_ShowShareScreenList = value;
|
||
if (_ShowShareScreenList)
|
||
{
|
||
var temp = LiveScreens;//获取一次刷新列表
|
||
}
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("ShowShareScreenList"));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当前分享的桌面
|
||
/// </summary>
|
||
private TRTCScreenCaptureSourceInfo _CurrentShareScreen;
|
||
public TRTCScreenCaptureSourceInfo CurrentShareScreen
|
||
{
|
||
get
|
||
{
|
||
if (_CurrentShareScreen == null && LiveScreens.Count > 0)
|
||
{
|
||
_CurrentShareScreen = LiveScreens[0].Info;
|
||
}
|
||
return _CurrentShareScreen;
|
||
}
|
||
set
|
||
{
|
||
_CurrentShareScreen = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("CurrentShareScreen"));
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 只有摄像头,则画面放大并居中
|
||
public Style MainBigWrapStyle
|
||
{
|
||
get
|
||
{
|
||
var style = new Style(typeof(Grid));
|
||
if (CameraRunning && ScreenRunning)
|
||
{
|
||
style.Setters.Add(new Setter { Property = FrameworkElement.HorizontalAlignmentProperty, Value = HorizontalAlignment.Right });
|
||
}
|
||
return style;
|
||
}
|
||
}
|
||
public Style MainSmallWrapStyle
|
||
{
|
||
get
|
||
{
|
||
var style = new Style(typeof(Border));
|
||
if (CameraRunning && ScreenRunning)
|
||
{
|
||
style.Setters.Add(new Setter { Property = FrameworkElement.HorizontalAlignmentProperty, Value = HorizontalAlignment.Right });
|
||
style.Setters.Add(new Setter { Property = FrameworkElement.VerticalAlignmentProperty, Value = VerticalAlignment.Bottom });
|
||
style.Setters.Add(new Setter { Property = Border.BorderThicknessProperty, Value = new Thickness(1) });
|
||
style.Setters.Add(new Setter { Property = Border.MarginProperty, Value = new Thickness(0, 0, 20, 20) });
|
||
style.Setters.Add(new Setter { Property = Border.WidthProperty, Value = 150d });
|
||
style.Setters.Add(new Setter { Property = Border.HeightProperty, Value = 150d });
|
||
}
|
||
return style;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 聊天窗口
|
||
/// <summary>
|
||
/// 消息集合
|
||
/// </summary>
|
||
private ObservableCollection<string> _Chats = new ObservableCollection<string>() { "1", "2" };
|
||
public ObservableCollection<string> Chats
|
||
{
|
||
set
|
||
{
|
||
_Chats = value;
|
||
if (PropertyChanged != null)
|
||
{
|
||
PropertyChanged(this, new PropertyChangedEventArgs("Chats"));//对StudentCount进行监听
|
||
}
|
||
}
|
||
get
|
||
{
|
||
return _Chats;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|