コード例 #1
0
        protected async override Task processMessageAsync(NewValidMessageEventArgs args)
        {
            AbstractMessage msg = args.MESSAGE;

            if (state == RecourceBindingState.BOUND || state == RecourceBindingState.ERROR || msg.isProcessed())
            {
                return;
            }
            switch (state)
            {
            case RecourceBindingState.UNBOUND:
                if (msg is StreamFeaturesMessage || msg is OpenStreamAnswerMessage)
                {
                    StreamFeaturesMessage features;
                    if (msg is OpenStreamAnswerMessage)
                    {
                        features = (msg as OpenStreamAnswerMessage).getStreamFeaturesMessage();
                    }
                    else
                    {
                        features = msg as StreamFeaturesMessage;
                    }

                    if (features is null)
                    {
                        return;
                    }
                    if (features.containsFeature("bind"))
                    {
                        setMessageProcessed(args);
                        BindResourceMessage bindMsg = new BindResourceMessage(XMPP_CONNECTION.account.user.resourcePart);
                        id = bindMsg.ID;
                        await XMPP_CONNECTION.SendAsync(bindMsg, true);

                        state = RecourceBindingState.BINDING;
                    }
                }
                break;

            case RecourceBindingState.BINDING:
                if (msg is IQMessage)
                {
                    IQMessage iQM = msg as IQMessage;
                    if (string.Equals(iQM.ID, id))
                    {
                        stopListeningForMessages();
                        setMessageProcessed(args);
                        XMPP_CONNECTION.SendAsync(new StartSessionMessage(), true).Wait();
                        state = RecourceBindingState.BOUND;
                        ResourceBound?.Invoke(this, new EventArgs());
                    }
                }
                break;
            }
        }
コード例 #2
0
 //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
 #region --Misc Methods (Public)--
 public override void reset()
 {
     state = RecourceBindingState.UNBOUND;
     id    = null;
     startListeningForMessages();
 }