Beispiel #1
0
        public async Task StartFresh()
        {
            Log("Starting fresh");
            if (!InternetAvailable())
            {
                Log("Internet not available. Exiting.");
                return;
            }

            if (Running)
            {
                Log("realtime client is already running");
                return;
            }

            if (AppIsInBackground)
            {
                Log("Application is in background");
                return;
            }
            if (Socket != null)
            {
                Shutdown();
                await Task.Delay(350);
            }
            try
            {
                var connectPacket = new FbnsConnectPacket
                {
                    Payload = await RealtimePayload.BuildPayload(_instaApi)
                };
                Socket = new StreamSocket();
                Socket.Control.KeepAlive = true;
                Socket.Control.NoDelay   = true;
                Socket.Control.OutboundBufferSizeInBytes = 20 * 1024 * 1024;
                await Socket.ConnectAsync(new HostName(DEFAULT_HOST), "443", SocketProtectionLevel.Tls12);

                _inboundReader                    = new DataReader(Socket.InputStream);
                _outboundWriter                   = new DataWriter(Socket.OutputStream);
                _inboundReader.ByteOrder          = ByteOrder.BigEndian;
                _inboundReader.InputStreamOptions = InputStreamOptions.Partial;
                _outboundWriter.ByteOrder         = ByteOrder.BigEndian;
                _runningTokenSource               = new CancellationTokenSource();
                await FbnsPacketEncoder.EncodePacket(connectPacket, _outboundWriter);
            }
            catch (Exception e)
            {
                DebugLogger.LogExceptionX(e);
                Restart();
                return;
            }
            StartPollingLoop();
        }