Websocket Related Functions

Hub

Low-level websocket handler for automaton. Before you use this, make sure you actually want to and not the more convenient pubsub implemented on top of this.

.register(type, fn)

Registers a handler for the given message type.

Parameters

NameTypeDescription
typeStringmessage type
fnfunctioncallback that will receive the message payload

Return Value

Type: () => void

unregister function

.send(type, payload)

Sends a message via websocket.

Parameters

NameTypeDescription
typeStringmessage type
payloadobjectmessage payload

Return Value

Type: number

message id

.request(type, payload)

Initiate a request/response over websocket. The server has to react to the message received by sending a Response message referencing the message id of the message.

Parameters

NameTypeDescription
typeStringmessage type
payload------message payload

Return Value

Type: Promise<unknown>

No description

.init(cid)

Initializes the Hub with the prepared connection id for the client.

Parameters

NameTypeDescription
cidStringconnection id

Return Value

Type: Promise<String>

resolves with the connection id after the websocket connection is established.

.getConnectionId()

Returns the current connection id.

Return Value

Type: String

connection id


publish(topic, message)

Publishes the given message payload for the given topic

Parameters

NameTypeDescription
topicStringtopic name
messageobjectmessage payload

subscribeToTopic(topic, handler)

Subscribes the given message handler to the given topic. Returns an unsubscribe function.

Parameters

NameTypeDescription
topicStringtopic name
handlerFunctionmessage handler function. Receives the (filtered) messages for the given topic.