Methods
(static) channel(key)
- Source:
Create an event dispatcher instance and subscribe to a new socket channel.
This can then be used to receive socket events for this channel
Example
const socketChannel = await sdk.socket.channel('awesome:notifications')
socketChannel.addEventListener('message', function(message) {
console.log('Received a new message from the socket')
})
// Disconnect from this channel and remove all listeners
socketChannel.destroy();
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String | The key or name of the channel to subscribe to |
(static) close()
- Source:
Close the connection to the socket service
Example
const closed = await sdk.socket.close()
(static) connect()
- Source:
Connect to the socket service
Example
const connected = await sdk.socket.connect()
(static) reconnect()
- Source:
Reconnect to the socket service
Example
const connected = await sdk.socket.reconnect()
(static) subscribe(key)
- Source:
Subscribe to a socket channel
Example
const subscribed = await sdk.socket.subscribe('some:cool:alert')
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String | The name of the channel to subscribe to |
(static) unsubscribe(key)
- Source:
Unsubscribe from a socket channel
Example
const unsubscribed = await sdk.socket.unsubscribe('some:cool:alert')
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String | The name of the channel to unsubscribe from |