public IEnumerable <Participant> Participants(string sessionCode)
        {
            if (!string.IsNullOrEmpty(sessionCode))
            {
                var room = _onlineMeetingRoomManager.GetOne(sessionCode);
                return(room?.Participants);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// 加入会话
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <JoinResult> Join(UserJoinViewModel user)
        {
            if (!user.IsValid())
            {
            }
            user.ConnectionId = Context.ConnectionId;

            // 从在线会议室中获取此会议室
            var onlineRoom = _onlineMeetingRoomManager.GetOne(user.SessionCode);
            // 从所有会议室获取到此会议室
            var room = await _meetingRoomManager.GetBySessionCodeAsync(user.SessionCode);

            // 同时存在
            if (onlineRoom == null || null == room)
            {
                return(new JoinResult(false, "找不到会话。请检查此代码是否正确,以及当前会话是否属于活动状态。"));
            }

            // 加入到此会议室中
            var participant = _mapper.Map <UserJoinViewModel, Participant>(user);

            onlineRoom.Join(participant);
            _onlineMeetingRoomManager.AddOrUpdate(room.SessionCode, onlineRoom);

            await Groups.AddToGroupAsync(user.ConnectionId, onlineRoom.SessionCode);

            // 通知其他人有新用户加入
            await Clients.GroupExcept(onlineRoom.SessionCode, user.ConnectionId).SendAsync("UserJoined", participant);

            // 添加加入会议的消息
            var message = new Message(null, "System", $"{user.Nickname} 加入了会议", "zh-cn");

            room.AppendMessage(message);
            await _meetingRoomManager.UpdateAsync(room);

            // 发送通知消息
            var msg = _mapper.Map <Message, ReturnMessage>(message);
            await Clients.Group(onlineRoom.SessionCode).SendAsync("ReceiveMessage", msg);

            return(new JoinResult(true, "加入成功"));
        }