Interactive documentation for real-time WebSocket communication
Real-time notifications for specification questionnaire section updates
This hub requires JWT authentication. Provide an access token via accessTokenFactory when connecting.
Company-based specification access control. Users can only subscribe to specifications shared with their company.
import * as signalR from "@microsoft/signalr";
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://your-api-url/default/hubs/specification-questionnaires", {
accessTokenFactory: async () => {
return await getAccessToken();
}
})
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build();
await connection.start();
console.log("Connected to SpecificationQuestionnaireHub");
Methods that clients can invoke on the server
Subscribe to real-time updates for a specific specification
| Name | Type | Required | Description |
|---|---|---|---|
specificationId |
Guid | Yes | The specification ID to subscribe to |
Promise<void>
const specificationId = "550e8400-e29b-41d4-a716-446655440000";
try {
await connection.invoke("SubscribeToSpecification", specificationId);
console.log("Subscribed to specification:", specificationId);
} catch (error) {
console.error("Failed to subscribe:", error.message);
}
Unsubscribe from specification updates
| Name | Type | Required | Description |
|---|---|---|---|
specificationId |
Guid | Yes | The specification ID to unsubscribe from |
Promise<void>
None - This method will not throw exceptions
const specificationId = "550e8400-e29b-41d4-a716-446655440000";
await connection.invoke("UnsubscribeFromSpecificationId", specificationId);
console.log("Unsubscribed from specification:", specificationId);
Events that the server sends to subscribed clients
Sent when a questionnaire is linked to or unlinked from a specification
When a questionnaire is linked to or unlinked from a specification chapter
All clients subscribed to the specification group
| Property | Type | Description |
|---|---|---|
specificationId |
Guid | The ID of the specification |
chapterType |
string | The chapter type (e.g., "production", "labeling") |
{
"specificationId": "550e8400-e29b-41d4-a716-446655440000",
"chapterType": "production"
}
connection.on("SpecificationQuestionnaireSectionUpdated", (data) => {
console.log("Questionnaire section updated:", data.specificationId);
console.log("Chapter type:", data.chapterType);
// Refresh the questionnaire list for this chapter
refreshQuestionnaires(data.specificationId, data.chapterType);
});
import * as signalR from "@microsoft/signalr";
// 1. Create connection
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://your-api-url/default/hubs/specification-questionnaires", {
accessTokenFactory: async () => await getAccessToken()
})
.withAutomaticReconnect()
.build();
// 2. Register event handlers BEFORE connecting
connection.on("SpecificationQuestionnaireSectionUpdated", (data) => {
console.log("Questionnaire section updated:", data);
refreshQuestionnaires(data.specificationId, data.chapterType);
});
// 3. Connect
await connection.start();
console.log("Connected to SignalR hub");
// 4. Subscribe to specification
const specificationId = "550e8400-e29b-41d4-a716-446655440000";
try {
await connection.invoke("SubscribeToSpecification", specificationId);
console.log("Subscribed to specification:", specificationId);
} catch (error) {
console.error("Failed to subscribe:", error.message);
}
// 5. Later, unsubscribe and disconnect
await connection.invoke("UnsubscribeFromSpecificationId", specificationId);
await connection.stop();
console.log("Disconnected");