Wraps a live websocket connection for use from app JavaScript, exposing the item id, connection attributes and profile of the connected user, and methods to send or broadcast messages. Instances are handed to an app's onConnected, onDisconnected and onMessage functions, registered via WebsocketMappingBuilder, so an app can react to and drive websocket traffic for its own channel type.
Properties
| Property | Returns | Description |
|---|---|---|
| attributes | Map<String,Object> | The attributes attached to this socket, including any parameters that were supplied when the socket connected. |
| broadcastSockets | List<KademiWebsocket> | |
| commentsType | String | The data type this socket was registered under, matching the type declared on the app's WebsocketMappingBuilder, used to group sockets for broadcast. |
| decodedId | String | The item id decoded from the connection request when this socket was first established. |
| host | String | The hostname of the website this socket connected to. |
| itemId | String | The item id currently assigned to this socket, used to scope broadcast and targeted sends. May differ from the decoded id if setItemId has been called since connecting. |
| profileId | Long | The id of the profile logged in on this socket's session. |
Methods
send(String msg) · broadcastAll(String msg) · broadcast(String msg) · close() · close(int code) · close(int code, String reason) · getHost() · getCommentsType() · getDecodedId() · getItemId() · setItemId(String itemId) · getAttributes() · getProfileId()
send(String msg)
Returns: void
Sends a message to this specific websocket connection only.
| Parameter | Description |
|---|---|
msg | the message text to send |
broadcastAll(String msg)
Returns: void
Broadcasts a message to every socket sharing this socket's data type and item id, including this connection itself.
| Parameter | Description |
|---|---|
msg | the message text to broadcast |
broadcast(String msg)
Returns: void
Broadcasts a message to every other socket sharing this socket's data type and item id, excluding this connection itself.
| Parameter | Description |
|---|---|
msg | the message text to broadcast |
close()
Returns: void
Closes this WebSocket.
close(int code)
Returns: void
Closes this WebSocket using the specified status code.
| Parameter | Description |
|---|---|
code | - the closing status code. |
close(int code, String reason)
Returns: void
Closes this WebSocket using the specified status code and reason.
| Parameter | Description |
|---|---|
code | - the closing status code. |
reason | - the reason, if any. |
getHost()
Returns: String
The hostname of the website this socket connected to.
getCommentsType()
Returns: String
The data type this socket was registered under, matching the type declared on the app's WebsocketMappingBuilder, used to group sockets for broadcast.
getDecodedId()
Returns: String
The item id decoded from the connection request when this socket was first established.
getItemId()
Returns: String
The item id currently assigned to this socket, used to scope broadcast and targeted sends. May differ from the decoded id if setItemId has been called since connecting.
setItemId(String itemId)
Returns: void
Sets the item id for this socket. The item id is used to scope which sockets a broadcast or targeted send reaches.
| Parameter | Description |
|---|---|
itemId | the new item id for this socket |
getAttributes()
Returns: Map<String,Object>
The attributes attached to this socket, including any parameters that were supplied when the socket connected.
getProfileId()
Returns: Long
The id of the profile logged in on this socket's session.