Пример #1
0
        public void addToRoom(int memberID, int roomid)
        {
            Groups.Add(Context.ConnectionId, roomid.ToString());
            try
            {
                Member member = new Member();
                member.LoadByPrimaryKey(memberID);
                bool isHidden = member.Status == (int)Helper.Enums.MemberStatus.Offline &&
                    Roles.IsUserInRole(member.Name, Helper.Enums.MemberRoles.InvisibleInRoom.ToString());

                RoomMember roomMember = new RoomMember();
                if (!roomMember.LoadByPrimaryKey(memberID, roomid))
                {
                    roomMember.AddNew();
                    roomMember.MemberID = memberID;
                    roomMember.RoomID = roomid;
                }
                roomMember.LastJoinDate = DateTime.Now;
                roomMember.InRoom = !isHidden;
                Room room = new Room();
                room.LoadByPrimaryKey(roomid);
                if (!room.IsColumnNull("CreatedBy"))
                {
                    if (room.CreatedBy == roomMember.MemberID)
                        roomMember.RoomMemberLevelID = (int)Helper.Enums.RoomMemberLevel.Owner;
                }
                roomMember.Save();

                Helper.ChatMember chatMember = roomMember.LoadWithSettings(roomid, roomMember.MemberID, roomMember.MemberID, null).FirstOrDefault();

                if (!isHidden)
                    Clients.Group(roomid.ToString()).addNewMember(roomid.ToString(), chatMember);
                if (roomMember.RoomMemberLevelID > (int)Helper.Enums.RoomMemberLevel.Visitor)
                    Groups.Add(Context.ConnectionId, GetRoomAdminGroupName(roomid));

                BLL.MemberLog log = new BLL.MemberLog();
                Helper.Enums.LogType lgType = Helper.Enums.LogType.EnterRoom;
                if (isHidden)
                    lgType = Helper.Enums.LogType.EnterRoomHidden;
                log.AddNew(memberID, new BLL.Log.EnterRoom() { Type = lgType, RoomID = roomid, RoomName = room.Name }, null, roomid);

                RoomMember onlineroomMember = new RoomMember();
                onlineroomMember.GetAllOnlineMembersByRoomID(roomid);
                Clients.All.updateExistingCount(roomid, onlineroomMember.RowCount);

                var item = ConnectedUsers.FirstOrDefault(m => m.MemberID == memberID);
                if (item == null)
                {
                    var newMember = new Helper.SignalRUser { ConnectionId = Context.ConnectionId, MemberName = member.Name, MemberID = member.MemberID, ProfilePic = member.ProfilePic, MemberTypeSpecID = member.MemberType.MemberTypeSpecDuration.MemberTypeSpecID };
                    ConnectedUsers.Add(newMember);
                }
            }
            catch (Exception ex)
            {

            }
        }
Пример #2
0
        public void removeFromRoom(int memberID, int roomid)
        {
            // just remove member from signalr hub and update flag InRoom to false
            try
            {
                Clients.Group(roomid.ToString()).removeMember(memberID, roomid);
                Groups.Remove(Context.ConnectionId, roomid.ToString());

                RoomMember roomMember = new RoomMember();
                if (roomMember.LoadByPrimaryKey(memberID, roomid))
                {

                    roomMember.InRoom = false;
                    roomMember.HasCam = false;
                    roomMember.HasMic = false;
                    roomMember.SetColumnNull(RoomMember.ColumnNames.QueueOrder);
                    roomMember.Save();

                    RoomMember onlineroomMember = new RoomMember();
                    onlineroomMember.GetAllOnlineMembersByRoomID(roomid);
                    Clients.All.updateExistingCount(roomid, onlineroomMember.RowCount);

                    if (roomMember.RoomMemberLevelID > (int)Helper.Enums.RoomMemberLevel.Visitor)
                        Groups.Remove(Context.ConnectionId, GetRoomAdminGroupName(roomid));
                }
            }
            catch (Exception ex)
            {
            }
        }