Last active
May 23, 2018 08:22
-
-
Save GrillPhil/6ddeaaa47649443b21fb03e31d5eb25e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using Microsoft.Azure.WebJobs.Extensions.SignalRService; | |
using Microsoft.Azure.WebJobs.Host; | |
using System.IO; | |
using System.Threading.Tasks; | |
namespace ServerlessRealtimeDemo | |
{ | |
public static class MessageFunction | |
{ | |
[FunctionName("message")] | |
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req, | |
[SignalR(HubName = "broadcast")]IAsyncCollector<SignalRMessage> signalRMessages, | |
TraceWriter log) | |
{ | |
string requestBody = new StreamReader(req.Body).ReadToEnd(); | |
if (string.IsNullOrEmpty(requestBody)) | |
{ | |
return new BadRequestObjectResult("Please pass a payload to broadcast in the request body."); | |
} | |
await signalRMessages.AddAsync(new SignalRMessage() | |
{ | |
Target = "notify", | |
Arguments = new object[] { requestBody } | |
}); | |
return new OkResult(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment