/** * Called when we receive a websocket message. Responsible for invoking event handlers. */ private void HandleMessage(object sender, MessageEventArgs args) { // Abort if we get an invalid payload. if (!args.IsText) { return; } var payload = SimpleJson.DeserializeObject <JsonArray>(args.Data); // Abort if this is not a OnJsonApiEvent. if (payload.Count != 3) { return; } if ((long)payload[0] != 8 || !((string)payload[1]).Equals("OnJsonApiEvent")) { return; } // Invoke our listeners. var ev = (dynamic)payload[2]; OnWebsocketEvent?.Invoke(new OnWebsocketEventArgs() { Path = ev["uri"], Type = ev["eventType"], Data = ev["eventType"] == "Delete" ? null : ev["data"] }); }
private void OnWebsocketMessage(WebsocketEventBase args) { OnWebsocketEvent?.Invoke(args); switch (args.Path) { case Endpoints.V2_LOLLOBBY_RECEIVED_INVITATIONS: List <ReceivedInvitation> invitations = string.IsNullOrEmpty(args.RawData) ? null : JsonConvert.DeserializeObject <List <ReceivedInvitation> >(args.RawData); if (invitations.Count <= 0) { return; } OnNewInvitationsEvent?.Invoke(new NewInvitationsEvent(args, invitations)); break; case Endpoints.V1_LOLMATCHMAKING_READYCHECK: var readyCheck = string.IsNullOrEmpty(args.RawData) ? null : JsonConvert.DeserializeObject <ReadyCheck>(args.RawData); OnReadyCheckEvent?.Invoke(new ReadyCheckEvent(args, readyCheck)); break; case Endpoints.V1_RIOTMESSAGINGSERVICE_STATE: var state = System.Enum.Parse(typeof(ERmsState), args.RawData); OnRmsStateChangedEvent?.Invoke(new RmsStateChangedEvent(args, state)); break; case Endpoints.V1_CHAMP_SELECT_SESSION: var champSession = string.IsNullOrEmpty(args.RawData) ? null : JsonConvert.DeserializeObject <ChampSelectSession>(args.RawData); OnChampSelectSessionChangedEvent?.Invoke(new ChampSelectSessionEvent(args, champSession)); break; case Endpoints.V1_LOLENDOFGAME_EOGSTATSBLOCK: var eogStats = string.IsNullOrEmpty(args.RawData) ? null : JsonConvert.DeserializeObject <EogStatsBlock>(args.RawData); OnEndGameEogEvent?.Invoke(new EogStatsEvent(args, eogStats)); break; } }