コード例 #1
0
        private async Task <bool> ConnectSocket()
        {
            await this.socket.Connect("https://nodeapi.treatstream.com/", "token=" + this.socketToken);

            this.socket.Listen("connect", (data) =>
            {
                this.WebSocketConnected = true;
            });

            this.socket.Listen("realTimeTreat", (data) =>
            {
                if (data != null)
                {
                    TreatStreamEvent tsEvent = JSONSerializerHelper.DeserializeFromString <TreatStreamEvent>(data.ToString());
                    if (tsEvent != null)
                    {
                        this.DonationOccurred(tsEvent);
                        Task.Run(async() =>
                        {
                            await EventService.ProcessDonationEvent(EventTypeEnum.TreatStreamDonation, tsEvent.ToGenericDonation());
                        });
                    }
                }
            });

            this.socket.Listen("error", async(errorData) =>
            {
                if (errorData != null)
                {
                    Logger.Log(errorData.ToString());
                }

                this.WebSocketDisconnectedOccurred();
                await this.ConnectSocket();
            });

            this.socket.Listen("disconnect", async(errorData) =>
            {
                if (errorData != null)
                {
                    Logger.Log(errorData.ToString());
                }

                this.WebSocketDisconnectedOccurred();
                await this.ConnectSocket();
            });

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

            if (this.WebSocketConnected)
            {
                this.WebSocketConnectedOccurred();
                return(true);
            }
            return(false);
        }
コード例 #2
0
 public void DonationOccurred(TreatStreamEvent eventData)
 {
     this.OnDonationOccurred(this, eventData);
 }