コード例 #1
0
ファイル: LayIMHub.cs プロジェクト: wanglong/LayIM_NetClient
        /// <summary>
        /// 群组发送消息
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public Task ClientSendMsgToGroup(ClientToGroupMessage message)
        {
            //先生成groupid
            var groupId = GroupHelper.CreateGroup().CreateName(message.to.id);

            message.roomid = groupId;
            //保存消息
            Task.Run(() => {
                MessageFactory.CreateInstance(ChatMessageSaveType.SearchEngine).Send(message);
            });
            //处理保存消息业务
            //发送给客户端
            ClientToClientReceivedMessage tomessage = new ClientToClientReceivedMessage
            {
                fromid   = message.mine.id,
                id       = message.to.id,        //注意,这里的群组发送人,就应该是群id了
                avatar   = message.mine.avatar,  //发送人头像
                content  = message.mine.content, //发送内容
                type     = message.to.type,      //类型 这里一定是friend
                username = message.mine.username //发送人姓名
            };
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg     = tomessage,
                other   = null,
                msgtype = ChatToClientType.ClientToGroup//这里是群组类型
            };

            return(Clients.Group(groupId).receiveMessage(result));
        }
コード例 #2
0
ファイル: LayIMHub.cs プロジェクト: wanglong/LayIM_NetClient
        /// <summary>
        /// 客户端聊天消息
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public Task ClientSendMsgToClient(ClientToClientMessage message)
        {
            //先生成groupid
            var groupId = GroupHelper.CreateGroup().CreateName(message.mine.id, message.to.id);

            message.roomid = groupId;
            //处理保存消息业务
            Task.Run(() => {
                ElasticMessage.Instance.Send(message);
            });
            #region  //发送给客户端

            ClientToClientReceivedMessage tomessage = new ClientToClientReceivedMessage
            {
                fromid   = message.mine.id,
                id       = message.mine.id,      //发送人id
                avatar   = message.mine.avatar,  //发送人头像
                content  = message.mine.content, //发送内容
                type     = message.to.type,      //类型 这里一定是friend
                username = message.mine.username //发送人姓名
            };
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg = tomessage, other = null, msgtype = ChatToClientType.ClientToClient
            };
            #endregion
            return(Clients.Group(groupId).receiveMessage(result));
        }
コード例 #3
0
        public static void SendMessage(string userName, int groupId)
        {
            //构造消息体
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg     = userName + " 加入群",
                msgtype = ChatToClientType.UserJoinGroupToClient,
                other   = new { groupid = groupId }
            };

            var groupName = GroupHelper.CreateGroup().CreateName(groupId);

            hub.Clients.Group(groupName).receiveMessage(result);
        }
コード例 #4
0
        public static void SendMessage(object message, string userId, ChatToClientType type, bool moreUser = false)
        {
            //构造消息体
            ToClientMessageResult result = new ToClientMessageResult
            {
                msg     = message,
                msgtype = type,
                other   = null
            };

            // 给多个用户发送消息
            if (moreUser)
            {
                hub.Clients.Users(userId.Split(',').ToList()).receiveMessage(result);
            }
            else
            {
                //给单个用户发送消息
                hub.Clients.User(userId).receiveMessage(result);
            }
        }