@@ -244,36 +244,36 @@ The web app also requires an HTTP API to send chat messages. Create an HTTP trig
244
244
1. Open the _src/functions/sendMessage.js_ file, update the content as follows:
245
245
246
246
` ` ` js
247
- const { app, output } = require(' @azure/functions' );
248
-
249
- const signalR = output.generic({
250
- type: ' signalR' ,
251
- name: ' signalR' ,
252
- hubName: ' default' ,
253
- connectionStringSetting: ' AzureSignalRConnectionString' ,
254
- });
255
-
256
- app.http(' messages' , {
257
- methods: [' POST' ],
258
- authLevel: ' anonymous' ,
259
- extraOutputs: [signalR],
260
- handler: async (request, context) => {
261
- const message = await request.json ();
262
- message.sender = request.headers && request.headers.get(' x-ms-client-principal-name' ) || ' ' ;
263
-
264
- let recipientUserId = ' ' ;
265
- if (message.recipient) {
266
- recipientUserId = message.recipient;
267
- message.isPrivate = true ;
268
- }
269
- context.extraOutputs.set(signalR,
270
- {
271
- ' userId' : recipientUserId,
272
- ' target' : ' newMessage' ,
273
- ' arguments' : [message]
274
- });
275
- }
276
- });
247
+ const { app, output } = require(' @azure/functions' );
248
+
249
+ const signalR = output.generic({
250
+ type: ' signalR' ,
251
+ name: ' signalR' ,
252
+ hubName: ' default' ,
253
+ connectionStringSetting: ' AzureSignalRConnectionString' ,
254
+ });
255
+
256
+ app.http(' messages' , {
257
+ methods: [' POST' ],
258
+ authLevel: ' anonymous' ,
259
+ extraOutputs: [signalR],
260
+ handler: async (request, context) => {
261
+ const message = await request.json ();
262
+ message.sender = request.headers && request.headers.get(' x-ms-client-principal-name' ) || ' ' ;
263
+
264
+ let recipientUserId = ' ' ;
265
+ if (message.recipient) {
266
+ recipientUserId = message.recipient;
267
+ message.isPrivate = true ;
268
+ }
269
+ context.extraOutputs.set(signalR,
270
+ {
271
+ ' userId' : recipientUserId,
272
+ ' target' : ' newMessage' ,
273
+ ' arguments' : [message]
274
+ });
275
+ }
276
+ });
277
277
` ` `
278
278
279
279
The function contains an HTTP trigger and a SignalR output binding. It takes the body from the HTTP request and sends it to clients connected to Azure SignalR Service. It invokes a function named ` newMessage` on each client.
0 commit comments