protected override BaseResponseResult DoWork(JoinRoomReq param) { BaseResponseResult rc = new BaseResponseResult((int)Code.OperationError, "操作失败!"); if (Index.User != null) { if (param.liveId > 0) { //找到当前直播对应的房间号 LiveChatRoom room = new LiveChatRoomBLL().Find(it => it.LiveID == param.liveId && it.Status == 1); //如果房间存在 if (room != null && room.ID > 0) { //将ConnectionID与UserID绑定到当前直播的房间中 LiveChatRoomMember member = new LiveChatRoomMember { ConnectionID = param.connectionId, RoomID = room.ID, UserID = Index.User.UserID }; member.ID = new LiveChatRoomMemberBLL().Add(member); //如果当前登陆的人员 成功 加入到直播聊天室 if (member.ID > 0) { //这里的代码很重要,这是在外部调用GroupChatHub var context = GlobalHost.ConnectionManager.GetHubContext <GroupChatHub>(); //将当前的ConnectionID加入到 以房间ID为名称的组中 context.Groups.Add(param.connectionId, room.ID.ToString()); //向客户端发送新加入人员信息 context.Clients.Group(room.ID.ToString()).publishMsg(GroupChatHub.FormatMsg("系统消息", Index.User.UserName + " 加入聊天", 0, Index.User.HeadPic)); rc.SetResult(0, "成功加入聊天室!"); } else { rc.SetResult(3, "加入聊天房间失败!"); } } else { rc.SetResult(1, "当前聊天房间不存在!"); } } else { rc.SetResult(1, "当前聊天房间不存在!"); } } else { rc.SetResult(2, "未登录!"); } return(rc); }
public LiveChatRoomMember Find(System.Linq.Expressions.Expression <Func <LiveChatRoomMember, bool> > where) { LiveChatRoomMember rc = null; try { if (where != null) { rc = db.Queryable <LiveChatRoomMember>().First(where); } } catch (Exception ex) { log.Error("Find", ex); } return(rc); }
public long Add(LiveChatRoomMember model) { long rc = 0; try { if (model != null) { rc = db.Insertable(model).ExecuteReturnBigIdentity(); } } catch (Exception ex) { log.Error("Add", ex); } return(rc); }
public override Task OnDisconnected(bool stopCalled) { LiveChatRoomMemberBLL biz = new LiveChatRoomMemberBLL(); //根据ConnectionID找到当前的聊天室信息 LiveChatRoomMember member = biz.Find(it => it.ConnectionID == Context.ConnectionId); if (member != null && member.ID > 0) { //从该房间清除该人员 if (biz.Delete(member.ID)) { //发送退出消息 Clients.Groups(new List <string> { member.RoomID.ToString() }).publishMsg(FormatMsg("系统消息", member.User.UserName + " 退出聊天", 0)); //从组中移除该ConnectionID Groups.Remove(Context.ConnectionId, member.RoomID.ToString()); } } return(base.OnDisconnected(stopCalled)); }
public long Add(LiveChatRoomMember model) { return(dal.Add(model)); }