SignalR Hub: User
URL: https://api.openshock.app/1/hubs/user
Endpoint
Connecting
Use a SignalR client and provide the required headers:
User-Agent: A meaningful identifier for your application. Browsers do this automaticallyOpen-Shock-Token: API token created in account settings.
import { HubConnectionBuilder, LogLevel } from "@microsoft/signalr";
const connection = new HubConnectionBuilder()
.withUrl("https://api.openshock.app/1/hubs/user", {
transport: HttpTransportType.WebSockets,
skipNegotiation: true,
})
.withAutomaticReconnect()
.configureLogging(LogLevel.Information)
.build();
await connection.start();Server methods
The user hub exposes the following methods that can be invoked with connection.invoke:
| Method | Definition | Description |
|---|---|---|
Control | Control(IReadOnlyList<Control> shocks) | Send one or more control commands to shockers. Each command requires id, type, intensity, duration and optional exclusive. |
ControlV2 | ControlV2(IReadOnlyList<Control> shocks, string? customName) | Same as Control but allows an optional custom sender name to appear in logs. |
CaptivePortal | CaptivePortal(Guid deviceId, bool enabled) | Enable or disable captive portal on a device. |
EmergencyStop | EmergencyStop(Guid deviceId) | Immediately stop a device. |
OtaInstall | OtaInstall(Guid deviceId, SemVersion version) | Trigger firmware update for a device to a specific version. |
Reboot | Reboot(Guid deviceId) | Reboot a device. |
Example control message:
[
{
"id": "00000000-0000-0000-0000-000000000000",
"type": 1,
"intensity": 50,
"duration": 1000,
"exclusive": false
}
]Client methods
Listen for server calls with connection.on("MethodName", handler).
User hub methods
| Method | Definition | Description |
|---|---|---|
Welcome | Welcome(string connectionId) | Fired after connecting and returns the SignalR connection ID. |
DeviceStatus | DeviceStatus(IList<DeviceOnlineState> deviceOnlineStates) | Provides online status and firmware version for devices accessible to the user. |
Log | Log(ControlLogSender sender, IEnumerable<ControlLog> logs) | Emits control log entries generated by device actions. |
DeviceUpdate | DeviceUpdate(Guid deviceId, DeviceUpdateType type) | Notifies when a device is updated or removed. |
OtaInstallStarted | OtaInstallStarted(Guid deviceId, int updateId, SemVersion version) | A firmware update began on the device. |
OtaInstallProgress | OtaInstallProgress(Guid deviceId, int updateId, OtaUpdateProgressTask task, float progress) | Progress update for an ongoing firmware install. |
OtaInstallFailed | OtaInstallFailed(Guid deviceId, int updateId, bool fatal, string message) | Firmware install failed. fatal indicates rollback. |
OtaRollback | OtaRollback(Guid deviceId, int updateId) | Firmware install rolled back to previous version. |
OtaInstallSucceeded | OtaInstallSucceeded(Guid deviceId, int updateId) | Firmware install finished successfully. |
Public share hub methods
| Method | Definition | Description |
|---|---|---|
Welcome | Welcome(PublicShareHub.AuthType authType) | Indicates whether the connected client is authenticated or a guest. |
Updated | Updated() | Share link configuration changed. |
These methods deliver typed payloads matching the backend models. Refer to the OpenShock API for structure details.
Share link hub
To connect to a share link hub, use the share link identifier and optionally provide a name query parameter for guest connections:
const shareConn = new HubConnectionBuilder()
.withUrl(
"https://api.openshock.app/1/hubs/share/link/01234567-89ab-cdef-0123-456789abcdef?name=Guest",
)
.build();
await shareConn.start();Guests can call Control to interact with the devices shared via the link. Authenticated users may also be notified through the user hub when share link activity occurs.
Disconnecting
Call connection.stop() when your application shuts down to gracefully close the WebSocket.
await connection.stop();This page describes the basics for working with OpenShock's SignalR hubs. For full type definitions consult the server source code or OpenShock community resources.
Last updated on