Пример #1
0
        internal static IEnumerator InitGlobalChatHandlers()
        {
            Twitch  = new ChatIntegration <ITwitchIntegration>();
            YouTube = new ChatIntegration <IYouTubeIntegration>();
            Mixer   = new ChatIntegration <IMixerIntegration>();
            Global  = new ChatIntegration <IGlobalChatIntegration>();

            bool initTwitch = false, initYouTube = false, initMixer = false;

            // Iterate through all the message handlers that were registered
            foreach (var instance in registeredInstances)
            {
                var instanceType = instance.Value.GetType();
                var typeName     = instanceType.Name;

                // Wait for all the registered handlers to be ready
                if (!instance.Value.IsPluginReady)
                {
                    Plugin.Log($"Instance of type {typeName} wasn't ready! Waiting until it is...");
                    yield return(new WaitUntil(() => instance.Value.IsPluginReady));

                    Plugin.Log($"Instance of type {typeName} is ready!");
                }

                bool isGlobalIntegration = typeof(IGlobalChatIntegration).IsAssignableFrom(instanceType);
                // Mark the correct services for initialization based on type
                if (typeof(ITwitchIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initTwitch = true;
                }
                if (typeof(IYouTubeIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initYouTube = true;
                }
                if (typeof(IMixerIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initMixer = true;
                }
            }

            // Initialize the appropriate streaming services
            if (initTwitch)
            {
                TwitchWebSocketClient.Initialize_Internal();
            }
            if (initYouTube)
            {
                YouTubeConnection.Initialize_Internal();
            }
            if (initMixer)
            {
                MixerClient.Initialize_Internal();
            }
        }
Пример #2
0
        internal static IEnumerator CreateGlobalMessageHandlers()
        {
            // Attempt to initialize message handlers for each of our chat services
            TwitchMessageHandler.Instance.InitializeMessageHandlers();
            YouTubeMessageHandler.Instance.InitializeMessageHandlers();
            GlobalMessageHandler.Instance.InitializeMessageHandlers();

            bool initTwitch = false, initYouTube = false;

            // Iterate through all the message handlers that were registered
            foreach (var instance in GlobalMessageHandler.registeredInstances)
            {
                var instanceType = instance.Value.GetType();
                var typeName     = instanceType.Name;

                // Wait for all the registered handlers to be ready
                if (!instance.Value.ChatCallbacksReady)
                {
                    Plugin.Log($"Instance of type {typeName} wasn't ready! Waiting until it is...");
                    yield return(new WaitUntil(() => instance.Value.ChatCallbacksReady));

                    Plugin.Log($"Instance of type {typeName} is ready!");
                }

                // Mark the correct services for initialization based on type
                if (typeof(ITwitchMessageHandler).IsAssignableFrom(instanceType))
                {
                    initTwitch = true;
                }
                if (typeof(IYouTubeMessageHandler).IsAssignableFrom(instanceType))
                {
                    initYouTube = true;
                }
                if (typeof(IGlobalMessageHandler).IsAssignableFrom(instanceType))
                {
                    initTwitch  = true;
                    initYouTube = true;
                }
            }

            // Initialize the appropriate streaming services
            if (initTwitch)
            {
                TwitchWebSocketClient.Initialize_Internal();
            }
            if (initYouTube)
            {
                YouTubeConnection.Initialize_Internal();
            }
        }