Пример #1
0
        /// <summary>
        /// 断开连接
        /// </summary>
        /// <param name="stopCalled"></param>
        /// <returns></returns>
        public override Task OnDisconnected(bool stopCalled)
        {
            string user = ConnectManager.GetUserName(Context.ConnectionId);

            ConnectManager.RemoveUser(user);
            Show(string.Format("{0}退出", user));

            return(base.OnDisconnected(stopCalled));
        }
Пример #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="content"></param>
        /// <param name="receiveUser"></param>
        public void Show(string content, string receiveUser = "")
        {
            string user = ConnectManager.GetUserName(Context.ConnectionId);

            if (string.IsNullOrEmpty(receiveUser))
            {
                Clients.All.show(content);
            }
            else
            {
                Clients.Client(ConnectManager.GetUserConnect(receiveUser)).show(string.Format("{0}发消息:{1}", user, content));
            }
        }
Пример #3
0
 /// <summary>
 /// 登录操作
 /// </summary>
 /// <param name="user"></param>
 public void Login(string user)
 {
     ConnectManager.OnlineInit(user, Context.ConnectionId);
     Show(string.Format("{0}:登录成功", user));
 }