Skip to content

Latest commit

 

History

History

SignalR Service Serverless Quick Start (JavaScript)

In this sample, we demonstrate how to broadcast messages with SignalR Service and Azure Function in serverless.

Prerequisites

Azure Functions with CommonJS

Because ESM support is still in preview for Azure Functions, this quickstart uses CommonJS modules including node-fetch. If you update the node-fetch package to 3.x, you may need to update the code to use ESM modules, which requires changing from const to import and *.js to *.mjs.

Setup and run locally

  1. Start local storage emulator in terminal.

    npm run start:azurite
  2. Rename local.settings.template.json to local.settings.json and update env variable.

    • SIGNALR_CONNECTION_STRING: The connection string of your Azure SignalR Service.
  3. Run command to start Azure Function locally in different terminal.

    npm start
  4. Visit http://localhost:7071/api/index.

    Screenshot of index showing no star count

  5. Go to this repo's home page and click the star button to increase or decrease the star count.

  6. The Azure Functions broadcast function is triggered every minute to see if the star count has changed. If it has chanaged base on checking the eTag, a new star count is sent as a message to the client.

close