示例#1
0
        private async Task BackgroundDonationCheck()
        {
            Dictionary <int, StreamlabsDonation> donationsReceived = new Dictionary <int, StreamlabsDonation>();

            foreach (StreamlabsDonation donation in await this.GetDonations())
            {
                donationsReceived[donation.ID] = donation;
            }

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    foreach (StreamlabsDonation slDonation in await this.GetDonations())
                    {
                        if (!donationsReceived.ContainsKey(slDonation.ID))
                        {
                            donationsReceived[slDonation.ID] = slDonation;
                            UserDonationModel donation = slDonation.ToGenericDonation();
                            await EventCommand.ProcessDonationEventCommand(donation, OtherEventTypeEnum.StreamlabsDonation);
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(10000);
            }
        }
示例#2
0
        public override async Task Connect()
        {
            await base.Connect();

            this.SocketReceiveWrapper("connect", (data) =>
            {
                this.Connected = true;
            });

            this.SocketReceiveWrapper("new-event", (data) =>
            {
                if (data != null)
                {
                    TipeeeStreamResponse response = SerializerHelper.DeserializeFromString <TipeeeStreamResponse>(data.ToString());
                    if (response.Event.Type.Equals("donation"))
                    {
                        this.service.DonationOccurred(response.Event);
                        Task.Run(async() =>
                        {
                            UserDonationModel donation = response.Event.ToGenericDonation();
                            await EventCommand.ProcessDonationEventCommand(donation, OtherEventTypeEnum.TipeeeStreamDonation);
                        });
                    }
                }
            });

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

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

            JObject joinRoomJObj = new JObject();

            joinRoomJObj["room"]     = this.apiKey;
            joinRoomJObj["username"] = this.username;
            this.SocketSendWrapper("join-room", joinRoomJObj);

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

            if (this.Connected)
            {
                this.service.WebSocketConnectedOccurred();
            }
        }
 protected override async Task ProcessReceivedPacket(string packetJSON)
 {
     if (!string.IsNullOrEmpty(packetJSON))
     {
         GawkBoxAlert alert = JsonConvert.DeserializeObject <GawkBoxAlert>(packetJSON);
         if (alert != null && alert.Gifts.Count > 0)
         {
             UserDonationModel donation = alert.ToGenericDonation();
             await EventCommand.ProcessDonationEventCommand(donation, OtherEventTypeEnum.GawkBoxDonation);
         }
     }
 }
示例#4
0
        public override async Task Connect()
        {
            await base.Connect();

            this.SocketReceiveWrapper("connect", (data) =>
            {
                this.Connected = true;
            });

            this.SocketReceiveWrapper("realTimeTreat", (data) =>
            {
                if (data != null)
                {
                    TreatStreamEvent tsEvent = SerializerHelper.DeserializeFromString <TreatStreamEvent>(data.ToString());
                    if (tsEvent != null)
                    {
                        this.service.DonationOccurred(tsEvent);
                        Task.Run(async() =>
                        {
                            UserDonationModel donation = tsEvent.ToGenericDonation();
                            await EventCommand.ProcessDonationEventCommand(donation, OtherEventTypeEnum.TreatStreamDonation);
                        });
                    }
                }
            });

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

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

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

            if (this.Connected)
            {
                this.service.WebSocketConnectedOccurred();
            }
        }
示例#5
0
        private async Task BackgroundDonationCheck()
        {
            int             currentCampaign = 0;
            TiltifyCampaign campaign        = null;
            Dictionary <int, TiltifyDonation> donationsReceived = new Dictionary <int, TiltifyDonation>();

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    if (ChannelSession.Settings.TiltifyCampaign != currentCampaign)
                    {
                        currentCampaign = ChannelSession.Settings.TiltifyCampaign;
                        donationsReceived.Clear();

                        IEnumerable <TiltifyCampaign> campaigns = await this.GetCampaigns(this.user);

                        campaign = campaigns.FirstOrDefault(c => c.ID.Equals(currentCampaign));
                        if (campaign != null)
                        {
                            foreach (TiltifyDonation donation in await this.GetCampaignDonations(campaign))
                            {
                                donationsReceived[donation.ID] = donation;
                            }
                        }
                    }

                    if (campaign != null)
                    {
                        foreach (TiltifyDonation tDonation in await this.GetCampaignDonations(campaign))
                        {
                            if (!donationsReceived.ContainsKey(tDonation.ID))
                            {
                                donationsReceived[tDonation.ID] = tDonation;
                                UserDonationModel donation = tDonation.ToGenericDonation();
                                await EventCommand.ProcessDonationEventCommand(donation, OtherEventTypeEnum.TiltifyDonation);
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(10000);
            }
        }