I have an Azure Function running in localhost which has a SignalR output binding as follows:
[FunctionName("FxAdoHttpTrigger")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
[SignalR(HubName = "AdoEvents")] IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var data = JsonConvert.DeserializeObject(requestBody);
await signalRMessages.AddAsync(
new SignalRMessage
{
Target = "newMessage",
Arguments = new[] { data }
});
}
}
The following Javascript is in a web app running on localhost:
connection.on("newMessage", (data) => {
const li = document.createElement("li");
li.textContent = `${data}`;
document.getElementById("messageList").appendChild(li);
});
async function start() {
try {
await connection.start();
console.log("SignalR Connected.");
} catch (err) {
console.log(err);
setTimeout(start, 5000);
}
};
connection.onclose(async () => {
alert('onclose fired');
//await start();
});
// Start the connection.
start();
The appSetting in the web app running locally is:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Values": {
"AzureSignalRConnectionString": "Endpoint=https://XXXsignalr-jjjjj.service.signalr.net;AccessKey=secret;Version=1.0;"
},
"AllowedHosts": "*"
}
I consistently get "SignalR Connected" but no client connection shows up in the SignalR Live Trace. No matter what i change the connection string to, I always get success on connect.
Since the Azure Function is publishing to SignalR separately from the Web App, who only wants to read newMessage, I'm at a loss of what i am missing. Do I need a newMessage method in my /Hubs/AdoEvent hub? I have no methods in the hub:
public class AdoHub : Hub
{
}
I'm missing something obvious. Any help would be greatly appreciated.
