Example #1
0
        public async void SendToUser([FromBody] MessageBody model)
        {
            MessageBody message = new MessageBody()
            {
                Type     = 1,
                Content  = model.Content,
                UserName = model.UserName
            };

            if (UserList.ContainsKey(model.UserName))
            {
                var connections = UserList[model.UserName].First();
                await Clients.Client(connections).SendAsync("Recv", new object[] { message });
            }

            //return Json(new { Code = 0 });
        }
Example #2
0
 /// <summary>
 /// 发送消息到指定分组
 /// </summary>
 /// <param name="groupName"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public async Task SendToGroupAsync(string groupName, MessageBody message)
 {
     await Clients.Group(groupName).SendAsync(groupName, new object[] { message });
 }
Example #3
0
 public void Send(MessageBody body)
 {
     Clients.All.SendAsync("Recv", body);
 }