Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
 public void OnMic(MicType micType, int micIndex, string streamGuid, int micStatus)
 {
     MicType    = micType;
     MicIndex   = micIndex;
     StreamGuid = streamGuid;
     MicAction  = Model.Chat.MicAction.OnMic;
     MicStatus  = micStatus;
 }
Пример #4
0
        internal void UpdateValue(string command, string value)
        {
            switch (command)
            {
            case "micstatus":
                try
                {
                    this.Status = (MicStatus)uint.Parse(value);
                }
                catch (Exception e)
                {
                    ErrorLog.Error("{0}.UpdateValue() Could not parse micstatus value \"{1}\", {2}", this.GetType().Name, value, e.Message);
                }
                break;

            case "mictype":
                try
                {
                    this.Type = (MicType)uint.Parse(value);
                }
                catch (Exception e)
                {
                    ErrorLog.Error("{0}.UpdateValue() Could not parse mictype value \"{1}\", {2}", this.GetType().Name, value, e.Message);
                }
#if DEBUG
                CrestronConsole.PrintLine("Mic {0} is MicType.{1}", this.ChannelNumber, this.Type);
#endif
                break;

            case "mutestatus":
                try
                {
                    string[] args = value.Split(',');
                    _Mute     = (args[0] == "1") ? true : false;
                    _MuteType = (MuteType)uint.Parse(args[1]);
                    _MuteLock = (args[2] == "1") ? true : false;
                }
                catch (Exception e)
                {
                    ErrorLog.Error("{0}.UpdateValue() Could not parse mutestatus value \"{1}\", {2}", this.GetType().Name, value, e.Message);
                }
#if DEBUG
                CrestronConsole.PrintLine("Mic {0} Mute = {1}, MuteType.{2}, MuteLock = {3}", this.ChannelNumber, this.Mute, this.MuteType, this.MuteLock);
#endif
                if (VolumeChanged != null)
                {
                    try
                    {
                        VolumeChanged(this, new VolumeChangeEventArgs(VolumeLevelChangeEventType.MuteChanged));
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("{0}.VolumeChanged event error, {1}", this.GetType().Name, e.Message);
                    }
                }
                break;
            }
        }
Пример #5
0
 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();
         }
     }
 }
Пример #6
0
        static MicStatusMessage GetUserMicStatus(int roomId, int userId, MicType micType)
        {
            var mics = micCache[roomId][micType];

            foreach (var s in mics.Values)
            {
                if (s.UserId == userId)
                {
                    return(s);
                }
            }
            return(null);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public Dictionary <int, MicStatusMessage> GetMicUsers(int roomId, MicType micType)
        {
            Dictionary <int, MicStatusMessage> result = new Dictionary <int, MicStatusMessage>();

            //lock (micCacheLocker[roomId])
            {
                foreach (var pair in micCache[roomId][micType])
                {
                    if (pair.Value.MicStatus != MicStatusMessage.MicStatus_Off && pair.Value.UserId > 0)
                    {
                        result.Add(pair.Key, pair.Value);
                    }
                }
            }
            return(result);
        }
        private void OnMicCommandExecute(SecureCommandArgs args)
        {
            if (args != null)
            {
                MicType micType = (MicType)args.Content;
                if (Me.MicStatus == MicStatusMessage.MicStatus_Off)
                {
                    RoomClient.OnMic(RoomVM.Id, micType, -1);
                }
                else
                {
                    switch (micType)
                    {
                    case MicType.Private:
                        PrivateMicUserVMs.Remove(Me);
                        break;

                    case MicType.Secret:
                        SecretMicUserVMs.Remove(Me);
                        break;

                    case MicType.Public:
                        switch (Me.MicIndex)
                        {
                        case 0:
                            FirstMicUserVM = null;
                            break;

                        case 1:
                            SecondMicUserVM = null;
                            break;

                        case 2:
                            ThirdMicUserVM = null;
                            break;
                        }
                        break;
                    }
                    RoomClient.DownMic(RoomVM.Id, micType, Me.MicIndex);
                    Me.DownMic();
                    updateMicImage(Me.Id, false);// update the local image manually as the downmic meesage will not be received by itself.
                }
            }
        }
Пример #10
0
        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);
            }
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
		static MicStatusMessage GetUserMicStatus(int roomId, int userId, MicType micType)
		{
			var mics = micCache[roomId][micType];
			foreach (var s in mics.Values)
			{
				if (s.UserId == userId)
				{
					return s;
				}
			}
			return null;
		}
Пример #13
0
 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;
 }
Пример #14
0
 public Dictionary<int, MicStatusMessage> GetMicUsers(int roomId, MicType micType)
 {
     Dictionary<int, MicStatusMessage> result = new Dictionary<int, MicStatusMessage>();
     //lock (micCacheLocker[roomId])
     {
         foreach (var pair in micCache[roomId][micType])
         {
             if (pair.Value.MicStatus != MicStatusMessage.MicStatus_Off && pair.Value.UserId >0)
             {
                 result.Add(pair.Key, pair.Value);
             }
         }
     }
     return result;
 }
Пример #15
0
 public void OnMic(MicType micType, int micIndex, string streamGuid, int micStatus)
 {
     MicType = micType;
     MicIndex = micIndex;
     StreamGuid = streamGuid;
     MicAction = Model.Chat.MicAction.OnMic;
     MicStatus = micStatus;
 }
Пример #16
0
 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);
         }
     }
 }
Пример #17
0
 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);
     }
 }
Пример #18
0
 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();
         }
     }      
 }