示例#1
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;
            }
        }
示例#2
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)); });
        }
示例#3
0
        public void Connect(string socketToken)
        {
            string url = $"https://sockets.streamlabs.com";

            IO.Options opt = new IO.Options
            {
                QueryString       = $"token={socketToken}",
                Reconnection      = true,
                ReconnectionDelay = 500,
                Port        = 433,
                Secure      = true,
                AutoConnect = false,
                Upgrade     = true
            };

            Quobject.SocketIoClientDotNet.Client.Socket socket = IO.Socket(url, opt);

            socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT, () => {
                log?.LogDebug("Connected");
                OnConnected?.Invoke(this, new EventArgs());
            });

            socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_DISCONNECT, data => {
                log?.LogDebug($"Disonnected: {data}");
                OnDisconnected?.Invoke(this, (string)data);
            });

            socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_ERROR, data => {
                log?.LogDebug($"Error: {data}");
                OnError?.Invoke(this, data);
            });

            socket.On("event", data => {
                log?.LogTrace($"EventData: {data}");
                Console.WriteLine(data);

                StreamlabsEvent streamlabsEvent = JsonConvert.DeserializeObject <StreamlabsEvent>(data.ToString());
                Console.WriteLine(data);

                JToken token = streamlabsEvent.Message;
                if (token.Type == JTokenType.Array)
                {
                    token = token.First;
                }

                switch (streamlabsEvent.Type)
                {
                case "streamlabels.underlying":
                    OnStreamlabels?.Invoke(this, token.ToObject <StreamlabsLabels>());
                    return;

                case "donation":
                    OnDonation?.Invoke(this, token.ToObject <StreamlabsDonation>());
                    break;

                case "redemption":
                    break;

                case "subscription":
                    switch (token["platform"].Value <string>())
                    {
                    case "twitch_account":
                        OnTwitchSubscription?.Invoke(this, token.ToObject <StreamlabsTwitchSubscription>());
                        break;
                    }

                    break;

                case "follow":
                    switch (token["platform"].Value <string>())
                    {
                    case "twitch_account":
                        OnTwitchFollow?.Invoke(this, token.ToObject <StreamlabsTwitchFollow>());
                        break;
                    }

                    break;

                case "host":
                    switch (token["platform"].Value <string>())
                    {
                    case "twitch_account":
                        OnTwitchHost?.Invoke(this, token.ToObject <StreamlabsTwitchHost>());
                        break;
                    }

                    break;

                case "bits":
                    switch (token["platform"].Value <string>())
                    {
                    case "twitch_account":
                        OnTwitchCheer?.Invoke(this, token.ToObject <StreamlabsTwitchCheer>());
                        break;
                    }

                    break;

                case "raid":
                    switch (token["platform"].Value <string>())
                    {
                    case "twitch_account":
                        OnTwitchRaid?.Invoke(this, token.ToObject <StreamlabsTwitchRaid>());
                        break;
                    }

                    break;

                default:
                    OnUndocumented?.Invoke(this, token);
                    break;
                }

                // else if (streamlabsEvent.Message.GetType() is "redemption")
                // {
                // }
                // else if (streamlabsEvent.Message.GetType() is "pausequeue")
                // {
                // }
                // else if (streamlabsEvent.Message.GetType() is "unpausequeue")
                // {
                // }
                // else if (streamlabsEvent.Message.GetType() is "mutevolume")
                // {
                // }
                // else if (streamlabsEvent.Message.GetType() is "unmutevolume")
                // {
                // }
                // else if (streamlabsEvent.Message.GetType() is "skipalert")
                // {
                // }
            });

            socket.Open();
        }