Example #1
0
        /**
         * Closes the connection with the hub. Should be invoked when League closes.
         */
        public void Close()
        {
            if (hasClosed)
            {
                return;
            }
            hasClosed = true;

            // Close socket.
            if (socket.ReadyState == WebSocketState.Open)
            {
                socket.Close();
            }

            // Call destructors for mobile connections.
            foreach (var connection in connections.Values)
            {
                connection.OnClose();
            }

            // Release resources.
            socket = null;
            league = null;

            connections.Clear();
            connections = null;
        }
Example #2
0
        public HubConnectionHandler(LeagueConnection league)
        {
            this.league = league;

            // Pass parameters in the URL.
            socket = new WebSocket(
                App.HUB_WS
                + "?token=" + HttpUtility.UrlEncode(Persistence.GetHubToken())
                + "&publicKey=" + HttpUtility.UrlEncode(CryptoHelpers.ExportPublicKey())
                );

            socket.OnMessage += HandleMessage;
            socket.OnClose   += (sender, ev) =>
            {
                // Invoke the close handler unless we explicitly triggered this closure.
                // Note that we invoke the event handler and close ourselves as well.
                // This means that in all cases, anyone listening to the closure event does
                // not have to close us. They only need to call Close on us if we want to
                // terminate a connection that is still stable.
                if (!hasClosed)
                {
                    OnClose?.Invoke();
                    Close();
                }
            };

            socket.Connect();
        }
Example #3
0
        public HubConnectionHandler(LeagueConnection league)
        {
            this.league = league;

            socket = new WebSocket(Program.HUB_WS);
            socket.CustomHeaders = new Dictionary <string, string>()
            {
                { "Token", Persistence.GetHubToken() },
                { "Public-Key", CryptoHelpers.ExportPublicKey() }
            };

            socket.OnMessage += HandleMessage;
            socket.OnClose   += (sender, ev) =>
            {
                // Invoke the close handler unless we explicitly triggered this closure.
                // Note that we invoke the event handler and close ourselves as well.
                // This means that in all cases, anyone listening to the closure event does
                // not have to close us. They only need to call Close on us if we want to
                // terminate a connection that is still stable.
                if (!hasClosed)
                {
                    OnClose?.Invoke();
                    Close();
                }
            };

            socket.Connect();
        }
Example #4
0
        public MobileConnectionHandler(LeagueConnection league, SendMessageDelegate send)
        {
            this.league = league;
            this.league.OnWebsocketEvent += HandleLeagueEvent;

            this.SendRaw = send;
            this.Send    = msg => SendRaw("\"" + CryptoHelpers.EncryptAES(key, msg) + "\"");
        }
Example #5
0
        public ConnectionManager(App app)
        {
            this.app    = app;
            this.league = new LeagueConnection();

            // Hook up league events.
            league.OnConnected += () =>
            {
                DebugLogger.Global.WriteMessage($"ConnectionManager is connected to League of Legends.");
                Connect();
            };
            league.OnDisconnected += () =>
            {
                DebugLogger.Global.WriteMessage($"ConnectionManager is disconnected from League of Legends.");
                Close();
            };
        }