Home > SYS_WebSocket > register
SYS_WebSocket.register() method
Register a WebSocket connection
Signature
function register(
id: string,
serviceUri: string,
receiveMessageCallFn?: (event: MessageEvent<any>) => void | Promise<void>,
connectedCallFn?: () => void | Promise<void>,
protocols?: string | Array<string>,
): void;2
3
4
5
6
7
Parameters
Parameter | Type | Description |
|---|---|---|
id | string | Custom WebSocket ID |
serviceUri | string | WebSocket service URI |
receiveMessageCallFn | (event: MessageEvent<any>) => void | Promise<void> | (Optional) Callback function when a message is received |
connectedCallFn | () => void | Promise<void> | (Optional) Callback function when the connection is established |
protocols | string | Array<string> | (Optional) Sub-protocols |
Returns
void
Remarks
It can be used to detect whether the WebSocket connection is normal before execution, but note that **do not attempt connections with the same ID but different parameters**, as this will cause confusion: if a WebSocket connection with the specified ID is active, changes to other parameters will not be applied
Note: This API requires the user to enable the extension external interaction permission, if not enabled, it will always throw Error