Setting up SignalR

Before you begin


If you are using a package manager like npm, you can install SignalR using npm install @microsoft/signalr. For other installation options that don’t depend on a platform like Node.js, such as consuming SignalR from a CDN, please refer to SignalR documentation.

Testing the connection

Once you’ve installed the SignalR library, you can test it’s set up correctly with the following code snippet. This opens a connection to the hub running on your custom subdomain, and checks authentication.

You should replace the text YOUR_ACCESS_TOKEN with the PAT obtained from Authenticating with the Streaming Writer API.

You should also replace YOUR_WORKSPACE_ID with the appropriate identifier, a combination of your organistation and workspace names. This can be located in one of the following ways:

  • Portal URL

  • Topics Page

Look in the browsers URL when you are logged into the Portal and inside the Workspace you want to work with. The URL contains the workspace id. e.g everything after "workspace=" till the next '&'

In the Portal, inside the Workspace you want to work with, click the Topics menu topics and then click the expand icon expand on any topic. Here you will see a 'Username' under the Broker Settings. This Username is also the Workspace Id.

// Also available as JsFiddle at
var signalR = require("@microsoft/signalr");
const token = "YOUR_TOKEN"
const workspaceId = "YOUR_WORKSPACE_ID"

const options = {
    accessTokenFactory: () => token

const connection = new signalR.HubConnectionBuilder()
    .withUrl("https://writer-" + workspaceId + "", options)

connection.start().then(() => console.log("SignalR connected."));

If the connection is successful, you should see the console log “SignalR connected”.