public void Start(XmppConnection connection) { connection.Features = Stanza.Parse <Features>(connection.NextElement()); if (connection.Features.Bind) { var bind = new Elements.Bind(connection.Jid.Resource); var iq = new XMPPIq(XMPPIq.IqTypes.set); iq.Add(bind); connection.Query(iq, (bindResult) => { var jid = bindResult.Element(XNamespace.Get(Namespaces.XmppBind) + "bind"); if (jid == null) { return; } connection.Jid = new JID(jid.Element(XNamespace.Get(Namespaces.XmppBind) + "jid").Value); if (connection.Features.Session) { var sess = new XElement(XNamespace.Get(Namespaces.XmppSession) + "session"); var sessIq = new XMPPIq(XMPPIq.IqTypes.set); sessIq.Add(sess); connection.Query(sessIq, (sessionResponse) => OnSessionStarted(connection)); } else { OnSessionStarted(connection); } }); connection.SessionLoop(); } }
public BookmarksManager(XmppConnection conn, bool autoAsk = true) { connection = conn; connection.SignedIn += (sender, e) => { if (autoAsk) { var query = new XMPPIq(XMPPIq.IqTypes.get); var priv = new XElement(XNamespace.Get("jabber:iq:private") + "query", new XElement(XNamespace.Get(Namespaces.StorageBookmarks) + "storage") ); query.Add(priv); connection.Query(query, (response) => { var roomsXML = response.Element(XNamespace.Get("jabber:iq:private") + "query") .Element(XNamespace.Get(Namespaces.StorageBookmarks) + "storage") .Elements(XNamespace.Get(Namespaces.StorageBookmarks) + "conference"); foreach (var roomObj in roomsXML) { var room = Stanza.Parse <BookmarkedConference>(roomObj); Rooms.Add(room); if (room.IsAutojoin) { Join(room); } } OnBookmarksSynced(conn); }); } }; }
public RosterManager(XmppConnection conn, bool autoAsk = true) { Roster = new ObservableCollection <RosterItem>(); conn.SignedIn += (sender, e) => { if (autoAsk) { var query = new XMPPIq(XMPPIq.IqTypes.get); query.Add(new XElement(XNamespace.Get(Namespaces.JabberRoster) + "query")); conn.Query(query, (response) => { var roster = response.Element(XNamespace.Get(Namespaces.JabberRoster) + "query") .Elements(XNamespace.Get(Namespaces.JabberRoster) + "item"); foreach (var item in roster) { Roster.Add(Stanza.Parse <RosterItem>(item)); } OnRosterUpdated(conn); }); } }; }