//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 20/01/2018 Created [Fabian Sauter] /// </history> public MUCHandler() { TIMED_LIST = new TSTimedList <MUCJoinHelper> { itemTimeoutInMs = (int)TimeSpan.FromSeconds(20).TotalMilliseconds }; }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 05/05/2018 Created [Fabian Sauter] /// </history> public XMPPConnection2(XMPPAccount account) : base(account) { this.holdConnection = false; this.connectionErrorCount = 0; this.lastConnectionError = null; this.TCP_CONNECTION = new TCPConnection2(account); this.TCP_CONNECTION.ConnectionStateChanged += TCPConnection_ConnectionStateChanged; this.TCP_CONNECTION.NewDataReceived += TCPConnection_NewDataReceived; this.PARSER = new MessageParser2(); this.MESSAGE_PROCESSORS = new AbstractMessageProcessor[4]; this.streamId = null; this.messageIdCache = new TSTimedList <string>(); this.connectionTimer = null; this.reconnectRequested = false; this.timeout = TimeSpan.FromMilliseconds(CONNECTION_TIMEOUT); this.GENERAL_COMMAND_HELPER = new GeneralCommandHelper(this); this.MUC_COMMAND_HELPER = new MUCCommandHelper(this); this.PUB_SUB_COMMAND_HELPER = new PubSubCommandHelper(this); this.OMEMO_COMMAND_HELPER = new OmemoCommandHelper(this); // The order in which new messages should get processed (TLS -- SASL -- Stream Management -- Resource binding -- ...). // https://xmpp.org/extensions/xep-0170.html //------------------------------------------------------------- // TLS: this.MESSAGE_PROCESSORS[0] = new TLSConnection(TCP_CONNECTION, this); // SASL: this.MESSAGE_PROCESSORS[1] = new SASLConnection(TCP_CONNECTION, this); // XEP-0198 (Stream Management): this.MESSAGE_PROCESSORS[2] = new SMConnection(TCP_CONNECTION, this); // Resource binding: RecourceBindingConnection recourceBindingConnection = new RecourceBindingConnection(TCP_CONNECTION, this); recourceBindingConnection.ResourceBound += RecourceBindingConnection_ResourceBound; this.MESSAGE_PROCESSORS[3] = recourceBindingConnection; //------------------------------------------------------------- NetworkHelper.Instance.NetworkChanged += Instance_NetworkChanged; this.omemoHelper = null; this.DISCO_FEATURE_HELPER = new DiscoFeatureHelper(this); }
/// <summary> /// Connects to the XMPP server. /// </summary> private async Task connectAsync() { if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { connectionErrorCount = 3; lastConnectionError = new ConnectionError(ConnectionErrorCode.NO_INTERNET); setState(ConnectionState.ERROR, lastConnectionError); reconnectRequested = false; holdConnection = false; Logger.Warn("[XMPPConnection2]: Unable to connect to " + account.serverAddress + " - no internet!"); return; } switch (state) { case ConnectionState.DISCONNECTED: case ConnectionState.ERROR: if (connectionErrorCount < 3) { setState(ConnectionState.CONNECTING); // Reset stuff: streamId = null; messageIdCache = new TSTimedList <string>(); resetMessageProcessors(); await TCP_CONNECTION.connectAsync(); } break; default: Logger.Warn("[XMPPConnection2]: Trying to connect but state is not " + ConnectionState.DISCONNECTED + " or " + ConnectionState.ERROR + "! State = " + state); await reconnectAsync(false); break; } }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 03/01/2018 Created [Fabian Sauter] /// </history> public DiscoDBManager() { this.messageIdCache = new TSTimedList <string>(); ConnectionHandler.INSTANCE.ClientConnected += INSTANCE_ClientConnected; }