Beispiel #1
0
        private static XmlElement CreateStatusUpdateStanza(PresenceStatus presenceStatus)
        {
            var stanzaType = presenceStatus.IsAvailable ? string.Empty : PresenceStanza.Type.Unavailable;
            var showStatus = ToShowStatus(presenceStatus.AvailabilitySubstate);

            return(PresenceStanza.New(stanzaType, showStatus, presenceStatus.StatusText));
        }
Beispiel #2
0
        public async Task SendUnsubscribeRequestAsync_Sends_Correct_Presence_Stanza()
        {
            var subscriptionJid = $"{Guid.NewGuid()}@domain.com";
            var expectedStanza  = PresenceStanza.New(PresenceStanza.Type.Unsubscribe).To(subscriptionJid);
            var actualStanza    = default(XmlElement);

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(e => actualStanza = e);

            await MessageSender.SendUnsubscribeRequestAsync(subscriptionJid);

            Assert.Equal(expectedStanza, actualStanza);
        }
Beispiel #3
0
        void presenceHandlerMethod(PresenceStanza presence)
        {
            //Console.WriteLine("Presence from " + presence.From);
            JabberContact contact = Roster[presence.From];

            if (contact != null)
            {
                contact.UpdatePresence(presence);
            }
            else
            {
                //Console.WriteLine("Unknown contact " + presence.From);
            }
        }
Beispiel #4
0
    public void JabberPresenceHandler(PresenceStanza message)
    {
        if (message.From == (Jid + "@" + Server))
        {
            switch (message.Type)
            {
            case "available":
                /* join conference */
                Log.AddMessage("Jabber", " [i] Join KrakenNet... ");
                JoinConference();
                break;

            case "unavailable":
            case "error":
                InKrakenNet = false;
                Log.AddMessage("Jabber", " [E] Not in KrakenNet, retrying...");
                Client.SendPresence(Jid, "available");
                break;

            default:
                Log.AddMessage("Jabber", " [E] Unhandled XMPP presence: ");
                Log.AddMessage("Jabber", "     Presence: " + message.From + " is " + message.Type);
                break;
            }
        }

        if (message.From == Conference)
        {
            if (message.FromResource == ConferenceJid)
            {
                switch (message.Type)
                {
                case "available":
                    if (!InKrakenNet)
                    {
                        Log.AddMessage("Jabber", " [i] We are in KrakenNet now");
                    }
                    InKrakenNet = true;
                    break;

                case "unavailable":
                case "error":
                    InKrakenNet = false;
                    Log.AddMessage("Jabber", " [E] Not in KrakenNet channel anymore, retrying...");
                    JoinConference(5000);
                    break;

                default:
                    Log.AddMessage("Jabber", " [E] Unhandled XMPP presence: ");
                    Log.AddMessage("Jabber", "     Presence: " + message.From + " is " + message.Type);
                    break;
                }
            }
            else
            {
                string name = message.FromResource.Split('/')[1];

                switch (message.Type)
                {
                case "available":
                    Log.AddMessage("Jabber", " [i] KrakenNet: " + name + " joined");
                    break;

                case "unavailable":
                case "error":
                    Log.AddMessage("Jabber", " [i] KrakenNet: " + name + " left");
                    break;

                default:
                    Log.AddMessage("Jabber", " [E] Unhandled XMPP presence: ");
                    Log.AddMessage("Jabber", "     Presence: " + message.From + " is " + message.Type);
                    break;
                }
            }
        }

        if (message.Type == "subscribe")
        {
            Log.AddMessage("Jabber", "Presence: Accepted " + message.From);
            Client.SendPresence(message.From, "subscribed");
        }
    }
Beispiel #5
0
 public void UpdatePresence(PresenceStanza p)
 {
     Show     = p.Show;   // online, offline, away, xa, chat, dnd
     Status   = p.Status; // user defined
     Priority = p.Priority;
 }
Beispiel #6
0
        void mainLoop()
        {
            DateTime time = DateTime.Now;

            while (true)
            {
                string msgReceived = null;

                if (DateTime.Now.Subtract(time).TotalSeconds > 60)
                {
                    Ping();
                    time = DateTime.Now;
                }

                try
                {
                    msgReceived = connection.Receive(200);
                }
                catch (IOException ioe)
                {
                    connection.Disconnect();
                    if (ConnectionStatusHandler != null)
                    {
                        ConnectionStatusHandler(false);
                    }
                    return;
                }

                if (msgReceived == "</stream:stream>")
                {
                    //Console.WriteLine("TODO: Close connection and thread!");
                    connection.Disconnect();
                    if (ConnectionStatusHandler != null)
                    {
                        ConnectionStatusHandler(false);
                    }
                    return;
                }
                else if (msgReceived != null)
                {
                    // process message
                    XmlDocument xdoc = new XmlDocument();
                    try
                    {
                        xdoc.LoadXml(msgReceived);

                        if (xdoc != null)
                        {
                            switch (xdoc.FirstChild.Name)
                            {
                            case "message":
                            {
                                if (MessageHandler != null)
                                {
                                    MessageStanza message = new MessageStanza(msgReceived);
                                    if (message != null)
                                    {
                                        MessageHandler(message);
                                    }
                                }
                                break;
                            }

                            case "presence":
                            {
                                if (PresenceHandler != null)
                                {
                                    PresenceStanza presence = new PresenceStanza(msgReceived);
                                    if (presence != null)
                                    {
                                        PresenceHandler(presence);
                                    }
                                }
                                break;
                            }

                            default:
                            {
                                MessageStanza message = new MessageStanza();
                                message.From = "MessageListener";
                                message.Body = new System.Collections.Hashtable();
                                message.Body.Add("", "Unknown message: \"" + msgReceived + "\"");
                                if (message != null)
                                {
                                    MessageHandler(message);
                                }
                                break;
                            }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error loading message: \"" + msgReceived + "\"");
                    }
                    //Console.WriteLine (msgReceived);
                }

                if (DialogEnabled)
                {
                    lock ((Object)threadWaiting)
                    {
                        threadWaiting = true;
                    }
                    while (DialogEnabled)
                    {
                        Thread.Sleep(200);
                    }
                    lock ((Object)threadWaiting)
                    {
                        threadWaiting = false;
                    }
                }
            }
        }