|
@@ -20,234 +20,5 @@ namespace WingLiveConsultationService
|
|
|
public interface IDistributedRoom
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- public enum VideoProtocol
|
|
|
- {
|
|
|
- Rtmp,
|
|
|
- Rtc
|
|
|
- }
|
|
|
-
|
|
|
- public enum LiveConsultationRoomStatus
|
|
|
- {
|
|
|
- Initiating,
|
|
|
- ConnectionTimeout,
|
|
|
- Connected
|
|
|
- }
|
|
|
-
|
|
|
- public class LiveConsultationRoomStatusArgs : EventArgs
|
|
|
- {
|
|
|
- /// <summary>
|
|
|
- /// The old diagnosis room status
|
|
|
- /// </summary>
|
|
|
- /// <value></value>
|
|
|
- public LiveConsultationRoomStatus OldStatus { get; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The new diagnosis room status
|
|
|
- /// </summary>
|
|
|
- /// <value></value>
|
|
|
- public LiveConsultationRoomStatus NewStatus { get; }
|
|
|
- public LiveConsultationRoomStatusArgs(LiveConsultationRoomStatus oldStatus, LiveConsultationRoomStatus newStatus)
|
|
|
- {
|
|
|
- OldStatus = oldStatus;
|
|
|
- NewStatus = newStatus;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public class RemoteNotifyTarget
|
|
|
- {
|
|
|
- public string ServerUrl {get;}
|
|
|
- public IList<string> ClientIds {get;}
|
|
|
-
|
|
|
- public RemoteNotifyTarget(string serverUrl)
|
|
|
- {
|
|
|
- ServerUrl = serverUrl;
|
|
|
- ClientIds = new List<string>();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public class LiveConsultationRoom : ILiveConsultationRoom, IDistributedRoom
|
|
|
- {
|
|
|
- private LiveConsultationRoomStatus _status;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The event diagnosis room closed
|
|
|
- /// </summary>
|
|
|
- public event EventHandler<LiveConsultationRoomStatusArgs> StatusChanged;
|
|
|
-
|
|
|
- public LiveConsultationMemeber Initiator { get; }
|
|
|
- public IList<LiveConsultationMemeber> Members { get; }
|
|
|
- public IList<LiveConsultationMemeber> Devices { get; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The diagnosis room status
|
|
|
- /// </summary>
|
|
|
- /// <value></value>
|
|
|
- public LiveConsultationRoomStatus Status
|
|
|
- {
|
|
|
- get => _status;
|
|
|
- private set
|
|
|
- {
|
|
|
- if (_status != value)
|
|
|
- {
|
|
|
- var old = _status;
|
|
|
- _status = value;
|
|
|
- OnStatusChanged(old, _status);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The diagnosis room No
|
|
|
- /// </summary>
|
|
|
- /// <value></value>
|
|
|
- public int RoomNo { get; }
|
|
|
-
|
|
|
- public LiveConsultationRoom(int roomNo, LiveConsultationMemeber initiator, IList<LiveConsultationMemeber> members, IList<LiveConsultationMemeber> devices)
|
|
|
- {
|
|
|
- RoomNo = roomNo;
|
|
|
- Initiator = initiator;
|
|
|
- Members = members;
|
|
|
- Devices = devices;
|
|
|
- }
|
|
|
-
|
|
|
- void OnStatusChanged(LiveConsultationRoomStatus oldStatus, LiveConsultationRoomStatus newStatus)
|
|
|
- {
|
|
|
- StatusChanged?.Invoke(this, new LiveConsultationRoomStatusArgs(oldStatus, newStatus));
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Check
|
|
|
- /// </summary>
|
|
|
- /// <param name="timeout">timeout (Unit is ms)</param>
|
|
|
- public void StartCheckConnectionTimeout(int timeout)
|
|
|
- {
|
|
|
- Task.Run(async () =>
|
|
|
- {
|
|
|
- lock (Initiator)
|
|
|
- {
|
|
|
- Status = LiveConsultationRoomStatus.Initiating;
|
|
|
- }
|
|
|
- await Task.Delay(timeout);
|
|
|
- lock (Initiator)
|
|
|
- {
|
|
|
- if (Status != LiveConsultationRoomStatus.Connected)
|
|
|
- {
|
|
|
- Status = LiveConsultationRoomStatus.ConnectionTimeout;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Accept the diagnosis connection
|
|
|
- /// </summary>
|
|
|
- /// <param name="userId">The accepter id</param>
|
|
|
- public void Accept(string userId)
|
|
|
- {
|
|
|
- var accepter = Members.FirstOrDefault(x=>x.Id == userId);
|
|
|
- if (accepter != null)
|
|
|
- {
|
|
|
- accepter.Status = LiveConsultationMemeberStatus.Accepted;
|
|
|
- Logger.WriteLineInfo($"User {accepter} accept to join room {RoomNo}");
|
|
|
- Status = LiveConsultationRoomStatus.Connected;
|
|
|
-
|
|
|
- var others = Members.Where(x=>x.Id != accepter.Id).ToList();
|
|
|
-
|
|
|
- NotifyMessage(others, NotificationTypeEnum.Message); //TODO define a new NotificationType Enum value
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Logger.WriteLineWarn($"Not find accepter with id:{userId} when accept diagnosis");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void NotifyMessage(IList<LiveConsultationMemeber> clients, NotificationTypeEnum notificationType)
|
|
|
- {
|
|
|
- //TODO
|
|
|
- var isDistributed = ConfigurationManager.IsDistributed;
|
|
|
- if (isDistributed)
|
|
|
- {
|
|
|
- var localUrl = ConfigurationManager.Host;
|
|
|
- var localIds = new List<string>();
|
|
|
- var remoteIds = new List<RemoteNotifyTarget>();
|
|
|
- foreach(var client in clients)
|
|
|
- {
|
|
|
- var serverUrl =client.LoginServerUrl ;
|
|
|
- var clientId = client.Id;
|
|
|
- if(serverUrl== localUrl)
|
|
|
- {
|
|
|
- localIds.Add(clientId);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var exist = remoteIds.FirstOrDefault(x=>x.ServerUrl == serverUrl);
|
|
|
- if(exist != null)
|
|
|
- {
|
|
|
- exist.ClientIds.Add(clientId);
|
|
|
- }
|
|
|
- else
|
|
|
- { var newItem = new RemoteNotifyTarget(serverUrl);
|
|
|
- newItem.ClientIds.Add(clientId);
|
|
|
- remoteIds.Add(newItem);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(localIds.Any())
|
|
|
- {
|
|
|
- LiveConsultationService.PushMessage(localIds, notificationType);
|
|
|
- }
|
|
|
-
|
|
|
- if (remoteIds.Any())
|
|
|
- {
|
|
|
- if(ConfigurationManager.IsDistributed)
|
|
|
- {
|
|
|
- LiveConsultationService.DispatchMessage(remoteIds, notificationType);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Logger.WriteLineWarn("Should not happen in non-distributed system");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var ids = clients.Select(x=>x.Id).ToArray();
|
|
|
- LiveConsultationService.PushMessage(ids, notificationType);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void Reject(string userId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void Join(string userId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void Leave(string userId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void Mute(string userId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void AddDevice(string userId, string deviceId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void RemoveDevice(string userId, string deviceId)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
}
|