Esempio n. 1
0
        public async Task <IEnumerable <InteractiveParticipantModel> > GetRecentParticipants()
        {
            Dictionary <uint, InteractiveParticipantModel> participants = new Dictionary <uint, InteractiveParticipantModel>();

            DateTimeOffset startTime = DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(10));
            InteractiveParticipantCollectionModel collection = null;

            await this.RunAsync(async() =>
            {
                do
                {
                    if (this.Client == null)
                    {
                        break;
                    }

                    collection = await this.Client.GetAllParticipants(startTime);
                    if (collection != null && collection.participants != null)
                    {
                        foreach (InteractiveParticipantModel participant in collection.participants)
                        {
                            participants[participant.userID] = participant;
                        }

                        if (collection.participants.Count() > 0)
                        {
                            startTime = DateTimeHelper.UnixTimestampToDateTimeOffset(collection.participants.Last().connectedAt);
                        }
                    }
                } while (collection != null && collection.participants.Count > 0 && collection.hasMore);
            });

            return(participants.Values);
        }
Esempio n. 2
0
 private async void Client_OnParticipantJoin(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e != null)
     {
         await this.AddParticipants(e.participants);
     }
     this.OnParticipantJoin(this, e);
 }
Esempio n. 3
0
 private void Client_OnParticipantUpdate(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e.participants != null)
     {
         //await this.AddParticipants(e.participants);
     }
     this.OnParticipantUpdate(this, e);
 }
Esempio n. 4
0
 private static void InteractiveClient_OnParticipantLeave(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e.participants != null)
     {
         foreach (InteractiveParticipantModel participant in e.participants)
         {
             System.Console.WriteLine("Participant Left: " + participant.username);
         }
     }
 }
 private void InteractiveClient_OnParticipantUpdate(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e.participants != null)
     {
         foreach (InteractiveParticipantModel participant in e.participants)
         {
             this.InteractiveDataTextBlock.Text += "Participant Updated: " + participant.username + Environment.NewLine;
         }
     }
 }
 private void Client_OnParticipantLeave(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e != null)
     {
         foreach (InteractiveParticipantModel participant in e.participants)
         {
             this.InteractiveUsers.Remove(participant.sessionID);
         }
     }
     this.OnParticipantLeave(this, e);
 }
Esempio n. 7
0
 private async void Client_OnParticipantLeave(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e != null)
     {
         foreach (InteractiveParticipantModel participant in e.participants)
         {
             await ChannelSession.ActiveUsers.RemoveInteractiveUser(participant);
         }
     }
     this.OnParticipantLeave(this, e);
 }
        public void GetAllParticipants()
        {
            this.InteractiveWrapper(async(MixerConnection connection, InteractiveClient interactiveClient) =>
            {
                this.ClearPackets();

                InteractiveParticipantCollectionModel participants = await interactiveClient.GetAllParticipants();

                Assert.IsNotNull(participants);
                Assert.IsNotNull(participants.participants);
            });
        }
Esempio n. 9
0
        private static void InteractiveClient_OnParticipantJoin(object sender, InteractiveParticipantCollectionModel e)
        {
            if (e.participants != null)
            {
                foreach (InteractiveParticipantModel participant in e.participants)
                {
                    Users.Add(participant.sessionID, participant);

                    System.Console.WriteLine("Participant Joined: " + participant.username);
                }
            }
        }
Esempio n. 10
0
 private void Client_OnParticipantUpdate(object sender, InteractiveParticipantCollectionModel e)
 {
     if (e.participants != null)
     {
         foreach (InteractiveParticipantModel participant in e.participants)
         {
             if (!string.IsNullOrEmpty(participant.sessionID))
             {
                 this.Participants[participant.sessionID] = participant;
             }
         }
     }
     this.OnParticipantUpdate(this, e);
 }
Esempio n. 11
0
 private static void InteractiveClient_OnParticipantLeave(object sender, InteractiveParticipantCollectionModel e)
 {
     try
     {
         if (e.participants != null)
         {
             foreach (InteractiveParticipantModel participant in e.participants)
             {
                 Program.participants.Remove(participant.sessionID);
                 System.Console.WriteLine("Participant Left: " + participant.username);
             }
         }
     }
     catch (Exception ex) { System.Console.WriteLine(ex.ToString()); }
 }
        private void InteractiveClient_OnParticipantLeave(object sender, InteractiveParticipantCollectionModel e)
        {
            if (e.participants != null)
            {
                foreach (InteractiveParticipantModel participant in e.participants)
                {
                    this.InteractiveDataTextBlock.Text += "Participant Left: " + participant.username + Environment.NewLine;

                    var existingUser = users.FirstOrDefault(u => u.Name.Equals(participant.username));
                    if (existingUser != null)
                    {
                        this.users.Remove(existingUser);
                    }
                }
            }
        }
        private void InteractiveClient_OnParticipantJoin(object sender, InteractiveParticipantCollectionModel e)
        {
            if (e.participants != null)
            {
                foreach (InteractiveParticipantModel participant in e.participants)
                {
                    this.InteractiveDataTextBlock.Text += $"Participant Joined: {participant.username}, sessionID: {participant.sessionID}" + Environment.NewLine;

                    var newUser = new User(participant.username, participant.sessionID);
                    if (this.users.Contains(newUser))
                    {
                        this.users.First(u => u.Equals(newUser)).Sessions.Add(participant.sessionID);
                    }
                    else
                    {
                        this.users.Add(newUser);
                    }
                }
            }
        }
        private async Task <bool> Initialize()
        {
            this.SceneGroups.Clear();
            this.Controls.Clear();
            this.InteractiveUsers.Clear();

            // Initialize Scenes
            InteractiveConnectedSceneGroupCollectionModel scenes = await ChannelSession.Interactive.GetScenes();

            if (scenes == null)
            {
                return(false);
            }

            this.SceneGroups = scenes.scenes;
            foreach (InteractiveConnectedSceneModel scene in this.SceneGroups)
            {
                foreach (InteractiveConnectedButtonControlModel button in scene.buttons)
                {
                    this.AddConnectedControl(scene, button);
                }

                foreach (InteractiveConnectedJoystickControlModel joystick in scene.joysticks)
                {
                    this.AddConnectedControl(scene, joystick);
                }
            }

            // Initialize Groups
            List <InteractiveGroupModel> groupsToAdd = new List <InteractiveGroupModel>();

            foreach (InteractiveUserGroupViewModel userGroup in ChannelSession.Settings.InteractiveUserGroups[this.Client.InteractiveGame.id])
            {
                if (userGroup.IsEnabled)
                {
                    groupsToAdd.Add(new InteractiveGroupModel()
                    {
                        groupID = userGroup.GroupName, sceneID = userGroup.DefaultScene
                    });
                }
            }

            if (!await this.CreateGroups(groupsToAdd))
            {
                return(false);
            }

            // Initialize Participants
            List <InteractiveParticipantModel> participantsToAdd    = new List <InteractiveParticipantModel>();
            List <InteractiveParticipantModel> participantsToLookUp = new List <InteractiveParticipantModel>();

            InteractiveParticipantCollectionModel participants = await this.GetAllParticipants();

            if (participants != null)
            {
                foreach (InteractiveParticipantModel participant in participants.participants)
                {
                    if (ChannelSession.Chat.ChatUsers.ContainsKey(participant.userID))
                    {
                        participantsToAdd.Add(participant);
                    }
                    else
                    {
                        participantsToLookUp.Add(participant);
                    }
                }
            }

            await this.AddParticipants(participantsToAdd);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(async() =>
            {
                foreach (InteractiveParticipantModel participant in participantsToLookUp)
                {
                    await ChannelSession.Chat.GetAndAddUser(participant.userID);
                }
                this.AddParticipants(participantsToLookUp);
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            return(true);
        }
Esempio n. 15
0
        public static void Main(string[] args)
        {
            Task.Run(async() =>
            {
                List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>()
                {
                    OAuthClientScopeEnum.channel__details__self,
                    OAuthClientScopeEnum.channel__update__self,

                    OAuthClientScopeEnum.interactive__manage__self,
                    OAuthClientScopeEnum.interactive__robot__self,

                    OAuthClientScopeEnum.user__details__self,
                    OAuthClientScopeEnum.user__log__self,
                    OAuthClientScopeEnum.user__notification__self,
                    OAuthClientScopeEnum.user__update__self,
                };

                MixerConnection connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser("ba911f5e09c2d3a87b715e0371f1e9ba96d476b5a7b26ba0", scopes);

                if (connection != null)
                {
                    System.Console.WriteLine("Mixer connection successful!");

                    UserModel user = await connection.Users.GetCurrentUser();
                    ExpandedChannelModel channel = await connection.Channels.GetChannel(user.username);
                    System.Console.WriteLine(string.Format("Logged in as: {0}", user.username));

                    InteractiveGameVersionModel version = await connection.Interactive.GetInteractiveGameVersion(Program.GameVersionID);
                    if (version != null)
                    {
                        InteractiveGameModel game = await connection.Interactive.GetInteractiveGame(version.gameId);
                        if (game != null)
                        {
                            System.Console.WriteLine();
                            System.Console.WriteLine(string.Format("Connecting to channel interactive using game {0}...", game.name));

                            Program.interactiveClient = await InteractiveClient.CreateFromChannel(connection, channel, game, version, Program.GameShareCode);

                            Program.interactiveClient.OnDisconnectOccurred += InteractiveClient_OnDisconnectOccurred;
                            Program.interactiveClient.OnParticipantJoin    += InteractiveClient_OnParticipantJoin;
                            Program.interactiveClient.OnParticipantLeave   += InteractiveClient_OnParticipantLeave;
                            Program.interactiveClient.OnGiveInput          += InteractiveClient_OnGiveInput;

                            if (await Program.interactiveClient.Connect() && await Program.interactiveClient.Ready())
                            {
                                InteractiveConnectedSceneGroupCollectionModel scenes = await Program.interactiveClient.GetScenes();
                                if (scenes != null)
                                {
                                    InteractiveConnectedSceneModel scene = scenes.scenes.First();

                                    InteractiveConnectedButtonControlModel gameStartButton = scene.buttons.First(b => b.controlID.Equals("gameStart"));
                                    InteractiveConnectedButtonControlModel timeLeftButton  = scene.buttons.First(b => b.controlID.Equals("timeLeft"));
                                    InteractiveConnectedButtonControlModel flyHitButton    = scene.buttons.First(b => b.controlID.Equals("flyHit"));
                                    InteractiveConnectedButtonControlModel gameEndButton   = scene.buttons.First(b => b.controlID.Equals("gameEnd"));
                                    InteractiveConnectedButtonControlModel resultsButton   = scene.buttons.First(b => b.controlID.Equals("results"));

                                    InteractiveParticipantCollectionModel participantCollection = await Program.interactiveClient.GetAllParticipants(DateTimeOffset.Now.Subtract(TimeSpan.FromMinutes(5)));
                                    if (participantCollection != null && participantCollection.participants != null)
                                    {
                                        foreach (InteractiveParticipantModel participant in participantCollection.participants)
                                        {
                                            Program.participants[participant.sessionID] = participant;
                                        }
                                    }

                                    while (true)
                                    {
                                        try
                                        {
                                            System.Console.WriteLine("Starting new game...");

                                            userTotals.Clear();

                                            gameStartButton.meta["timeLeft"] = 30;
                                            await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>()
                                            {
                                                gameStartButton
                                            });

                                            for (int i = 30; i >= 0; i--)
                                            {
                                                timeLeftButton.meta["timeLeft"] = i;
                                                await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>()
                                                {
                                                    timeLeftButton
                                                });

                                                await Task.Delay(1000);
                                            }

                                            await Task.Delay(2000);

                                            System.Console.WriteLine("Game completed, selecting winner...");

                                            InteractiveParticipantModel winner = null;
                                            foreach (var kvp in userTotals.OrderByDescending(kvp => kvp.Value))
                                            {
                                                if (Program.participants.TryGetValue(kvp.Key, out winner))
                                                {
                                                    resultsButton.meta["winner"] = JObject.FromObject(winner);
                                                    await Program.interactiveClient.UpdateControls(scene, new List <InteractiveControlModel>()
                                                    {
                                                        resultsButton
                                                    });
                                                    break;
                                                }
                                            }

                                            if (winner != null)
                                            {
                                                System.Console.WriteLine("Winner: " + winner.username);
                                            }

                                            await Task.Delay(5000);
                                        }
                                        catch (Exception ex) { System.Console.WriteLine(ex.ToString()); }
                                    }
                                }
                            }
                        }
                    }
                }
            }).Wait();
        }