SignalR

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 automatically
  • Open-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:

MethodDefinitionDescription
ControlControl(IReadOnlyList<Control> shocks)Send one or more control commands to shockers. Each command requires id, type, intensity, duration and optional exclusive.
ControlV2ControlV2(IReadOnlyList<Control> shocks, string? customName)Same as Control but allows an optional custom sender name to appear in logs.
CaptivePortalCaptivePortal(Guid deviceId, bool enabled)Enable or disable captive portal on a device.
EmergencyStopEmergencyStop(Guid deviceId)Immediately stop a device.
OtaInstallOtaInstall(Guid deviceId, SemVersion version)Trigger firmware update for a device to a specific version.
RebootReboot(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

MethodDefinitionDescription
WelcomeWelcome(string connectionId)Fired after connecting and returns the SignalR connection ID.
DeviceStatusDeviceStatus(IList<DeviceOnlineState> deviceOnlineStates)Provides online status and firmware version for devices accessible to the user.
LogLog(ControlLogSender sender, IEnumerable<ControlLog> logs)Emits control log entries generated by device actions.
DeviceUpdateDeviceUpdate(Guid deviceId, DeviceUpdateType type)Notifies when a device is updated or removed.
OtaInstallStartedOtaInstallStarted(Guid deviceId, int updateId, SemVersion version)A firmware update began on the device.
OtaInstallProgressOtaInstallProgress(Guid deviceId, int updateId, OtaUpdateProgressTask task, float progress)Progress update for an ongoing firmware install.
OtaInstallFailedOtaInstallFailed(Guid deviceId, int updateId, bool fatal, string message)Firmware install failed. fatal indicates rollback.
OtaRollbackOtaRollback(Guid deviceId, int updateId)Firmware install rolled back to previous version.
OtaInstallSucceededOtaInstallSucceeded(Guid deviceId, int updateId)Firmware install finished successfully.

Public share hub methods

MethodDefinitionDescription
WelcomeWelcome(PublicShareHub.AuthType authType)Indicates whether the connected client is authenticated or a guest.
UpdatedUpdated()Share link configuration changed.

These methods deliver typed payloads matching the backend models. Refer to the OpenShock API for structure details.

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

On this page