Example #1
0
        public Client() : base()
        {
            _threadDispatcher = new GameObject($"StreamLabsClientUnityDispatcher-{Guid.NewGuid()}");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnConnected    += ((object sender, bool e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnected?.Invoke(sender, e)); });
            base.OnDisconnected += ((object sender, bool e) => { ThreadDispatcher.Instance().Enqueue(() => OnDisconnected?.Invoke(sender, e)); });
            base.OnError        += ((object sender, string e) => { ThreadDispatcher.Instance().Enqueue(() => OnError?.Invoke(sender, e)); });
            base.OnUndocumented += ((object sender, string e) => { ThreadDispatcher.Instance().Enqueue(() => OnUndocumented?.Invoke(sender, e)); });

            base.OnDonation     += ((object sender, StreamlabsEvent <DonationMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnDonation?.Invoke(sender, e)); });
            base.OnStreamlabels += ((object sender, StreamlabelsEvent e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamlabels?.Invoke(sender, e)); });

            base.OnTwitchFollow       += ((object sender, StreamlabsEvent <TwitchFollowMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchFollow?.Invoke(sender, e)); });
            base.OnTwitchSubscription += ((object sender, StreamlabsEvent <TwitchSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchSubscription?.Invoke(sender, e)); });
            base.OnTwitchHost         += ((object sender, StreamlabsEvent <TwitchHostMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchHost?.Invoke(sender, e)); });
            base.OnTwitchCheer        += ((object sender, StreamlabsEvent <TwitchCheerMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchCheer?.Invoke(sender, e)); });

            base.OnYouTubeSubscription += ((object sender, StreamlabsEvent <YouTubeSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSubscription?.Invoke(sender, e)); });
            base.OnYouTubeSponsor      += ((object sender, StreamlabsEvent <YouTubeSponsorMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSponsor?.Invoke(sender, e)); });
            base.OnYouTubeSuperchat    += ((object sender, StreamlabsEvent <YouTubeSuperchatMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSuperchat?.Invoke(sender, e)); });

            base.OnMixerFollow       += ((object sender, StreamlabsEvent <MixerFollowMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerFollow?.Invoke(sender, e)); });
            base.OnMixerSubscription += ((object sender, StreamlabsEvent <MixerSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerSubscription?.Invoke(sender, e)); });
            base.OnMixerHost         += ((object sender, StreamlabsEvent <MixerHostMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerHost?.Invoke(sender, e)); });
        }
Example #2
0
        private void ForMessage(StreamlabsEvent streamlabsEvent, object eventData)
        {
            switch (streamlabsEvent.For)
            {
            case "streamlabs":
                if (streamlabsEvent.Type == "donation")
                {
                    var donation = JsonConvert.DeserializeObject <StreamlabsEvent <DonationMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Donation deserialized successfully");
                    OnDonation?.Invoke(this, donation);
                }
                break;

            case "twitch_account":
            {
                switch (streamlabsEvent.Type)
                {
                case "follow":
                {
                    var follow = JsonConvert.DeserializeObject <StreamlabsEvent <TwitchFollowMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Twitch Follow deserialized successfully");
                    OnTwitchFollow?.Invoke(this, follow);
                }
                break;

                case "subscription":
                {
                    var sub = JsonConvert.DeserializeObject <StreamlabsEvent <TwitchSubscriptionMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Twitch Sub deserialized successfully");
                    OnTwitchSubscription?.Invoke(this, sub);
                }
                break;

                case "host":
                {
                    var host = JsonConvert.DeserializeObject <StreamlabsEvent <TwitchHostMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Twitch Host deserialized successfully");
                    OnTwitchHost?.Invoke(this, host);
                }
                break;

                case "bits":
                {
                    var cheer = JsonConvert.DeserializeObject <StreamlabsEvent <TwitchCheerMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Twitch Cheer deserialized successfully");
                    OnTwitchCheer?.Invoke(this, cheer);
                }
                break;
                }
            }
            break;

            case "youtube_account":
            {
                switch (streamlabsEvent.Type)
                {
                case "follow":
                {
                    var follow = JsonConvert.DeserializeObject <StreamlabsEvent <YouTubeSubscriptionMessage> >(eventData.ToString());
                    _logger?.LogDebug($"YouTube Sub deserialized successfully");
                    OnYouTubeSubscription?.Invoke(this, follow);
                }
                break;

                case "subscription":
                {
                    var sub = JsonConvert.DeserializeObject <StreamlabsEvent <YouTubeSponsorMessage> >(eventData.ToString());
                    _logger?.LogDebug($"YouTube Sponsor deserialized successfully");
                    OnYouTubeSponsor?.Invoke(this, sub);
                }
                break;

                case "superchat":
                {
                    var super = JsonConvert.DeserializeObject <StreamlabsEvent <YouTubeSuperchatMessage> >(eventData.ToString());
                    _logger?.LogDebug($"YouTube Superchat deserialized successfully");
                    OnYouTubeSuperchat?.Invoke(this, super);
                }
                break;
                }
            }
            break;

            case "mixer_account":
            {
                switch (streamlabsEvent.Type)
                {
                case "follow":
                {
                    var follow = JsonConvert.DeserializeObject <StreamlabsEvent <MixerFollowMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Mixer Follow deserialized successfully");
                    OnMixerFollow?.Invoke(this, follow);
                }
                break;

                case "subscription":
                {
                    var sub = JsonConvert.DeserializeObject <StreamlabsEvent <MixerSubscriptionMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Mixer Sub deserialized successfully");
                    OnMixerSubscription?.Invoke(this, sub);
                }
                break;

                case "host":
                {
                    var host = JsonConvert.DeserializeObject <StreamlabsEvent <MixerHostMessage> >(eventData.ToString());
                    _logger?.LogDebug($"Mixer Host deserialized successfully");
                    OnMixerHost?.Invoke(this, host);
                }
                break;
                }
            }
            break;
            }
        }