/// <summary> /// Subscribe to a contact /// </summary> /// <param name="to">Bare Jid of the rosteritem we want to subscribe</param> /// <param name="message">a message which normally contains the reason why we want to subscibe to this contact</param> public void Subscribe(Jid to, string message) { Presence pres = new Presence(); pres.Type = PresenceType.subscribe; pres.To = to; pres.Status = message; m_connection.Send(pres); }
/// <summary> /// Subscribe to a contact /// </summary> /// <param name="to">Bare Jid of the rosteritem we want to subscribe</param> public void Subscribe(Jid to) { // <presence to='*****@*****.**' type='subscribe'/> Presence pres = new Presence(); pres.Type = PresenceType.subscribe; pres.To = to; m_connection.Send(pres); }
//Example: Refusing a presence subscription request: //<presence to='*****@*****.**' type='unsubscribed'/> /// <summary> /// Refuse subscription request /// </summary> /// <param name="to">Bare Jid to approve</param> public void RefuseSubscriptionRequest(Jid to) { // <presence to='*****@*****.**' type='subscribe'/> Presence pres = new Presence(); pres.Type = PresenceType.unsubscribed; pres.To = to; m_connection.Send(pres); }
/// <summary> /// Leave a conference room /// </summary> /// <param name="room"></param> /// <param name="nickname"></param> public void LeaveRoom(Jid room, string nickname) { Jid to = new Jid(room.ToString()); to.Resource = nickname; Presence pres = new Presence(); pres.To = to; pres.Type = PresenceType.unavailable; m_connection.Send(pres); }
/// <summary> /// Join a chatroom /// </summary> /// <param name="room">jid of the room to join</param> /// <param name="nickname">nickname to use in the room</param> /// <param name="password">password for password protected chat rooms</param> /// <param name="disableHistory">true for joining without chat room history</param> public void JoinRoom(Jid room, string nickname, string password, bool disableHistory) { /* <presence from='[email protected]/pda' to='[email protected]/thirdwitch'> <x xmlns='http://jabber.org/protocol/muc'> <password>cauldron</password> </x> </presence> join room and request no history <presence from='[email protected]/pda' to='[email protected]/thirdwitch'> <x xmlns='http://jabber.org/protocol/muc'> <history maxchars='0'/> </x> </presence> */ Jid to = new Jid(room.ToString()); to.Resource = nickname; Presence pres = new Presence(); pres.To = to; Muc x = new Muc(); if (password != null) x.Password = password; if (disableHistory) { History hist = new History(); hist.MaxCharacters = 0; x.History = hist; } pres.AddChild(x); m_connection.Send(pres); }
/// <summary> /// Change the Nickname in a room /// </summary> /// <param name="room"></param> /// <param name="newNick"></param> public void ChangeNickname(Jid room, string newNick) { Jid to = new Jid(room.ToString()); to.Resource = newNick; Presence pres = new Presence(); pres.To = to; m_connection.Send(pres); }
/// <summary> /// Sends our Presence, the packet is built of Status, Show and Priority /// </summary> public void SendMyPresence() { Presence pres = new Presence(m_Show, m_Status, m_Priority); // Add client caps when enabled if (m_EnableCapabilities) { if (m_Capabilities.Version == null) UpdateCapsVersion(); pres.AddChild(m_Capabilities); } this.Send(pres); }
/// <summary> /// A presence is received. Now check if its from a Jid we are looking for and /// raise the event in this case. /// </summary> /// <param name="sender"></param> /// <param name="pres"></param> private void m_connection_OnPresence(object sender, Presence pres) { if (pres == null) return; lock (m_grabbing) { IDictionaryEnumerator myEnum = m_grabbing.GetEnumerator(); while(myEnum.MoveNext()) { TrackerData t = myEnum.Value as TrackerData; if (t.comparer.Compare(new Jid((string)myEnum.Key), pres.From) == 0) { // Execute the callback t.cb(this, pres, t.data); } } } }