Set up SignalR
Before you begin
Get a PAT for Authentication.
Ensure you know your environment ID.
Installation
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 Reader API.
You should also replace YOUR_ENVIRONMENT_ID
with the appropriate identifier, a combination of your organization and environment names.
This can be located in one of the following ways:
- Portal URL - Look in the browsers URL when you are logged into the Portal and inside the environment you want to work with. The URL contains the environment ID. For example, everything after "workspace=" through to the next &
!!! note
`workspace=` is legacy. This is in fact your environment ID.
- Settings - Click on
Settings
and then the environment. Click onGeneral settings
. The environment name and environment ID is displayed.
var signalR = require("@microsoft/signalr");
const options = {
accessTokenFactory: () => 'YOUR_ACCESS_TOKEN'
};
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://reader-YOUR_ENVIRONMNENT_ID.platform.quix.ai/hub", options)
.build();
connection.start().then(() => console.log("SignalR connected."));
If the connection is successful, you should see the console log "SignalR connected".