Home Reference Source
public class | source

PubsubContainer

Pubsub container

A publish-subscribe interface, providing real-time message-based communication with other users.

Constructor Summary

Public Constructor
public

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:

NameTypeAttributeDescription
container Container

the Skygear container

Return:

PubsubContainer

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

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