void VisitSessionService_VisitorLeave(object sender, VisitorLeaveEventArgs e) { Visitor visitor = VisitorService.GetVisitorById(e.VisitorId); List <Socket> ss = new List <Socket>(); foreach (var item in GetOnlineOperatorSockets(visitor.AccountId)) { sh.SendPacket(item, e); } }
void processServerEvents(DataArriveEventArgs e) { // 客服状态改变 if (e.Data.GetType() == typeof(OperatorForceLogoffEventArgs)) { if (OperatorForceLogoff != null) { OperatorForceLogoff(this, null); } } else if (e.Data.GetType() == typeof(OperatorStatusChangeEventArgs)) { OperatorStatusChangeEventArgs os = (OperatorStatusChangeEventArgs)e.Data; Operator op = GetOperatorById(os.OperatorId); if (op != null) { op.Status = os.Status; OperatorStatusChanged(this, os); } } //访客对话请求 else if (e.Data.GetType() == typeof(VisitorChatRequestEventArgs)) { VisitorChatRequestEventArgs vc = (VisitorChatRequestEventArgs)e.Data; Visitor v = GetVisitorById(vc.VisitorId); if (v != null) { v.CurrentSession.Status = VisitSessionStatus.ChatRequesting; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); VisitorChatRequest(this, vc); addChat(vc.Chat); } } //客服对话邀请 else if (e.Data.GetType() == typeof(OperatorChatRequestEventArgs)) { OperatorChatRequestEventArgs ocr = (OperatorChatRequestEventArgs)e.Data; Operator op = GetOperatorById(ocr.OperatorId); Visitor v = GetVisitorById(ocr.VisitorId); if (op != null && v != null) { op.Status = OperatorStatus.InviteChat; addChat(ocr.Chat); //v.CurrentSession.Status = VisitSessionStatus. //OperatorChatRequest(this, ocr); OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, OperatorStatus.InviteChat)); } } // 访客对话请求被接受 else if (e.Data.GetType() == typeof(VisitorChatRequestAcceptedEventArgs)) { VisitorChatRequestAcceptedEventArgs v = e.Data as VisitorChatRequestAcceptedEventArgs; Chat chat = GetChatByChatId(v.VisitorChatRequest.Chat.ChatId); Operator op = GetOperatorById(v.VisitorChatRequest.Chat.OperatorId); Visitor visitor = GetVisitorById(v.VisitorChatRequest.VisitorId); if (chat != null && op != null && visitor != null) { chat.OperatorId = v.VisitorChatRequest.Chat.OperatorId; op.Status = OperatorStatus.Chatting; visitor.CurrentSession.OperatorId = op.OperatorId; VisitSession vs = visitor.CurrentSession; vs.ChatingTime = v.VisitorChatRequest.Chat.AcceptTime; vs.Status = VisitSessionStatus.Chatting; //VisitorChatRequestAccepted(this, (VisitorChatRequestAcceptedEventArgs)e.Data); OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(v.VisitorChatRequest.Chat.OperatorId, OperatorStatus.Chatting)); VisitorSessionChange(this, new VisitorSessionChangeEventArgs(vs)); } } // 客服对话邀请被接受 else if (e.Data.GetType() == typeof(OperatorChatRequestAcceptedEventArgs)) { OperatorChatRequestAcceptedEventArgs ocr = (OperatorChatRequestAcceptedEventArgs)e.Data; Operator op = GetOperatorById(ocr.ChatRequest.OperatorId); Visitor v = GetVisitorById(ocr.ChatRequest.VisitorId); if (op != null && v != null) { op.Status = OperatorStatus.Chatting; v.CurrentSession.Status = VisitSessionStatus.Chatting; if (OperatorChatRequestAccepted != null) { OperatorChatRequestAccepted(this, (OperatorChatRequestAcceptedEventArgs)e.Data); } VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, op.Status)); } } // 客服对话邀请被拒绝 else if (e.Data.GetType() == typeof(OperatorChatRequestDeclinedEventArgs)) { OperatorChatRequestDeclinedEventArgs ocr = (OperatorChatRequestDeclinedEventArgs)e.Data; Operator op = GetOperatorById(ocr.ChatRequest.OperatorId); Visitor v = GetVisitorById(ocr.ChatRequest.VisitorId); Chat c = GetChatByChatId(ocr.ChatRequest.Chat.ChatId); if (op != null && v != null && c != null) { c.Status = ChatStatus.Decline; if (!IsOperatorHasActiveChat(op.OperatorId)) { op.Status = OperatorStatus.Idle; OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(op.OperatorId, OperatorStatus.Idle)); } v.CurrentSession.Status = VisitSessionStatus.Visiting; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); if (OperatorChatRequestDeclined != null) { OperatorChatRequestDeclined(this, (OperatorChatRequestDeclinedEventArgs)e.Data); } } } // 新的对话 else if (e.Data.GetType() == typeof(NewChatEventArgs)) { NewChat(this, (NewChatEventArgs)e.Data); } // 对话状态改变 else if (e.Data.GetType() == typeof(ChatStatusChangedEventArgs)) { ChatStatusChangedEventArgs cs = (ChatStatusChangedEventArgs)e.Data; Chat chat = GetChatByChatId(cs.ChatId); if (chat == null) { return; } Visitor v = GetVisitorById(chat.VisitorId); if (v == null) { return; } chat.Status = cs.Status; Operator o = GetOperatorById(chat.OperatorId); if (chat.Status == ChatStatus.Accepted) { v.CurrentSession.Status = VisitSessionStatus.Chatting; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); o.Status = OperatorStatus.Chatting; OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(chat.OperatorId, OperatorStatus.Chatting)); } else if (chat.Status == ChatStatus.Closed) { v.CurrentSession.Status = VisitSessionStatus.Visiting; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); if (o != null && !IsOperatorHasActiveChat(chat.OperatorId)) { o.Status = OperatorStatus.Idle; OperatorStatusChanged(this, new OperatorStatusChangeEventArgs(chat.OperatorId, OperatorStatus.Idle)); } } if (ChatStatusChanged != null) { ChatStatusChanged(this, cs); } } else if (e.Data.GetType() == typeof(OperatorChatJoinInviteEventArgs)) { ChatJoinInvite(this, (OperatorChatJoinInviteEventArgs)e.Data); } else if (e.Data.GetType() == typeof(OperatorChatJoinInviteAcceptedEventArgs)) { ChatJoinInviteAccepted(this, (OperatorChatJoinInviteAcceptedEventArgs)e.Data); } else if (e.Data.GetType() == typeof(OperatorChatJoinInviteDeclinedEventArgs)) { ChatJoinInviteDeclined(this, (OperatorChatJoinInviteDeclinedEventArgs)e.Data); } // 新消息 else if (e.Data.GetType() == typeof(ChatMessageEventArgs) && NewMessage != null) { NewMessage(this, (ChatMessageEventArgs)e.Data); } // 新访问,访客可能已经存在 else if (e.Data.GetType() == typeof(NewVisitingEventArgs) && NewVisiting != null) { NewVisitingEventArgs nv = (NewVisitingEventArgs)e.Data; nv.Visitor.CurrentSession = nv.Session; Visitor v = GetVisitorById(nv.Visitor.VisitorId); if (v != null) { v.CurrentSession = nv.Session; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); } else { addVisitor(nv.Visitor); NewVisiting(this, (NewVisitingEventArgs)e.Data); } } // 访客离开 else if (e.Data.GetType() == typeof(VisitorLeaveEventArgs)) { VisitorLeaveEventArgs vl = e.Data as VisitorLeaveEventArgs; Visitor v = GetVisitorById(vl.VisitorId); if (v != null) { v.CurrentSession.Status = VisitSessionStatus.Leave; VisitorSessionChange(this, new VisitorSessionChangeEventArgs(v.CurrentSession)); } //VisitorLeave(this, (VisitorLeaveEventArgs)e.Data); } }