Exemplo n.º 1
0
 public SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestData req,
                                        [SignalRConnectionInfoInput(HubName = "Hub", UserId = "{query.userid}")] SignalRConnectionInfo signalRConnectionInfo)
 {
     _logger.LogInformation("Executing negotation.");
     return(signalRConnectionInfo);
 }
Exemplo n.º 2
0
 public void Func1([SignalRConnectionInfo(UserId = DefaultUserId, HubName = DefaultHubName, ConnectionStringSetting = Constants.AzureSignalRConnectionStringName)] SignalRConnectionInfo connectionInfo)
 {
     UpdateFunctionOutConnectionString(connectionInfo, Constants.AzureSignalRConnectionStringName);
 }
Exemplo n.º 3
0
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "chat")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 4
0
 public static SignalRConnectionInfo Negotiate([HttpTrigger] HttpRequest request, [SignalRConnectionInfo(HubName = "ServerlessChat")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 5
0
 public static SignalRConnectionInfo negotiate(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "imageAnalysis")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
 public SignalRConnectionInfo Negotiate(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req,
     [SignalRConnectionInfo(HubName = GlobalConstants.SignalR_HubName)] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 7
0
 public IActionResult Negotiate([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "negotiate")] HttpRequest req,
                                [SignalRConnectionInfo(HubName = "alert")] SignalRConnectionInfo info)
 {
     return(new OkObjectResult(info));
 }
Exemplo n.º 8
0
 public static SignalRConnectionInfo Negotiate(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest request,
     [SignalRConnectionInfo(HubName = "googazon", ConnectionStringSetting = "AzureSignalRConnectionString")] SignalRConnectionInfo connectionInfo)
 => connectionInfo;
Exemplo n.º 9
0
        private async void btnConnect_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                return;
            }

            try
            {
                me.UserName = txtUserName.Text?.Trim();
                me.UserId   = Guid.NewGuid().ToString();

                spinner.IsVisible = true;
                spinner.IsRunning = true;
                lblMessages.Text  = "Getting connection info...";

                SignalRConnectionInfo connectionInfo = await SignalRService.GetSignalRConnectionInfo();

                var url = connectionInfo.Url;
                lblMessages.Text = $"Connecting...";

                connection = new HubConnectionBuilder()
                             .WithUrl(url, options =>
                {
                    options.AccessTokenProvider = () => Task.FromResult(connectionInfo.AccessToken);
                })
                             .Build();

                //connection.Closed += async (error) =>
                //{
                //    //Optional code: only used for retrying to connect
                //    //await Task.Delay(new Random().Next(0, 5) * 1000);
                //    //await connection.StartAsync();
                //};

                //Waiting for other player
                connection.On <GamePlayer>("waiting", (player) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (player.UserId == me.UserId)
                        {
                            lblStatus.Text           = "Waiting for players...";
                            waitingSpinner.IsVisible = true;
                            waitingSpinner.IsRunning = true;

                            btnSetup.IsVisible       = false;
                            btnStopWaiting.IsEnabled = true;
                            btnStopWaiting.IsVisible = true;
                        }
                    });
                });

                //2 player game successfully created (method name MUST be 'newgame'
                connection.On <GameInfo>("newgame", (info) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        gameInfo          = info;
                        var currentPlayer = info.Players.Find(x => x.UserId == me.UserId);
                        multiplayerGameContent.IsVisible = true;
                        lblStatus.Text = $"Game setup successful, you are player {currentPlayer.PlayerNumber}";
                        if (currentPlayer.PlayerNumber == 1)
                        {
                            isPlayer1 = true;
                            btnStartTimer.IsEnabled = true;
                        }
                        else
                        {
                            isPlayer1 = false;
                            btnStartTimer.IsEnabled = false;
                        }

                        //Fill label with game content
                        lblGameContent.Text = $"Room Id: {info.RoomId}{Environment.NewLine}Player 1: {info.Players[0].UserName}{Environment.NewLine}Player 2: {info.Players[1].UserName}{Environment.NewLine}Toks:{Environment.NewLine}";

                        for (int i = 0; i < info.Toks.Count; ++i)
                        {
                            lblGameContent.Text += $"- {info.Toks[i].PrimaryFieldText}{Environment.NewLine}";
                        }

                        btnStopWaiting.IsEnabled = false;
                        btnStopWaiting.IsVisible = false;
                        waitingSpinner.IsVisible = false;
                        waitingSpinner.IsRunning = true;
                    });
                });

                #region Rounds and guesses

                connection.On <GameMessage>("log", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var newMessage    = $"{message.Player.UserName}: {message.Type}";
                            lblMessages.Text += Environment.NewLine + newMessage;
                        }
                    });
                });

                connection.On <GameMessage>("round_p1", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var num         = ++roundNumP1;
                            lblRoundP1.Text = (num).ToString();
                        }
                    });
                });
                connection.On <GameMessage>("guess_p1", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var num         = ++guessNumP1;
                            lblGuessP1.Text = (num).ToString();
                        }
                    });
                });
                connection.On <GameMessage>("round_p2", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var num         = ++roundNumP2;
                            lblRoundP2.Text = (num).ToString();
                        }
                    });
                });
                connection.On <GameMessage>("guess_p2", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var num         = ++guessNumP2;
                            lblGuessP2.Text = (num).ToString();
                        }
                    });
                });
                #endregion

                //2 player "Elapsed" function
                connection.On <GameMessage>("time", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var num       = (int)message.Content;
                            timeCount    += num;
                            lblTimer.Text = (timeCount).ToString();
                        }
                    });
                });

                //2 player "Start/Stop" function
                connection.On <GameMessage>("startstoptimer", (message) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        bool allowMessage = true;
                        if (onlyAllowRoomId == true && gameInfo.RoomId != message.RoomId && !string.IsNullOrEmpty(gameInfo.RoomId))
                        {
                            allowMessage = false;
                        }

                        if (allowMessage)
                        {
                            var timerIsRunning = Convert.ToBoolean(message.Content);

                            if (timerIsRunning)
                            {
                                if (isPlayer1)
                                {
                                    GameTimer.Stop();
                                }

                                TimerIsRunning     = false;
                                btnStartTimer.Text = "Start Timer";
                            }
                            else
                            {
                                if (isPlayer1)
                                {
                                    GameTimer.Start();
                                }

                                TimerIsRunning     = true;
                                btnStartTimer.Text = "Stop Timer";
                            }
                        }
                    });
                });

                await connection.StartAsync();

                lblMessages.Text = $"Connected.{Environment.NewLine}Id: {me.UserId}{Environment.NewLine}Name: {me.UserName}";
                //btnConnect.Text = connectionInfo.AccessToken;
                btnConnect.IsEnabled = false;

                gridRoundGuess.IsVisible = true;
                btnGuessP1.IsEnabled     = true;
                btnGuessP2.IsEnabled     = true;
                btnRoundP1.IsEnabled     = true;
                btnRoundP2.IsEnabled     = true;

                lblStatus.Text     = "Click below to start a game:";
                btnSetup.IsEnabled = true;

                spinner.IsVisible = false;
                spinner.IsEnabled = false;
            }
            catch (Exception ex)
            {
                lblMessages.Text = ex.Message;
            }
        }
Exemplo n.º 10
0
 public static IActionResult GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "messages")] SignalRConnectionInfo connectionInfo)
 {
     return((ActionResult) new OkObjectResult(connectionInfo));
 }
Exemplo n.º 11
0
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [SignalRConnectionInfo(HubName = "analyzis")] SignalRConnectionInfo connectionInfo) =>
 connectionInfo;
 public static SignalRConnectionInfo Run(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest request,
     [SignalRConnectionInfo(HubName = HubName, ConnectionStringSetting = SignalrConnectionAppSetting, UserId = "{headers.x-bright-user-id}")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 13
0
 public SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "negotiate")] HttpRequest req,
     [SignalRConnectionInfo(HubName = HubNames.GameHub, UserId = "{headers.x-ms-signalr-userid}")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 14
0
 public static SignalRConnectionInfo Negotiate(
     [HttpTrigger(AuthorizationLevel.Function)] HttpRequest req,
     [SignalRConnectionInfo(HubName = "general", UserId = "{headers.x-ms-signalr-userid}")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
 public static SignalRConnectionInfo Negotiate(
     [HttpTrigger(AuthorizationLevel.AuthLevelValue, "post")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "HubValue")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req,
     [SignalRConnectionInfo(HubName = "simplechat", UserId = "{query.userid}")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 17
0
 public SignalRConnectionInfo SignalRNegotiate(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "negotiate")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "cah")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 18
0
 public SignalRConnectionInfo GetSignalRInfo([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "twitch/negotiate")] HttpRequest req,
                                             [SignalRConnectionInfo(HubName = "channelPoints")] SignalRConnectionInfo connectionInfo, ILogger log)
 {
     log.LogInformation($"Client negotiate: {connectionInfo.Url}, {connectionInfo.AccessToken}");
     return(connectionInfo);
 }
Exemplo n.º 19
0
 public static SignalRConnectionInfo Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
                                         [SignalRConnectionInfo(HubName = "broadcast", UserId = "{headers.x-tezos-live-userid}")] SignalRConnectionInfo connectionInfo,
                                         Microsoft.Extensions.Logging.ILogger log)
 {
     return(connectionInfo);
 }
Exemplo n.º 20
0
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "signalr/{userId}/negotiate")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "ponies", UserId = "{userId}")] SignalRConnectionInfo connectionInfo)
 => connectionInfo;
Exemplo n.º 21
0
 public static SignalRConnectionInfo Run(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req,
     [SignalRConnectionInfo(HubName = "live")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 22
0
 public static SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [SignalRConnectionInfo(HubName = "status")] SignalRConnectionInfo connectionInfo)
 {
     // connectionInfo contains an access key token with a name identifier claim set to the authenticated user
     return(connectionInfo);
 }
Exemplo n.º 23
0
 public static SignalRConnectionInfo Negotiate(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req,
     [SignalRConnectionInfo(HubName = "Rover")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 24
0
 public static SignalRConnectionInfo NegotiateConnection(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage request,
     [SignalRConnectionInfo(HubName = ParkingStateHubName)] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 25
0
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "signalr/negotiate")] HttpRequest req,
     [SignalRConnectionInfo(HubName = "dttelemetry")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
 public static SignalRConnectionInfo Run(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", "options")] HttpRequest req,
     [SignalRConnectionInfo(HubName = LimitedTrialState.HUB_NAME, UserId = "{headers.x-ms-client-principal-id}")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 27
0
 public void Func2([SignalRConnectionInfo(UserId = DefaultUserId, HubName = DefaultHubName, ConnectionStringSetting = AttrConnStrConfigKey)] SignalRConnectionInfo connectionInfo)
 {
     UpdateFunctionOutConnectionString(connectionInfo, AttrConnStrConfigKey);
 }
 public static SignalRConnectionInfo GetSignalRInfo([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
                                                    [SignalRConnectionInfo(HubName = "hubName")] SignalRConnectionInfo connectionInfo) /// UserId = "{headers.xxx}" add for security reasons but use Ibinder
 {
     ////binder.Bind<SignalRConnectionInfo>(new SignalRConnectionInfoAttribute() { HubName = "hubName", UserId = "ProfileId jwt token" });
     return(connectionInfo);
 }
Exemplo n.º 29
0
 public static SignalRConnectionInfo GetSignalRInfo(
     [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestMessage req,
     [SignalRConnectionInfo(HubName = "General")] SignalRConnectionInfo connectionInfo)
 {
     return(connectionInfo);
 }
Exemplo n.º 30
0
 public IActionResult Run(
     [HttpTrigger(AuthorizationLevel.Function)] HttpRequest req,
     [SignalRConnectionInfo(HubName = "DoorSensorNotificationsHub")] SignalRConnectionInfo connectionInfo)
 {
     return(new OkObjectResult(connectionInfo));
 }