Esempio n. 1
0
        public PubSub(EndPoint proxy = null) : base(null, proxy)
        {
            _threadDispatcher = new GameObject("TwitchPubSubUnityDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnPubSubServiceConnected += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnPubSubServiceConnected?.Invoke(sender, e)); });
            base.OnPubSubServiceError     += ((object sender, OnPubSubServiceErrorArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnPubSubServiceError?.Invoke(sender, e)); });
            base.OnPubSubServiceClosed    += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnPubSubServiceClosed?.Invoke(sender, e)); });
            base.OnListenResponse         += ((object sender, OnListenResponseArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnListenResponse?.Invoke(sender, e)); });
            base.OnTimeout             += ((object sender, OnTimeoutArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnTimeout?.Invoke(sender, e)); });
            base.OnBan                 += ((object sender, OnBanArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnBan?.Invoke(sender, e)); });
            base.OnUnban               += ((object sender, OnUnbanArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUnban?.Invoke(sender, e)); });
            base.OnUntimeout           += ((object sender, OnUntimeoutArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUntimeout?.Invoke(sender, e)); });
            base.OnHost                += ((object sender, OnHostArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnHost?.Invoke(sender, e)); });
            base.OnSubscribersOnly     += ((object sender, OnSubscribersOnlyArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnSubscribersOnly?.Invoke(sender, e)); });
            base.OnSubscribersOnlyOff  += ((object sender, OnSubscribersOnlyOffArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnSubscribersOnlyOff?.Invoke(sender, e)); });
            base.OnClear               += ((object sender, OnClearArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnClear?.Invoke(sender, e)); });
            base.OnEmoteOnly           += ((object sender, OnEmoteOnlyArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnEmoteOnly?.Invoke(sender, e)); });
            base.OnEmoteOnlyOff        += ((object sender, OnEmoteOnlyOffArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnEmoteOnlyOff?.Invoke(sender, e)); });
            base.OnR9kBeta             += ((object sender, OnR9kBetaArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnR9kBeta?.Invoke(sender, e)); });
            base.OnR9kBetaOff          += ((object sender, OnR9kBetaOffArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnR9kBetaOff?.Invoke(sender, e)); });
            base.OnBitsReceived        += ((object sender, OnBitsReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnBitsReceived?.Invoke(sender, e)); });
            base.OnStreamUp            += ((object sender, OnStreamUpArgs arg) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamUp(sender, arg)); });
            base.OnStreamDown          += ((object sender, OnStreamDownArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamDown?.Invoke(sender, e)); });
            base.OnViewCount           += ((object sender, OnViewCountArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnViewCount?.Invoke(sender, e)); });
            base.OnWhisper             += ((object sender, OnWhisperArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnWhisper?.Invoke(sender, e)); });
            base.OnChannelSubscription += ((object sender, OnChannelSubscriptionArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChannelSubscription?.Invoke(sender, e)); });
        }
Esempio n. 2
0
 public void Invoke <T>(Func <Task <T> > func, Action <T> action)
 {
     Task.Run(func).ContinueWith((x) =>
     {
         var value = x.Result;
         ThreadDispatcher.Instance().Enqueue(() => action.Invoke(value));
     });
 }
Esempio n. 3
0
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, bool checkStatusOnStart = true, bool invokeEventsOnStart = false) : base(api, checkIntervalSeconds, checkStatusOnStart, invokeEventsOnStart)
        {
            _threadDispatcher = new GameObject("ThreadDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnStreamOnline         += ((object sender, OnStreamOnlineArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamOnline?.Invoke(sender, e)); });
            base.OnStreamOffline        += ((object sender, OnStreamOfflineArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamOffline?.Invoke(sender, e)); });
            base.OnStreamUpdate         += ((object sender, OnStreamUpdateArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamUpdate?.Invoke(sender, e)); });
            base.OnStreamMonitorStarted += ((object sender, OnStreamMonitorStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamMonitorStarted?.Invoke(sender, e)); });
            base.OnStreamMonitorEnded   += ((object sender, OnStreamMonitorEndedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamMonitorEnded?.Invoke(sender, e)); });
            base.OnStreamsSet           += ((object sender, OnStreamsSetArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamsSet?.Invoke(sender, e)); });
        }
Esempio n. 4
0
        public Client() : base(null)
        {
            _threadDispatcher = new GameObject("TwitchClientUnityDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnLog                              += ((object sender, OnLogArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLog?.Invoke(sender, e)); });
            base.OnConnected                        += ((object sender, OnConnectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnected?.Invoke(sender, e)); });
            base.OnJoinedChannel                    += ((object sender, OnJoinedChannelArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnJoinedChannel?.Invoke(sender, e)); });
            base.OnIncorrectLogin                   += ((object sender, OnIncorrectLoginArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnIncorrectLogin?.Invoke(sender, e)); });
            base.OnChannelStateChanged              += ((object sender, OnChannelStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChannelStateChanged?.Invoke(sender, e)); });
            base.OnUserStateChanged                 += ((object sender, OnUserStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserStateChanged?.Invoke(sender, e)); });
            base.OnMessageReceived                  += ((object sender, OnMessageReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnMessageReceived?.Invoke(sender, e)); });
            base.OnWhisperReceived                  += ((object sender, OnWhisperReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnWhisperReceived?.Invoke(sender, e)); });
            base.OnMessageSent                      += ((object sender, OnMessageSentArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnMessageSent?.Invoke(sender, e)); });
            base.OnWhisperSent                      += ((object sender, OnWhisperSentArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnWhisperSent?.Invoke(sender, e)); });
            base.OnChatCommandReceived              += ((object sender, OnChatCommandReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChatCommandReceived?.Invoke(sender, e)); });
            base.OnWhisperCommandReceived           += ((object sender, OnWhisperCommandReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnWhisperCommandReceived?.Invoke(sender, e)); });
            base.OnUserJoined                       += ((object sender, OnUserJoinedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserJoined?.Invoke(sender, e)); });
            base.OnModeratorJoined                  += ((object sender, OnModeratorJoinedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnModeratorJoined?.Invoke(sender, e)); });
            base.OnModeratorLeft                    += ((object sender, OnModeratorLeftArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnModeratorLeft?.Invoke(sender, e)); });
            base.OnNewSubscriber                    += ((object sender, OnNewSubscriberArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNewSubscriber?.Invoke(sender, e)); });
            base.OnReSubscriber                     += ((object sender, OnReSubscriberArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnReSubscriber?.Invoke(sender, e)); });
            base.OnHostLeft                         += ((object sender, EventArgs arg) => { ThreadDispatcher.Instance().Enqueue(() => OnHostLeft(sender, arg)); });
            base.OnExistingUsersDetected            += ((object sender, OnExistingUsersDetectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnExistingUsersDetected?.Invoke(sender, e)); });
            base.OnUserLeft                         += ((object sender, OnUserLeftArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserLeft?.Invoke(sender, e)); });
            base.OnHostingStarted                   += ((object sender, OnHostingStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnHostingStarted?.Invoke(sender, e)); });
            base.OnHostingStopped                   += ((object sender, OnHostingStoppedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnHostingStopped?.Invoke(sender, e)); });
            base.OnDisconnected                     += ((object sender, OnDisconnectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnDisconnected?.Invoke(sender, e)); });
            base.OnConnectionError                  += ((object sender, OnConnectionErrorArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnectionError?.Invoke(sender, e)); });
            base.OnChatCleared                      += ((object sender, OnChatClearedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChatCleared?.Invoke(sender, e)); });
            base.OnUserTimedout                     += ((object sender, OnUserTimedoutArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserTimedout?.Invoke(sender, e)); });
            base.OnLeftChannel                      += ((object sender, OnLeftChannelArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLeftChannel?.Invoke(sender, e)); });
            base.OnUserBanned                       += ((object sender, OnUserBannedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserBanned?.Invoke(sender, e)); });
            base.OnModeratorsReceived               += ((object sender, OnModeratorsReceivedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnModeratorsReceived?.Invoke(sender, e)); });
            base.OnChatColorChanged                 += ((object sender, OnChatColorChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChatColorChanged?.Invoke(sender, e)); });
            base.OnSendReceiveData                  += ((object sender, OnSendReceiveDataArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnSendReceiveData?.Invoke(sender, e)); });
            base.OnNowHosting                       += ((object sender, OnNowHostingArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNowHosting?.Invoke(sender, e)); });
            base.OnBeingHosted                      += ((object sender, OnBeingHostedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnBeingHosted?.Invoke(sender, e)); });
            base.OnRaidNotification                 += ((object sender, OnRaidNotificationArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnRaidNotification?.Invoke(sender, e)); });
            base.OnGiftedSubscription               += ((object sender, OnGiftedSubscriptionArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnGiftedSubscription?.Invoke(sender, e)); });
            base.OnRaidedChannelIsMatureAudience    += ((object sender, EventArgs arg) => { ThreadDispatcher.Instance().Enqueue(() => OnRaidedChannelIsMatureAudience(sender, arg)); });
            base.OnRitualNewChatter                 += ((object sender, OnRitualNewChatterArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnRitualNewChatter?.Invoke(sender, e)); });
            base.OnFailureToReceiveJoinConfirmation += ((object sender, OnFailureToReceiveJoinConfirmationArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnFailureToReceiveJoinConfirmation?.Invoke(sender, e)); });
            base.OnUnaccountedFor                   += ((object sender, OnUnaccountedForArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUnaccountedFor?.Invoke(sender, e)); });
        }
        public UnityFollowerService(ITwitchAPI api, int checkIntervalSeconds = 60, int queryCount = 25) : base(api, checkIntervalSeconds, queryCount)
        {
            _threadDispatcher = new GameObject("ThreadDispatcher");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnServiceStarted       += ((object sender, OnServiceStartedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStarted?.Invoke(sender, e)); });
            base.OnServiceStopped       += ((object sender, OnServiceStoppedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnServiceStopped?.Invoke(sender, e)); });
            base.OnNewFollowersDetected += ((object sender, OnNewFollowersDetectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNewFollowersDetected?.Invoke(sender, e)); });
        }