import {PubsubContainer} from 'skygear-build/packages/skygear-core/lib/pubsub.js'
PubsubContainer
Pubsub container
A publish-subscribe interface, providing real-time message-based communication with other users.
Constructor Summary
Public Constructor | ||
public |
constructor(container: Container): PubsubContainer |
Member Summary
Public Members | ||
public |
autoPubsub: Boolean Indicating if the pubsub client should connect to server automatically. |
Method Summary
Public Methods | ||
public |
hasHandlers(channel: String): Boolean Checks if the channel is subscribed with any handler. |
|
public |
off(channel: string, callback: function(object: *)) Unsubscribes a function callback on the specified channel. |
|
public |
on(channel: string, callback: function(object: *)): function(object: *) Subscribes a function callback on receiving message at the specified channel. |
|
public |
onClose(listener: function()) Registers listener on connection between pubsub client and server is closed. |
|
public |
onOpen(listener: function()) Registers listener on connection between pubsub client and server is open. |
|
public |
once(channel: string): Promise<Object> Subscribes the channel for just one message. |
|
public |
publish(channel: String, data: Object) Publishes message to a channel. |
|
public |
Connects to server if the Skygear container has credential, otherwise close the connection. |
Public Constructors
public constructor(container: Container): PubsubContainer source
Params:
Name | Type | Attribute | Description |
container | Container | the Skygear container |
Public Members
public autoPubsub: Boolean source
Indicating if the pubsub client should connect to server automatically.
Public Methods
public hasHandlers(channel: String): Boolean source
Checks if the channel is subscribed with any handler.
Params:
Name | Type | Attribute | Description |
channel | String | name of the channel |
Return:
Boolean | true if the channel has handlers |
public off(channel: string, callback: function(object: *)) source
Unsubscribes a function callback on the specified channel.
If pass in callback
is null, all callbacks in the specified channel
will be removed.
Params:
Name | Type | Attribute | Description |
channel | string | name of the channel to unsubscribe |
|
callback | function(object: *) | function to be trigger with incoming data |
public on(channel: string, callback: function(object: *)): function(object: *) source
Subscribes a function callback on receiving message at the specified channel.
Params:
Name | Type | Attribute | Description |
channel | string | name of the channel to subscribe |
|
callback | function(object: *) | function to be trigger with incoming data |
Return:
function(object: *) | The callback function |
public onClose(listener: function()) source
Registers listener on connection between pubsub client and server is closed.
Params:
Name | Type | Attribute | Description |
listener | function() | function to be triggered when connection closed |
public onOpen(listener: function()) source
Registers listener on connection between pubsub client and server is open.
Params:
Name | Type | Attribute | Description |
listener | function() | function to be triggered when connection open |
public once(channel: string): Promise<Object> source
Subscribes the channel for just one message.
This function takes one message off from a pubsub channel, returning a promise of that message. When a message is received from the channel, the channel will be unsubscribed.
Params:
Name | Type | Attribute | Description |
channel | string | name of the channel |
Return:
Promise<Object> | promise of next message in this channel |
public publish(channel: String, data: Object) source
Publishes message to a channel.
Params:
Name | Type | Attribute | Description |
channel | String | name of the channel |
|
data | Object | data to be published |
public reconfigure() source
Connects to server if the Skygear container has credential, otherwise close the connection.