Exemplo n.º 1
0
        private async Task ConnectPropertiesAsync()
        {
            bool isDeveloperAPIEnabled = true;

            try
            {
                MixPlayStatus _ = await MixPlay.GetStatusAsync();
            }
            catch
            {
                isDeveloperAPIEnabled = false;
            }

            if (isDeveloperAPIEnabled)
            {
                // Blank object to clear the loading
                JObject response = new JObject();
                await this.connection.SendToPropertyInspectorAsync(this.Action, response, this.Context);
            }
            else
            {
                // Developer API is not enabled
                JObject response = new JObject
                {
                    ["error"] = JValue.CreateString("developerAPINotEnabled")
                };
                await this.connection.SendToPropertyInspectorAsync(this.Action, response, this.Context);
            }
        }
Exemplo n.º 2
0
        public override async Task RunTickAsync()
        {
            try
            {
                MixPlayStatus status = await MixPlay.GetStatusAsync();

                if (status.IsConnected)
                {
                    await this.connection.SetStateAsync(1, this.Context);

                    string title = status.GameName.Replace(' ', '\n');
                    await this.connection.SetTitleAsync(title, this.Context, SDKTarget.HardwareAndSoftware);
                }
                else
                {
                    await this.connection.SetStateAsync(0, this.Context);

                    await this.connection.SetTitleAsync("Not\nConnected", this.Context, SDKTarget.HardwareAndSoftware);
                }
            }
            catch
            {
                await this.connection.SetStateAsync(0, this.Context);

                await this.connection.SetTitleAsync("Not\nConnected", this.Context, SDKTarget.HardwareAndSoftware);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Start by creating a mix play object with the client creds.
            MixPlay mixplay = new MixPlay(ClientId, null);

            //
            // Handle Auth.
            try
            {
                // Try to read a cached auth token so we don't have to sign in if we already did.
                string authToken = ReadAuth();
                if (String.IsNullOrWhiteSpace(authToken))
                {
                    // Get a short code for auth.
                    MixPlayAuthShortCode shortCode = mixplay.GetAuthShortCode();

                    // Launch the browser to let the user login (a real program can do this however it wants)
                    Process.Start(new ProcessStartInfo("cmd", $"/c start {shortCode.ShortCodeAuthUrl}"));

                    // Wait for the user to login.
                    mixplay.WaitForShortCodeAuthComplete();

                    // Now that auth is complete, cache the auth token so the user doesn't have to sign in again.
                    //WriteAuth(mixplay.GetAuthTokenString());
                }
                else
                {
                    // Try to use the auth token
                    mixplay.SetAuthTokenString(authToken);
                }
            }
            catch (MixPlayException e)
            {
                if (e.HasMixerResultCode)
                {
                    Console.WriteLine("Auth failed due to MixPlay code " + e.MixerErrorCode);
                }
                else
                {
                    Console.WriteLine("Auth failed due to http error " + e.HttpErrorCode);
                }
                return;
            }

            //
            // Do other stuff.
            try
            {
                mixplay.OpenSession();

                mixplay.Connect(InteractiveId, ShareCode, true);
            }
            catch (MixPlayException e)
            {
                if (e.HasMixerResultCode)
                {
                    Console.WriteLine("Auth failed due to MixPlay code " + e.MixerErrorCode);
                }
                else
                {
                    Console.WriteLine("Auth failed due to http error " + e.HttpErrorCode);
                }
                return;
            }

            Thread.Sleep(50000);
        }