I'm trying to move my app using SignalR from a "traditional server based" to an Serverless Azure Function App. I have no problem hitting the Negotiate method, but my most basic client-to-server method will not fire.
// Server endpoints...
namespace TooDuh.Serverless.Hubs
{
public class TestHub: ServerlessHub
{
[FunctionName("negotiate")]
public SignalRConnectionInfo Negotiate( [HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req )
{
var claims = GetClaims(req.Headers["Authorization"]);
var connectionInfo = Negotiate( req.Headers["x-ms-signalr-user-id"], claims );
return connectionInfo;
}
[FunctionName("SendMessage")]
public async Task SendMessage(
[SignalRTrigger] InvocationContext invocationContext, string message, ILogger logger)
{
logger.LogInformation($"Receive {message} from {invocationContext.ConnectionId}.");
char[] stringArray = message.ToCharArray();
Array.Reverse(stringArray);
string reversedStr = new string(stringArray);
await Clients.All.SendAsync("ReceiveMessage", reversedStr);
}
...
// Client method...
async function sendToServer(){
try {
console.log("[Client.SignalR.SendMessage] " + userInput.value);
await connection.invoke("SendMessage", userInput.value);
} catch (err) {
console.error(err);
}
}
Is there something different I'm supposed to do with the bindings? The docs are a real scramble, but I'm trying to work from AzureSignalR-samples/BidirectionChat on GitHub... which does nothing better when I try to debug locally.
Here is the way i am able to hit a SignalR ServerlessHub method
Step-1: Create an Azure Functions project
Step-2: Make sure your Azure Functions project is configured properly to use SignalR. The SignalR service connection string should be stored in your configuration. In the
local.settings.jsonfile for local developmentStep-3: Create Your SignalR Hub
Step-4: Add Required Packages
Step-5: Client Code You can use a simple HTML/JavaScript client to connect to your SignalR hub.
Verify the Connection State:
Before invoking the "SendMessage" method, ensure that the SignalR connection is in the "Connected" state. You can use the
stateproperty of the connection to check the current state and ensure it's connected before sending a messageResult