public void ResubscribeOccurred(GameWispResubscribeEvent eventData)
 {
     if (this.OnResubscribeOccurred != null)
     {
         this.OnResubscribeOccurred(this, eventData);
     }
 }
        public override async Task Connect()
        {
            await base.Connect();

            this.SocketReceiveWrapper("unauthorized", (errorData) =>
            {
                MixItUp.Base.Util.Logger.Log(errorData.ToString());
            });

            this.SocketReceiveWrapper("disconnect", (errorData) =>
            {
                MixItUp.Base.Util.Logger.Log(errorData.ToString());
                this.service.WebSocketDisconnectedOccurred();
            });

            this.SocketReceiveWrapper("connect", (connectData) =>
            {
                JObject jobj   = new JObject();
                jobj["key"]    = GameWispService.ClientID;
                jobj["secret"] = ChannelSession.SecretManager.GetSecret("GameWispSecret");
                this.SocketSendWrapper("authentication", jobj);
            });

            this.SocketReceiveWrapper("authenticated", (authData) =>
            {
                if (authData != null)
                {
                    JObject sendJObj         = new JObject();
                    sendJObj["access_token"] = this.oauthToken.accessToken;
                    this.SocketSendWrapper("channel-connect", sendJObj);
                }
            });

            this.SocketReceiveWrapper("app-channel-connected", (appChannelData) =>
            {
                if (appChannelData != null)
                {
                    JObject jobj = JObject.Parse(appChannelData.ToString());
                    if (jobj != null && jobj["data"] != null && jobj["data"]["status"] != null && jobj["data"]["channel_id"] != null)
                    {
                        if (jobj["data"]["status"].ToString().Equals("authenticated"))
                        {
                            this.channelID = jobj["data"]["channel_id"].ToString();
                        }
                    }
                }
            });

            this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-new", (eventData) =>
            {
                GameWispSubscribeEvent subscribeEvent = new GameWispSubscribeEvent(eventData.Data);
                this.service.SubscribeOccurred(subscribeEvent);
                Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispSubscribed)), subscribeEvent); });
            });

            this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-renewed", (eventData) =>
            {
                GameWispResubscribeEvent resubscribeEvent = new GameWispResubscribeEvent(eventData.Data);
                this.service.ResubscribeOccurred(resubscribeEvent);
                Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispResubscribed)), resubscribeEvent); });
            });

            this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-benefits-change", (eventData) =>
            {
                this.service.SubscriberBenefitsChangeOccurred(new GameWispBenefitsChangeEvent(eventData.Data));
            });

            this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-status-change", (eventData) =>
            {
                GameWispSubscribeEvent subscribeEvent = new GameWispSubscribeEvent(eventData.Data);
                this.service.SubscriberStatusChangeOccurred(subscribeEvent);
                Task.Run(async() => { await this.RunGameWispCommand(ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GameWispSubscribed)), subscribeEvent); });
            });

            this.SocketEventReceiverWrapper <GameWispWebSocketEvent>("subscriber-anniversary", (eventData) =>
            {
                this.service.SubscriberAnniversaryOccurred(new GameWispAnniversaryEvent(eventData.Data));
            });

            for (int i = 0; i < 10 && !this.ConnectedAndAuthenticated; i++)
            {
                await Task.Delay(1000);
            }

            if (this.ConnectedAndAuthenticated)
            {
                this.service.WebSocketConnectedOccurred();
            }
        }