Pubsub
The Pubsub client
Constructor Summary
Public Constructor | ||
public |
constructor(container: Container, internal: Boolean): Pubsub Constructs a new Pubsub object. |
Member Summary
Public Members | ||
public get |
|
|
public get |
connected: Boolean True if it is connected to the server. |
Method Summary
Public Methods | ||
public |
close() Closes connection. |
|
public |
connect() Connects to server if the Skygear container has credentials and not connected. |
|
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()): EventHandle Registers a connection close listener |
|
public |
onOpen(listener: function()): EventHandle Registers a connection open listener |
|
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 |
reset() Closes connection and clear all handlers. |
|
public |
subscribe(channel: string, handler: function(object: *)): function(object: *) Subscribes a function callback on receiving message at the specified channel. |
|
public |
unsubscribe(channel: string, handler: function(object: *)) Unsubscribes a function callback on the specified channel. |
Public Constructors
Public Members
Public Methods
public connect() source
Connects to server if the Skygear container has credentials and not connected.
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()): EventHandle source
Registers a connection close listener
Params:
Name | Type | Attribute | Description |
listener | function() | the listener |
public onOpen(listener: function()): EventHandle source
Registers a connection open listener
Params:
Name | Type | Attribute | Description |
listener | function() | the listener |
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.
public subscribe(channel: string, handler: 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 |
|
handler | function(object: *) | function to be trigger with incoming data |
Return:
function(object: *) | The callback function |
public unsubscribe(channel: string, handler: 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 |
|
handler | function(object: *) |
|
function to be trigger with incoming data |