GetRoomJid() public method

public GetRoomJid ( bool includeUsername ) : JabberID
includeUsername bool
return JabberID
示例#1
0
        public Future <Packet> Send(string text)
        {
            var    jid = Settings.GetRoomJid(false) ?? Settings.RecipientJid;
            Packet msg;

            if (jid == null)
            {
                throw new InvalidOperationException("An endpoint must specify either a chat channel or a recipient");
            }

            if ((Settings.ChatChannel ?? "").Length > 0)
            {
                msg = new MUC.Message.GroupChatMessage(jid, text);
            }
            else
            {
                msg = new SoapboxCore.Message.NormalMessagePacket(jid, text);
            }

            return(Session.AsyncSend(msg));
        }
示例#2
0
        protected static IEnumerator <object> DoConnect(JabberGateway gateway, EndpointSettings settings, Action <float> setStatus)
        {
            Session session = null;
            var     options = new ConnectionOptions(settings.Server);

            yield return(Jabber.AsyncLogin(
                             settings.Username, settings.Password, settings.Resource, false, options
                             ).Bind(() => session));

            setStatus(0.5f);

            // F*****g soapbox doesn't handle pings or let you handle them with strongly typed packets, wee
            session.OnXMLReceived += (xml, socketID) => {
                if (xml.Contains("<ping xmlns=\"urn:xmpp:ping\""))
                {
                    Program.Scheduler.Start(HandlePing(session, xml, socketID), TaskExecutionPolicy.RunAsBackgroundTask);
                }
            };

            var messagePrefix = settings.ChatAlias.ToLowerInvariant() + ":";

            session.AddHandler(typeof(SoapboxCore.Message.ChatMessagePacket), (p) => {
                var cm = (SoapboxCore.Message.ChatMessagePacket)p;

                string bodyText = null;
                try {
                    bodyText = cm.Body;
                } catch {
                }

                if (bodyText != null)
                {
                    HandleIncomingMessage(gateway, settings.Name, cm.From, bodyText);
                }
            });

            session.AddHandler(typeof(MUC.Message.GroupChatMessage), (p) => {
                var gcm = (MUC.Message.GroupChatMessage)p;

                string bodyText = null;
                try {
                    bodyText = gcm.Body;
                } catch {
                }

                if ((bodyText != null) && (bodyText.ToLowerInvariant().Trim().StartsWith(messagePrefix)))
                {
                    bodyText = bodyText.Substring(bodyText.IndexOf(':') + 1);
                    HandleIncomingMessage(gateway, settings.Name, gcm.From, bodyText);
                }
            });

            session.OnAsynchronousException += (e) => {
                Program.Scheduler.OnTaskError(e);
            };

            var roomJid = settings.GetRoomJid(true);

            if (roomJid != null)
            {
                yield return(session.AsyncSend(new MUC.Presence.JoinRoomRequest(roomJid)));
            }

            setStatus(1.0f);

            yield return(new Result(new Endpoint(
                                        gateway, settings, session
                                        )));
        }
示例#3
0
        protected static IEnumerator<object> DoConnect(JabberGateway gateway, EndpointSettings settings, Action<float> setStatus)
        {
            Session session = null;
            var options = new ConnectionOptions(settings.Server);
            yield return Jabber.AsyncLogin(
                settings.Username, settings.Password, settings.Resource, false, options
            ).Bind(() => session);

            setStatus(0.5f);

            // F*****g soapbox doesn't handle pings or let you handle them with strongly typed packets, wee
            session.OnXMLReceived += (xml, socketID) => {
                if (xml.Contains("<ping xmlns=\"urn:xmpp:ping\""))
                    Program.Scheduler.Start(HandlePing(session, xml, socketID), TaskExecutionPolicy.RunAsBackgroundTask);
            };

            var messagePrefix = settings.ChatAlias.ToLowerInvariant() + ":";

            session.AddHandler(typeof(SoapboxCore.Message.ChatMessagePacket), (p) => {
                var cm = (SoapboxCore.Message.ChatMessagePacket)p;

                string bodyText = null;
                try {
                    bodyText = cm.Body;
                } catch {
                }

                if (bodyText != null)
                    HandleIncomingMessage(gateway, settings.Name, cm.From, bodyText);
            });

            session.AddHandler(typeof(MUC.Message.GroupChatMessage), (p) => {
                var gcm = (MUC.Message.GroupChatMessage)p;

                string bodyText = null;
                try {
                    bodyText = gcm.Body;
                } catch {
                }

                if ((bodyText != null) && (bodyText.ToLowerInvariant().Trim().StartsWith(messagePrefix))) {
                    bodyText = bodyText.Substring(bodyText.IndexOf(':') + 1);
                    HandleIncomingMessage(gateway, settings.Name, gcm.From, bodyText);
                }
            });

            session.OnAsynchronousException += (e) => {
                Program.Scheduler.OnTaskError(e);
            };

            var roomJid = settings.GetRoomJid(true);
            if (roomJid != null)
                yield return session.AsyncSend(new MUC.Presence.JoinRoomRequest(roomJid));

            setStatus(1.0f);

            yield return new Result(new Endpoint(
                gateway, settings, session
            ));
        }