Open tstpierre opened 4 years ago
I found this bindings documentation for the function itself, but is there a server sdk to assist with creating the groups, etc.
Or are we left with doing REST calls to the signalR service directly?
Hi,
i had the same issue and resolved it like this:
const connection: HubConnection = new HubConnectionBuilder()
.withUrl(process.env.REACT_APP_SIGNALR_CONNECTION + "?userId=[USERID]")
.configureLogging(LogLevel.Information)
.build();
[FunctionName("negotiate")]
public static SignalRConnectionInfo GetSignalRInfo(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
[SignalRConnectionInfo(HubName = "chat", UserId = "{query.userId}" )] SignalRConnectionInfo connectionInfo)
{
return connectionInfo;
}
I didnt find a way to attach it to the header.
This the source code from the @microsoft/signalr
npm package it seems like there is no way to attach a custom header.
private async getNegotiationResponse(url: string): Promise<INegotiateResponse> {
let headers;
if (this.accessTokenFactory) {
const token = await this.accessTokenFactory();
if (token) {
headers = {
["Authorization"]: `Bearer ${token}`,
};
}
}
const negotiateUrl = this.resolveNegotiateUrl(url);
this.logger.log(LogLevel.Debug, `Sending negotiation request: ${negotiateUrl}.`);
try {
const response = await this.httpClient.post(negotiateUrl, {
content: "",
headers,
});
I hope this helps you a bit.
In @microsoft/signalr
5.0, a headers
option will be added. https://docs.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-5.0&tabs=javascript#configure-client-options
In addition to the above (thank you for the great question)
When using SignalR Service in serverless and a function app running in Javascript, how do you add users to a group?
Do i need to create a specific function? What should this look like? Specific documentation if possible please :) I've been grappling for days...
Thanks
@DarrenWainwright We should definitely update this sample to use groups. In the meantime, have you seen https://github.com/Azure/azure-signalr/blob/1dcfaab8ee90f9a18f96f9bdb7f0a25ab72a8d70/docs/management-sdk-guide.md?
Edit: I now see you're looking for something for JS. Maybe take a look at https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service-output?tabs=javascript#group-management
How in an Azure Function in node do we access user/connect info and add to a group to control how many messages we actually broadcast out?
Is there a server side hub npm package (much like @microsoft/signalr is for clients) that give us a better sense of whats available?