public void AgentConnect(string name) { if (ChatSessions == null) { ChatSessions = new ConcurrentDictionary <string, string>(); } var agent = new Agent() { Id = Context.ConnectionId, Name = name, IsOnline = true }; if (!Agents.ContainsKey(agent.Id)) { Agents.Add(agent.Id, agent); } else { Agents[agent.Id] = agent; } Clients.Caller.loginResult(true, agent.Id, agent.Name); Clients.All.onlineStatus(Agents.Values.Count(x => x.IsOnline) > 0); }
public void AddAgent(AgentConnection agent) { agent.Session = this; agent.OnOpen += () => ConnectionOpen(agent); agent.OnClose += () => ConnectionClose(agent); agent.OnConnectionError += (message) => ConnectionError(agent, message); agent.OnMessage += (payload) => MessageReceived(agent, payload); if (!Agents.ContainsKey(agent.Address)) { Agents.Add(agent.Address, agent); } }
public void AddClient(AgentConnection client) { client.Session = this; client.OnOpen += () => ConnectionOpen(client); client.OnClose += () => ConnectionClose(client); client.OnConnectionError += (message) => ConnectionError(client, message); client.OnMessage += (payload) => MessageReceived(client, payload); if (!Agents.ContainsKey(client.Address)) { Agents.Add(client.Address, client); } }
public void LeaveChat(string id) { if (string.IsNullOrEmpty(id)) { return; } // was it an agent var agent = Agents.ContainsKey(id) ? Agents[id] : null; if (agent != null) { Agents.Remove(id); var sessions = ChatSessions.Where(x => x.Value == agent.Id); if (sessions != null) { foreach (var session in sessions) { Clients.Client(session.Key).addMessage("", UiStringTheAgentWasDisconnectedFromChat); } } Clients.All.updateStatus(Agents.Values.Count(x => x.IsOnline) > 0); } // was it a visitor if (ChatSessions.ContainsKey(id)) { var agentId = ChatSessions[id]; Clients.Client(agentId).addMessage(id, UiStringSystem, UiStringTheVisitorCloseTheConnection); ChatClient client = GetChatClient(id); SaveChat(id, client); string buffer = ""; ChatSessions.TryRemove(id, out buffer); ChatClients.Remove(id); } }