Exemplo n.º 1
0
        /// <summary>
        /// 人对组聊天,连接服务器
        /// </summary>
        /// <param name="sendid">当前用户id</param>
        /// <param name="groupid">当前群组id</param>
        /// <returns></returns>
        public Task ClientToGroup(string sendid, string groupid)
        {
            if (sendid == null || groupid == null)
            {
                throw new ArgumentNullException("sendid or groupid can't be null");
            }
            string groupName = MessageUtils.GetGroupName(groupid);

            Groups.Add(CurrentUserConnectionId, groupName);
            //构建系统连接成功消息
            var msg = MessageUtils.GetSystemMessage(groupName, MessageConfig.ClientToGroupConnectedSucceed, new { t = MessageConfig.ClientTypeCTG, currentid = sendid, receiveid = groupid });

            //将消息推送到当前组 (A和B聊天的组) 同样调用receiveMessage方法
            return(Clients.Caller.receiveMessage(msg));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 人对人聊天 连接服务器
        /// </summary>
        /// <param name="sendid">发送人</param>
        /// <param name="receiveid">接收人</param>
        /// <returns></returns>
        public Task ClientToClient(string sendid, string receiveid)
        {
            if (sendid == null || receiveid == null)
            {
                throw new ArgumentNullException("sendid or receiveid can't be null");
            }
            //获取组名
            string groupName = MessageUtils.GetGroupName(sendid, receiveid);

            //将当前用户添加到此组织内
            Groups.Add(CurrentUserConnectionId, groupName);
            //构建系统连接成功消息
            //读取历史记录 --- 2016-3-7 修改
            var historyMsg = MessageUtils.GetHistoryMessage(sendid, receiveid);

            var msg = MessageUtils.GetSystemMessage(groupName, MessageConfig.ClientToClientConnectedSucceed, new { t = MessageConfig.ClientTypeCTC, currentid = sendid, receiveid = receiveid, history = historyMsg });

            //将消息推送到当前组 (A和B聊天的组) 同样调用receiveMessage方法

            return(Clients.Caller.receiveMessage(msg));
        }