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

PropertyReturnsDescription
attributesMap<String,Object>The attributes attached to this socket, including any parameters that were supplied when the socket connected.
broadcastSocketsList<KademiWebsocket>
commentsTypeStringThe data type this socket was registered under, matching the type declared on the app's WebsocketMappingBuilder, used to group sockets for broadcast.
decodedIdStringThe item id decoded from the connection request when this socket was first established.
hostStringThe hostname of the website this socket connected to.
itemIdStringThe 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.
profileIdLongThe 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.

ParameterDescription
msgthe 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.

ParameterDescription
msgthe 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.

ParameterDescription
msgthe message text to broadcast

close()

Returns: void

Closes this WebSocket.

close(int code)

Returns: void

Closes this WebSocket using the specified status code.

ParameterDescription
code- the closing status code.

close(int code, String reason)

Returns: void

Closes this WebSocket using the specified status code and reason.

ParameterDescription
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.

ParameterDescription
itemIdthe 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.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.