/// <summary> /// Closes the chatroom /// </summary> public void Close() { var presence = new Presence { Id = XmppIdentifierGenerator.Generate(), To = Identifier, Type = PresenceType.Unavailable }; PendingMessages.Add(presence.Id); Session.Send(presence); }
/// <summary> /// Performs the gateway unregistration process /// </summary> public void Unregister() { var query = new RegisterQuery(); var iq = new IQ(); iq.ID = XmppIdentifierGenerator.Generate(); iq.Type = IQType.Set; iq.From = Session.UserId; iq.To = Identifier; iq.Items.Add(query); query.Remove = ""; PendingMessages.Add(iq.ID); Session.Send(iq); }
/// <summary> /// Performs the gateway registration process /// </summary> /// <param name = "username"></param> /// <param name = "password"></param> public void Register(string username, string password) { var query = new RegisterQuery(); var iq = new IQ(); iq.ID = XmppIdentifierGenerator.Generate(); iq.Type = IQType.Set; iq.From = Session.UserId; iq.To = Identifier; iq.Items.Add(query); query.UserName = username; query.Password = password; PendingMessages.Add(iq.ID); Session.Send(iq); }
/// <summary> /// try to add a new client's mac address. /// </summary> /// <param name="deviceInfo">The new client's info.</param> /// <returns><c>true</c> if the client was added successfully, <c>false</c> if it was already registered.</returns> public bool TryAddClient(DeviceInfo deviceInfo) { if (ConnectedClients.Any(d => d.MacAddress == deviceInfo.MacAddress)) { return(false); } lock (ConnectedClients) { ConnectedClients.Add(deviceInfo); } // Initialize the pending messages for this client if (!PendingMessages.ContainsKey(deviceInfo.MacAddress)) { lock (PendingMessages) { PendingMessages.Add(deviceInfo.MacAddress, new Queue <ChatMessage>()); } } return(true); }
/// <summary> /// try to add a new client's mac address. /// </summary> /// <param name="clientAddress">The new client's address.</param> /// <returns><c>true</c> if the client was added successfully, <c>false</c> if it was already registered.</returns> public bool TryAddClient(string clientAddress) { if (ConnectedClients.Contains(clientAddress)) { return(false); } lock (ConnectedClients) { ConnectedClients.Add(clientAddress); } // Initialize the pending messages for this client if (!PendingMessages.ContainsKey(clientAddress)) { lock (PendingMessages) { PendingMessages.Add(clientAddress, new Stack <ChatMessage>()); } } return(true); }