public void ToggleAudio(int roomId, MicType micType) { var micS = GetUserMicStatus(roomId, unc.User.Id, micType); if (micS != null && micS.MicStatus != MicStatusMessage.MicStatus_Off) { if ((micS.MicStatus & MicStatusMessage.MicStatus_Audio) > 0) { micS.MicStatus = micS.MicStatus & (~MicStatusMessage.MicStatus_Audio); } else { micS.MicStatus = micS.MicStatus | MicStatusMessage.MicStatus_Audio; } var msg = new MicStatusMessage { MicAction = Model.Chat.MicAction.Toggle, MicStatus = micS.MicStatus, UserId = unc.User.Id }; BroadCast(roomId, (u) => u.Callback.MicStatusMessageReceived(roomId, msg), unc.User.Id); } }
public void DownMic(int roomId, MicType micType, int index) { var mics = micCache[roomId][micType]; if (index < 0) { var usr = mics.Values.FirstOrDefault(u => u.UserId == unc.User.Id); if (usr != null) { index = usr.MicIndex; } } if (index >= 0) { if (mics[index].UserId == unc.User.Id) { mics[index].Reset(); var msg = new MicStatusMessage { MicAction = Model.Chat.MicAction.DownMic, MicIndex = index, MicStatus = MicStatusMessage.MicStatus_Off, MicType = micType, UserId = unc.User.Id }; BroadCast(roomId, (u) => u.Callback.MicStatusMessageReceived(roomId, msg), unc.User.Id); } } }
static void InitMicCache(int roomId, MicType micType, int count) { if (count > 0) { micCache[roomId][micType] = new SafeDictionary <int, MicStatusMessage>(); for (int i = 0; i < count; i++) { micCache[roomId][micType][i] = new MicStatusMessage(); } } }
static int GetAvailableMicStatus(int roomId, MicType micType, int userId, int suggestedIndex, out MicStatusMessage msg) { msg = null; var mics = micCache[roomId][micType]; int index = -1; if (suggestedIndex > -1) { if (suggestedIndex < mics.Count) { if (mics[suggestedIndex].UserId == userId) { msg = mics[suggestedIndex]; index = suggestedIndex; } } } if (msg == null) { foreach (var pair in mics) { if (pair.Value.UserId == -1 || pair.Value.UserId == userId) { msg = pair.Value; index = pair.Key; break; } } } if (msg == null && micType == MicType.Public) { msg = new MicStatusMessage { MicType = micType, MicStatus = MicStatusMessage.MicStatus_Queue, }; //Mic Queue if (micType == MicType.Public) { msg = micQueue[roomId].FirstOrDefault(u => u.UserId == userId); if (msg == null) { micQueue[roomId].Add(msg); } } index = micQueue[roomId].IndexOf(msg); } return(index); }
public void OnMic(int roomId, MicType micType, int suggestedIndex = -1) { MicStatusMessage msg = null; int index = GetAvailableMicStatus(roomId, micType, unc.User.Id, suggestedIndex, out msg); if (msg != null) { msg.UserId = unc.User.Id; msg.MicAction = MicAction.OnMic; msg.MicType = micType; if (msg.MicStatus != MicStatusMessage.MicStatus_Queue) { if (index >= 0) { msg.MicIndex = index; msg.StreamGuid = Guid.NewGuid().ToString(); msg.MicStatus = MicStatusMessage.MicStatus_Video; } } unc.Callback.MicStatusMessageReceived(roomId, msg); BroadCast(roomId, (u) => u.Callback.MicStatusMessageReceived(roomId, msg), unc.User.Id); } }
private void MicStatusMessageReceivedEventHandler(int arg1, MicStatusMessage arg2) { if (arg1 == RoomVM.Id) { var uvm = UserVMs.FirstOrDefault(u => u.Id == arg2.UserId); if (uvm != null) { switch (arg2.MicAction) { #region OnMic case MicAction.OnMic: { switch (arg2.MicType) { case MicType.Public: { switch (arg2.MicIndex) { case 0: FirstMicUserVM = uvm; break; case 1: SecondMicUserVM = uvm; break; case 2: ThirdMicUserVM = uvm; break; } } break; case MicType.Private: if (!PrivateMicUserVMs.Contains(uvm)) { PrivateMicUserVMs.Add(uvm); } break; case MicType.Secret: if (!SecretMicUserVMs.Contains(uvm)) { SecretMicUserVMs.Add(uvm); } break; default: break; } uvm.OnMic(arg2.MicType, arg2.MicIndex, arg2.StreamGuid, arg2.MicStatus); updateMicImage(uvm.Id, true); } break; #endregion #region DownMic case MicAction.DownMic: { switch (arg2.MicType) { case MicType.Public: switch (arg2.MicIndex) { case 0: FirstMicUserVM = null; break; case 1: SecondMicUserVM = null; break; case 2: ThirdMicUserVM = null; break; } break; case MicType.Private: PrivateMicUserVMs.Remove(uvm); break; case MicType.Secret: SecretMicUserVMs.Remove(uvm); break; } } uvm.DownMic(); updateMicImage(uvm.Id, false); break; #endregion #region Toggle case MicAction.Toggle: { uvm.Toggle(arg2.MicStatus); } break; #endregion } } } }