protected override async Task <bool> ConnectInternal()
        {
            this.Client = await this.RunAsync(ConstellationClient.Create(ChannelSession.Connection.Connection));

            return(await this.RunAsync(async() =>
            {
                if (this.Client != null)
                {
                    this.backgroundThreadCancellationTokenSource = new CancellationTokenSource();

                    if (await this.RunAsync(this.Client.Connect()))
                    {
                        this.Client.OnDisconnectOccurred += ConstellationClient_OnDisconnectOccurred;
                        if (ChannelSession.Settings.DiagnosticLogging)
                        {
                            this.Client.OnPacketSentOccurred += WebSocketClient_OnPacketSentOccurred;
                            this.Client.OnMethodOccurred += WebSocketClient_OnMethodOccurred;
                            this.Client.OnReplyOccurred += WebSocketClient_OnReplyOccurred;
                            this.Client.OnEventOccurred += WebSocketClient_OnEventOccurred;
                        }
                        this.Client.OnSubscribedEventOccurred += ConstellationClient_OnSubscribedEventOccurred;

                        await this.SubscribeToEvents(ConstellationClientWrapper.subscribedEvents.Select(e => new ConstellationEventType(e, ChannelSession.Channel.id)));

                        return true;
                    }
                }
                return false;
            }));
        }
Example #2
0
        private static async void TrackFollows(MixerConnection connection, ExpandedChannelModel channel, ChatClient chat)
        {
            var constalation = await ConstellationClient.Create(connection);

            WriteLine("made constellation");

            var connected = await constalation.Connect();

            if (!connected)
            {
                WriteLine("constalation failed");
                return;
            }


            WriteLine("connected to constellation");

            await constalation.SubscribeToEventsWithResponse(new ConstellationEventType[]
            {
                new ConstellationEventType(ConstellationEventTypeEnum.channel__id__followed, channel.id)
            });

            void Constalation_OnSubscribedEventOccurred(object sender, Base.Model.Constellation.ConstellationLiveEventModel e)
            {
                var following = e.payload.Value <bool>("following");
                var user      = e.payload.Value <JObject>("user");
                var username  = user.Value <string>("username");
                var mood      = following ? "follow" : "unfollow";

                chat.Send($"/{mood} {username}");
                Log($"{username}\t{mood}");
            }

            constalation.OnSubscribedEventOccurred += Constalation_OnSubscribedEventOccurred;
        }
Example #3
0
        public static void ClassInitialize(TestContext context)
        {
            TestWrapper(async(MixerConnection connection) =>
            {
                constellationClient = await ConstellationClient.Create(connection);

                Assert.IsTrue(await constellationClient.Connect());
            });
        }
Example #4
0
        public async Task Disconnect()
        {
            if (this.Client != null)
            {
                this.Client.OnDisconnectOccurred -= ConstellationClient_OnDisconnectOccurred;
                if (ChannelSession.Settings.DiagnosticLogging)
                {
                    this.Client.OnPacketSentOccurred -= WebSocketClient_OnPacketSentOccurred;
                    this.Client.OnMethodOccurred     -= WebSocketClient_OnMethodOccurred;
                    this.Client.OnReplyOccurred      -= WebSocketClient_OnReplyOccurred;
                    this.Client.OnEventOccurred      -= WebSocketClient_OnEventOccurred;
                }
                this.Client.OnSubscribedEventOccurred -= ConstellationClient_OnSubscribedEventOccurred;

                await this.RunAsync(this.Client.Disconnect());

                this.backgroundThreadCancellationTokenSource.Cancel();
            }
            this.Client = null;
        }
Example #5
0
        public async Task <bool> Connect()
        {
            this.Client = await this.RunAsync(ConstellationClient.Create(ChannelSession.Connection.Connection));

            if (this.Client != null)
            {
                if (await this.RunAsync(this.Client.Connect()))
                {
                    this.Client.OnDisconnectOccurred += ConstellationClient_OnDisconnectOccurred;
                    if (ChannelSession.Settings.DiagnosticLogging)
                    {
                        this.Client.OnMethodOccurred += WebSocketClient_OnMethodOccurred;
                        this.Client.OnReplyOccurred  += WebSocketClient_OnReplyOccurred;
                        this.Client.OnEventOccurred  += WebSocketClient_OnEventOccurred;
                    }
                    this.Client.OnSubscribedEventOccurred += ConstellationClient_OnSubscribedEventOccurred;

                    await this.SubscribeToEvents(ConstellationClientWrapper.subscribedEvents.Select(e => new ConstellationEventType(e, ChannelSession.Channel.id)));

                    return(true);
                }
            }
            return(false);
        }
Example #6
0
        public static void Main(string[] args)
        {
            List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>()
            {
                OAuthClientScopeEnum.chat__bypass_links,
                OAuthClientScopeEnum.chat__bypass_slowchat,
                OAuthClientScopeEnum.chat__change_ban,
                OAuthClientScopeEnum.chat__change_role,
                OAuthClientScopeEnum.chat__chat,
                OAuthClientScopeEnum.chat__connect,
                OAuthClientScopeEnum.chat__clear_messages,
                OAuthClientScopeEnum.chat__edit_options,
                OAuthClientScopeEnum.chat__giveaway_start,
                OAuthClientScopeEnum.chat__poll_start,
                OAuthClientScopeEnum.chat__poll_vote,
                OAuthClientScopeEnum.chat__purge,
                OAuthClientScopeEnum.chat__remove_message,
                OAuthClientScopeEnum.chat__timeout,
                OAuthClientScopeEnum.chat__view_deleted,
                OAuthClientScopeEnum.chat__whisper,

                OAuthClientScopeEnum.channel__details__self,
                OAuthClientScopeEnum.channel__update__self,

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

            System.Console.WriteLine("Connecting to Mixer...");

            MixerConnection connection = MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], scopes).Result;

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

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

                System.Console.WriteLine();
                System.Console.WriteLine("Connecting to constellation...");

                constellationClient = ConstellationClient.Create(connection).Result;

                constellationClient.OnDisconnectOccurred      += ConstellationClient_OnDisconnectOccurred;
                constellationClient.OnSubscribedEventOccurred += ConstellationClient_OnSubscribedEventOccurred;

                if (constellationClient.Connect().Result)
                {
                    System.Console.WriteLine("Constellation connection successful!");

                    List <ConstellationEventTypeEnum> eventsToSubscribeTo = new List <ConstellationEventTypeEnum>()
                    {
                        ConstellationEventTypeEnum.channel__id__followed, ConstellationEventTypeEnum.channel__id__hosted, ConstellationEventTypeEnum.channel__id__subscribed,
                        ConstellationEventTypeEnum.channel__id__resubscribed, ConstellationEventTypeEnum.channel__id__resubShared, ConstellationEventTypeEnum.channel__id__subscriptionGifted,
                        ConstellationEventTypeEnum.channel__id__update, ConstellationEventTypeEnum.channel__id__skill, ConstellationEventTypeEnum.channel__id__patronageUpdate,
                        ConstellationEventTypeEnum.progression__id__levelup,
                    };

                    List <ConstellationEventType> events = eventsToSubscribeTo.Select(e => new ConstellationEventType(e, channel.id)).ToList();

                    constellationClient.SubscribeToEvents(events).Wait();

                    System.Console.WriteLine("Subscribed to events successful!");
                    System.Console.WriteLine();

                    while (true)
                    {
                    }
                }
            }
        }