示例#1
0
        public static async Task <UserModel> GetCurrentUser(MixerClient client)
        {
            ChannelModel channel = await ChannelsServiceUnitTests.GetChannel(client);

            PrivatePopulatedUserModel user = await client.Users.GetCurrentUser();

            Assert.IsNotNull(user);
            Assert.IsTrue(user.id > (uint)0);

            return(user);
        }
示例#2
0
        public static async Task <ChannelChatModel> GetChat(MixerClient client)
        {
            ChannelModel channel = await ChannelsServiceUnitTests.GetChannel(client);

            ChannelChatModel chat = await client.Chats.GetChat(channel);

            Assert.IsNotNull(chat);
            Assert.IsTrue(chat.endpoints.Count() > 0);

            return(chat);
        }
示例#3
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();
            }
        }
示例#4
0
 protected void TestWrapper(Func <MixerClient, Task> function)
 {
     try
     {
         MixerClient client = AuthorizationUnitTests.GetMixerClient();
         function(client).Wait();
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.ToString());
     }
 }
示例#5
0
        private static void Main(string[] args)
        {
            PrintLine(Cyan, "MixerLib ChatMonitor example\n");

            IAuthorization auth = (TOKEN != null) ? new Auth.ImplicitGrant(TOKEN) : null;

            try
            {
                Print(Gray, $"Connecting to mixer.com/{CHANNEL_NAME}...");
                using (var mixer = MixerClient.StartAsync(CHANNEL_NAME, auth).Result)
                {
                    Print(Green, "OK\n");

                    Print(Gray, $"You are connected as ");
                    if (mixer.IsAuthenticated)
                    {
                        PrintLine(Green, mixer.UserName + "\n");
                    }
                    else
                    {
                        PrintLine(Red, "anonymous\n");
                    }

                    var(title, gameTypeId) = mixer.RestClient.GetChannelInfoAsync().Result;
                    PrintLine(DarkGray, $"Title: '{title}'");
                    var game = mixer.RestClient.LookupGameTypeByIdAsync(gameTypeId.GetValueOrDefault()).Result;
                    PrintLine(DarkGray, $"Game:  '{game?.Name}'");

                    var uptime = mixer.GetUptime();
                    if (uptime.HasValue)
                    {
                        PrintLine(DarkGray, $"Channel has been live for {uptime} with {mixer.CurrentViewers} viewers currently.");
                    }
                    else
                    {
                        PrintLine(DarkGray, "Channel is OFFLINE.");
                    }

                    mixer.ChatMessage   += Mixer_ChatMessage;
                    mixer.ChannelUpdate += Mixer_StatusUpdate;

                    PrintLine(Gray, "\nPress ENTER to exit\n\n");
                    Console.ReadLine();

                    mixer.ChatMessage   -= Mixer_ChatMessage;
                    mixer.ChannelUpdate -= Mixer_StatusUpdate;
                }
            }
            catch (Exception ex)
            {
                Print(Red, $"\nERROR: {ex.Message}");
            }
        }
        public static async Task <ChannelModel> GetChannel(MixerClient client)
        {
            string channelName = ConfigurationManager.AppSettings["ChannelName"];

            if (string.IsNullOrEmpty(channelName))
            {
                Assert.Fail("ChannelName value isn't set in application configuration");
            }

            ChannelModel channel = await client.Channels.GetChannel(channelName);

            Assert.IsNotNull(channel);
            Assert.IsTrue(channel.id > (uint)0);

            return(channel);
        }
示例#7
0
        public static MixerClient GetMixerClient()
        {
            if (AuthorizationUnitTests.client == null)
            {
                string clientID = ConfigurationManager.AppSettings["ClientID"];
                if (string.IsNullOrEmpty(clientID))
                {
                    Assert.Fail("ClientID value isn't set in application configuration");
                }

                AuthorizationUnitTests.client = MixerClient.ConnectViaShortCode(clientID, new List <ClientScopeEnum>()
                {
                    ClientScopeEnum.channel__details__self,
                    ClientScopeEnum.channel__update__self,

                    //ClientScopeEnum.chat__bypass_links,
                    //ClientScopeEnum.chat__bypass_slowchat,
                    //ClientScopeEnum.chat__change_ban,
                    //ClientScopeEnum.chat__change_role,
                    ClientScopeEnum.chat__chat,
                    //ClientScopeEnum.chat__clear_messages,
                    ClientScopeEnum.chat__connect,
                    //ClientScopeEnum.chat__edit_options,
                    //ClientScopeEnum.chat__giveaway_start,
                    //ClientScopeEnum.chat__poll_start,
                    //ClientScopeEnum.chat__poll_vote,
                    //ClientScopeEnum.chat__purge,
                    //ClientScopeEnum.chat__remove_message,
                    //ClientScopeEnum.chat__timeout,
                    //ClientScopeEnum.chat__view_deleted,
                    ClientScopeEnum.chat__whisper,

                    ClientScopeEnum.user__details__self,
                    ClientScopeEnum.user__log__self,
                    ClientScopeEnum.user__notification__self,
                    ClientScopeEnum.user__update__self,
                },
                                                                                (string code) =>
                {
                    Assert.IsNotNull(code);
                    Process.Start("https://mixer.com/oauth/shortcode?code=" + code);
                }).Result;
            }

            Assert.IsNotNull(AuthorizationUnitTests.client);
            return(AuthorizationUnitTests.client);
        }
示例#8
0
文件: Program.cs 项目: jbdk/MixerLib
        //
        // This will show all the packets coming in on the web-socket's on the console, by installing a ConsoleLogger
        //
        private static void Main(string[] args)
        {
            const string CHANNEL_NAME = "xbox";
            const string TOKEN        = null;

            var logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();
            var loggerFactory = new SerilogLoggerFactory(logger);

            IAuthorization auth = (TOKEN != null) ? new Auth.ImplicitGrant(TOKEN) : null;

            try
            {
                Console.WriteLine($"Connecting to mixer.com/{CHANNEL_NAME}...");
                using (var mixer = MixerClient.StartAsync(CHANNEL_NAME, auth, loggerFactory).Result)
                {
                    Console.WriteLine("OK\n");

                    Console.WriteLine($"You are connected as ");
                    if (mixer.IsAuthenticated)
                    {
                        Console.WriteLine(mixer.UserName + "\n");
                    }
                    else
                    {
                        Console.WriteLine("anonymous\n");
                    }

                    Console.WriteLine("\nPress ENTER to exit\n\n");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\nERROR: {ex.Message}");
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            var settingsJson = File.Exists(SETTINGS_FILENAME) ? File.ReadAllText(SETTINGS_FILENAME) : "{}";

            settings = JsonConvert.DeserializeObject <Settings>(settingsJson);
            SaveSettings();

            clipDirectory = settings.ClipDirectory + "/" + DateTime.UtcNow.ToFileTimeUtc();
            Directory.CreateDirectory(clipDirectory);

            stopwatch  = new Stopwatch();
            mixer      = new MixerClient();
            downloader = new HttpClient();

            foreach (var keypair in settings.Channels)
            {
                Console.WriteLine("Processing " + keypair.Key);
                stopwatch.Reset();
                ProcessChannel(keypair.Value).Wait();
                Console.WriteLine("Took {0} minutes", stopwatch.ElapsedMilliseconds / 1000 / 60);
            }
        }
示例#10
0
 public ChannelsService(MixerClient client) : base(client)
 {
 }
示例#11
0
 public ServiceBase(MixerClient client)
 {
     Validator.ValidateVariable(client, "client");
     this.client = client;
 }
示例#12
0
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            this.LoginButton.IsEnabled = false;

            string clientID = ConfigurationManager.AppSettings["ClientID"];

            if (string.IsNullOrEmpty(clientID))
            {
                throw new ArgumentException("ClientID value isn't set in application configuration");
            }

            this.client = await MixerClient.ConnectViaShortCode(clientID,
                                                                new List <ClientScopeEnum>()
            {
                ClientScopeEnum.chat__chat,
                ClientScopeEnum.chat__connect,
                ClientScopeEnum.channel__details__self,
                ClientScopeEnum.channel__update__self,
                ClientScopeEnum.user__details__self,
                ClientScopeEnum.user__log__self,
                ClientScopeEnum.user__notification__self,
                ClientScopeEnum.user__update__self,
            },
                                                                (string code) =>
            {
                this.ShortCodeTextBox.Text = code;
                Process.Start("https://mixer.com/oauth/shortcode");
            });

            if (this.client != null)
            {
                this.user = await this.client.Users.GetCurrentUser();

                this.channel = await this.client.Channels.GetChannel(this.user.username);

                this.chatClient = await ChatClient.CreateFromChannel(this.client, this.user.channel);

                this.chatClient.MessageOccurred       += ChatClient_MessageOccurred;
                this.chatClient.UserJoinOccurred      += ChatClient_UserJoinOccurred;
                this.chatClient.UserLeaveOccurred     += ChatClient_UserLeaveOccurred;
                this.chatClient.UserTimeoutOccurred   += ChatClient_UserTimeoutOccurred;
                this.chatClient.UserUpdateOccurred    += ChatClient_UserUpdateOccurred;
                this.chatClient.PollStartOccurred     += ChatClient_PollStartOccurred;
                this.chatClient.PollEndOccurred       += ChatClient_PollEndOccurred;
                this.chatClient.PurgeMessageOccurred  += ChatClient_PurgeMessageOccurred;
                this.chatClient.DeleteMessageOccurred += ChatClient_DeleteMessageOccurred;
                this.chatClient.ClearMessagesOccurred += ChatClient_ClearMessagesOccurred;

                if (await this.chatClient.Connect() && await this.chatClient.Authenticate())
                {
                    this.ChannelUserTextBlock.Text = this.user.username;
                    this.StreamTitleTextBox.Text   = this.channel.name;
                    this.GameTitleTextBlock.Text   = this.channel.type.name;

                    foreach (ChatUserModel user in await this.client.Chats.GetUsers(this.chatClient.Channel))
                    {
                        this.chatUsers.Add(new ChatUser(user));
                    }

                    this.LoginGrid.Visibility = Visibility.Collapsed;

                    this.MainGrid.Visibility = Visibility.Visible;
                }
            }

            this.LoginButton.IsEnabled = true;
        }
示例#13
0
 public UsersService(MixerClient client) : base(client)
 {
 }