Skip to content

Usage

object:Channel

Channel object exposes trust-safe flexible Pub/Sub messaging properties, functions and events to build real-time event messaging / event driven applications at scale.

Concepts

  • A message is attached to an event
  • Group similar events into a channel
  • Subscribe to a channel to receive all channel event messages.
  • Publish event message to the channel and it will be sent to all the channel subscribers who are connected to dataBrdiges network and online.
  • if you need to have an access controlled channel, prefix the channel name with pvt: , prs: and sys: .To subscribe to these type of channel. you will need to pass a trust-token when you subscribe to the channel. A trust-token is a JWT document created using a combination of channelname + sessionid + app.secret.
  • Use your existing access control, authorization and session identification rule-set, process and methods to create a trust-token instructing the dataBrdiges router to accept the pvt: prs: and sys: channel subscription, connection of from client application.
  • Trust-tokens allows you to enable secured, access controlled and compliance driven real-time event driven messaging in your existing and new initiative applications.

dataBrdiges library supports 4 types of channel. The namespace is the 4 characters preceding the channelName (pvt:,prs:,sys:), identifying which type of channel the application is connecting to. If the channel type is pvt:,prs:,sys:, dataBrdiges library will use the access_token function to get the access encrypted token and will use it for all communication with this channel.

Channel Type Channel Name Style Description
Public channelName Public channel is used to send and receive messages that are to be publicly available. This channel type does not require any trust authorization token to subscribe. e.g channelName = mychannel
Private pvt: channeName Private channels is restricted channel. application will need to provide trust authorization token to subscribe and use Private channel. The dataBrdiges library will use the access_token function to get the trust authorization token. e.g channelName = pvt:mychannel
Presence prs: channeName Presence channels is a specialized private channel with additional feature of presence awareness. Subscribing to presence channel allows application to be notified of members joining / leaving the channel. Since Presence channel is a specialized version of Private channel, application will need to provide trust authorization token to subscribe and use Private channels. The dataBrdiges library will use the access_token function to get the trust authorization token. e.g channelName = prs:mychannel
System sys: channeName System channel is a specialized Presence channel to build command and control applications. Using System channel to create command and control server applications to send messages to devices and application using dataBrdiges library in **trust-safe manner **, build smart update configuration system and implement **trust-safe ** actions for remote and automated management. System channel allows application to send and receive messages with the server application (using dataBrdiges server library). Since System channel is a specialized version of Presence channel, application will need to provide trust authorization token to subscribe and use Private channels. The dataBrdiges library will use the access_token function to get the trust authorization token. e.g channelName = sys:systeminfo

dataBrdiges library provides 2 different ways to access any of above channel types based on usage.

Channel Type Description
Subscribe to Channel application that subscribes to a channel will receive messages and can send messages.
Connect to Channel Where we have use-cases where application needs to only send messages and not interested to consume / receive channel messages, should connect to channel instead of subscribing to the channel.

Subscribe to Channel

Application that subscribes to a channel will receive messages and can send messages.

subscribe()

The default method for subscribing to a channel involves invoking the channel.subscribe function of your dataBrdiges object:

try {
    const subscribed_channel = dbridge.channel.subscribe('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try {
    const subscribed_channel = dbridge.channel.subscribe('mychannel');
} catch (err) {
    console.log(err.source, err.code, err.message);
}
try:
    subscribed_channel =  await dbridge.channel.subscribe('mychannel')
except dBError as e:
    print(e.code, e.source, e.message)
try {
    dBridges.channel.channel subscribed_channel = dbridge.channel.subscribe('mychannel');
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
try{
    channel subscribed_channel =  dbridge.channel.subscribe('mychannel')
} catch (dBError dberror){
    Log.d("main", "onEvent: " +  dberror.code + ","  +  dberror.source);
}
do {
    subscribed_channel:channel =  dbridge.channel.subscribe('mychannel')
} catch (error) {   
    let dberror = error as?  dBError
    print("main", "onEvent: " +  dberror.code + ","  +  dberror.source)
}
Parameter Rules Description
string channelName **OR*
pvt:**channelName **OR
prs:**channelName **OR
**sys:**channelName*
channelName to which subscription to be done.
Return Type Description
object channel object which events and related functions can be bound to.

Application can directly work with dataBrdiges object without using Channel object. Using this method application cannot publish any events.

try {
    dbridge.channel.subscribe('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try {
    dbridge.channel.subscribe('mychannel');
} catch (err) {
    console.log(err.source, err.code, err.message);
}
try:
    await dbridge.channel.subscribe('mychannel')
except dBError as e:
    print(e.code, e.source, e.message)
try {
    dbridge.channel.subscribe('mychannel');
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
try{
    dbridge.channel.subscribe('mychannel')
} catch (dBError dberror){
    Log.d("main", "onEvent: " +  dberror.code + ","  +  dberror.source);
}
do {
    dbridge.channel.subscribe('mychannel')
} catch (error) {   
    let dberror = error as?  dBError
    print("main", "onEvent: " +  dberror.code + ","  +  dberror.source)
}
Exceptions:
Source Code Description
DBLIB_CHANNEL_SUBSCRIBE NETWORK_DISCONNECTED Connection to dataBrdiges network is not active.
DBLIB_CHANNEL_SUBSCRIBE INVALID_CHANNELNAME Applicable for below conditions
1. channelName is not defined.
2. channelName validation error, typeof() channelName is not type string
3. channelName validation error, channelName fails a-zA-Z0-9\.:_- validation.
DBLIB_CHANNEL_SUBSCRIBE INVALID_CHANNELNAME_LENGTH channelName validation error, length of channelName greater than 64
DBLIB_CHANNEL_SUBSCRIBE CHANNEL_ALREADY_SUBSCRIBED channelName is already subscribed.

unsubscribe()

To unsubscribe from a subscribed channel, invoke the unsubscribe function of your dataBrdiges object. unsubscribe cannot be done on channel object.

try {
    dbridge.channel.unsubscribe('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try {
    dbridge.channel.unsubscribe('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try:
    dbridge.channel.unsubscribe('mychannel')
except dBError as e:
    print(e.code, e.source, e.message)    
try {
    dbridge.channel.unsubscribe('mychannel');
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
try{
    dbridge.channel.unsubscribe('mychannel')
} catch (dBError dberror){
    Log.d("main", "onEvent: " +  dberror.code + ","  +  dberror.source);
}
do {
    dbridge.channel.unsubscribe('mychannel')
} catch (error) {   
    let dberror = error as?  dBError
    print("main", "onEvent: " +  dberror.code + ","  +  dberror.source)
}  
Parameter Rules Description
string channelName **OR*
pvt:**channelName **OR
prs:**channelName **OR
**sys:**channelName*
*channel*Name to which un-subscription to be done.
Return Type Description
NA
Exceptions:
Source Code Description
DBLIB_CHANNEL_UNSUBSCRIBE NETWORK_DISCONNECTED Connection to dataBrdiges network is not active.
DBLIB_CHANNEL_UNSUBSCRIBE CHANNEL_NOT_SUBSCRIBED channelName is not subscribed.
DBLIB_CHANNEL_UNSUBSCRIBE INVALID_CHANNEL_TYPE channelName is not subscribed, but it is in connected state.
DBLIB_CHANNEL_UNSUBSCRIBE UNSUBSCRIBE_ALREADY_INITIATED unsubscription to the channel is already initiated and hence the current unsubscribe command exited with exception.

Connect to Channel

Use-cases where application needs to only send channel messages and not interested to consume / receive channel messages, should connect to channel instead of subscribing to the channel.

connect()

The default method for connecting to a channel involves invoking the channel.connect function of your dataBrdiges object. Application cannot publish system events for which it has connected to.

try {
    const connected_channel = dbridge.channel.connect('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try {
    const connected_channel = dbridge.channel.connect('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try:
    connected_channel = dbridge.channel.connect('mychannel')
except dBError as e:
    print(e.code, e.source, e.message)
try {
    dBridges.channel.channelnbd connected_channel = dbridge.channel.connect('mychannel');
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
try{
    channelnbd  connected_channel =  dbridge.channel.connect('mychannel')
} catch (dBError dberror){
    Log.d("main", "onEvent: " +  dberror.code + ","  +  dberror.source);
}
do {
    let connected_channel:Connect =  dbridge.channel.connect('mychannel')
} catch (error) {   
    let dberror = error as?  dBError
    print("main", "onEvent: " +  dberror.code + ","  +  dberror.source)
}
Parameter Rules Description
string channelName **OR*
pvt:**channelName **OR
prs:**channelName **OR
**sys:**channelName*
*channel*Name to which connection to be done.
Return Type Description
object channel object which events and related functions can be bound to.
Exceptions:
Source Code Description
DBLIB_CHANNEL_CONNECT NETWORK_DISCONNECTED Connection to dataBrdiges network is not active.
DBLIB_CHANNEL_CONNECT CHANNEL_ALREADY_CONNECTED channelName is already connected.
DBLIB_CHANNEL_CONNECT INVALID_CHANNELNAME Applicable for below conditions
1. channelName is not defined.
2. channelName validation error, typeof() channelName is not type string
3. channelName validation error, length of channelName greater than 64
4. channelName validation error, channelName fails a-zA-Z0-9\.:_- validation.
5. if channelName contains : and first token is not pvt,prs,sys

disconnect()

To disconnect from a connected channel, invoke the disconnect function of your dataBrdiges object. disconnect cannot be done on channel object.

try {
    dbridge.channel.disconnect('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try {
    dbridge.channel.disconnect('mychannel')
} catch (err) {
    console.log(err.source, err.code, err.message)
}
try:
    dbridge.channel.disconnect('mychannel')
except dBError as e:
    print(e.code, e.source, e.message) 
try {
    dbridge.channel.disconnect('mychannel');
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
try {
    dbridge.channel.disconnect('mychannel');
} catch (dBError dberror){
    Log.d("main", "onEvent: " +  dberror.code + ","  +  dberror.source);
}
do {
    dbridge.channel.disconnect('mychannel')
} catch (error) {   
    let dberror = error as?  dBError
    print("main", "onEvent: " +  dberror.code + ","  +  dberror.source)
}
Parameter Rules Description
string channelName **OR*
pvt:**channelName **OR
prs:**channelName **OR
**sys:**channelName*
*channel*Name to which disconnection to be done.
Return Type Description
NA
Exceptions:
Source Code Description
DBLIB_CHANNEL_DISCONNECT NETWORK_DISCONNECTED Connection to dataBrdiges network is not active.
DBLIB_CHANNEL_DISCONNECT DISCONNECT_ALREADY_INITIATED disconnect to the channel is already initiated and hence the current disconnect command exited with exception.
DBLIB_CHANNEL_DISCONNECT INVALID_CHANNEL channelName is not connected.
DBLIB_CHANNEL_DISCONNECT INVALID_CHANNEL_TYPE channelName is not connected, but it is in subscribed state.

Channel Information

isOnline()

dBridgeObject as well as channelObject provides a function to check if the channel is online. The best practice is to check the channel is online before publishing any message.

const isonline = dbridge.channel.isOnline('mychannel');
// Using channelObject
const isonline = subscribed_channel.isOnline();
const isonline = dbridge.channel.isOnline('mychannel');
// Using channelObject
const isonline = subscribed_channel.isOnline();
isonline = dbridge.channel.isOnline('mychannel')
# Using channelObject
isonline = subscribed_channel.isOnline()
bool isonline = dbridge.channel.isOnline('mychannel');
// Using channelObject
bool isonline = subscribed_channel.isOnline();
Boolean isonline = dbridge.channel.isOnline('mychannel');
// Using channelObject
Boolean isonline = subscribed_channel.isOnline();
let isonline:Bool = dbridge.channel.isOnline('mychannel')
// Using channelObject
let isonline:Bool = subscribed_channel.isOnline()
Parameter Rules Description
string channelName **OR*
pvt:**channelName **OR
prs:**channelName **OR
**sys:**channelName*
*channel*Name
Return Values Description
boolean Is the current status of channel online or offline.

list()

dBridgeObject provides a function to get list of successfully subscribed or connected channel.

const channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }]
const channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }]
channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }] 
List<Dictionary<string, object>>  channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }]
List<Dictionary<String, object>>  channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }]
let channels = dbridge.channel.list();
#=> [{"name":  "mychannel" , "type": "subscribed/connect" ,  "isonline": true/false }]
Return Type Description
array of dict Array of channels subscribed or connected.

Dictionary contains below information.

Key Description
name (string) channelName of subscribed or connected channel.
type (string) subscribed or connected
isonline (boolean) Is the current status of channel online or offline.

getChannelName()

channelObject provides a function to get the channelName.

const chName = channelobject.getChannelName();
const chName = channelobject.getChannelName();
chName = channelobject.getChannelName();
string chName = channelobject.getChannelName();
String chName = channelobject.getChannelName();
let chName = channelobject.getChannelName();
Return Type Description
string channelName of subscribed or connected channel.

Publish to Channel

Publish event-message using the publish function on an instance of the channel object.

A message is linked to an event and hence event-message. dataBrdiges allows you to bind to various events to create rich event driven processing flows

publish()

The default method for publishing to a channel involves invoking the channel.publish function of your channelObject.

try {
    channelObject.publish(event, payload, seqno);
} catch (err) {
    console.log(err.source, err.code, err.message);
}

// Best practice is to check the channel is online before publishing any message.
if (channelObject.isOnline()) {
    try {
        channelObject.publish(event, payload, seqno);
    } catch (err) {
        console.log(err.source, err.code, err.message);
    }
}
try {
    channelObject.publish(event, payload, seqno);
} catch (err) {
    console.log(err.source, err.code, err.message);
}

// Best practice is to check the channel is online before publishing any message.
if (channelObject.isOnline()) {
    try {
        channelObject.publish(event, payload, seqno);
    } catch (err) {
        console.log(err.source, err.code, err.message);
    }
}
try:
    channelObject.publish(eventname, payload, excludeSessionId, sourceId, seqno)
except dBError as e:
    print(e.code, e.source, e.message) 

# Best practice is to check the channel is online before publishing any message.
if channelObject.isOnline():
    try:
        channelObject.publish(eventname, payload, excludeSessionId, sourceId, seqno)
    except dBError as e:
        print(e.code, e.source, e.message) 
try {
  channelObject.publish(event, payload, excludeSessionId, sourceId, seqno);
} catch (dBError err) {
  Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}

// Best practice is to check the channel is online before publishing any message.
if (channelObject.isOnline()) {
  try {
    channelObject.publish(event, payload, excludeSessionId, sourceId, seqno);
  } catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
  }    
}
try {
    channelObject.publish(eventname, payload, seqno);
} catch(dBError dberror) {
    Log.d("Exception: ", "dBError : " +  dberror.code + "::" + dberror.source);
}

// Best practice is to check the channel is online before publishing any message.
if (channelObject.isOnline()) {
    try {
        channelObject.publish(eventname, payload, seqno);
    } catch(dBError dberror) {
        Log.d("Exception: ", "dBError : " +  dberror.code + "::" + dberror.source);
    }
}
do {
    channelObject.publish(eventname, payload, seqno)
} catch(dBError dberror) {
    print("Exception: ", "dBError : " +  dberror.code + "::" + dberror.source)
}

// Best practice is to check the channel is online before publishing any message.
if (channelObject.isOnline()) {
    do {
        channelObject.publish(eventname, payload, seqno)
    } catch(dBError dberror) {
        print("Exception: ", "dBError : " +  dberror.code + "::" + dberror.source)
    }
}
Parameter Description
event (string) event Name to which the message to be sent. event Name cannot start with dbridges:
payload (string) Payload to be sent with the event.
seqno (string) [optional] Message sequence number. This is optional parameter. seqno can be used by applications to manage message queue processing by the subscribers.
Return Values Description
NA
Exceptions:
Source Code Description
DBLIB_CHANNEL_PUBLISH INVALID_SUBJECT Applicable for below conditions
1. event validation error, typeof() event is not type string
2. event validation error, event is not defined
DBLIB_CHANNEL_PUBLISH NETWORK_DISCONNECTED Connection to dataBrdiges network is not active.

Binding to events

A message is linked to an event and hence event-message. dataBrdiges allows you to bind to various events to create rich event processing flows. An application needs to bind to event to process the received message.

You can use the following methods either on a channelObject, to bind to events on a particular channel; or on the dbridgeObject, to bind to events on all subscribed channels simultaneously.

bind and unbind

Bind to "event" on channel: payload and metadata is received.

//  Binding to channel events on channelObject using Anonymous function.
try {
    channelObject.bind('eventName',  (payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to channel events on dbridgeObject  using Anonymous function.
try {
    dbridge.channel.bind('eventName', (payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to channel events on channelObject using user function.
const myEventHandler = (payload, metadata) =>{
    console.log(payload, metadata);
};

try {
    dbridge.channel.bind('eventName', myEventHandler);
} catch(err){
     console.log(err.source, err.code, err.message);
} 
//  Binding to channel events on channelObject using Anonymous function.
try {
    channelObject.bind('eventName',  (payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to channel events on dbridgeObject  using Anonymous function.
try {
    dbridge.channel.bind('eventName', (payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to channel events on channelObject using user function.
const myEventHandler = (payload, metadata) =>{
    console.log(payload, metadata);
};

try {
    dbridge.channel.bind('eventName', myEventHandler);
} catch(err){
     console.log(err.source, err.code, err.message);
}
# Binding to channel events on channelObject  
def eventFunction(payload ,  metadata):
    print(payload , metadata)

try:
    channelObject.bind('eventName',  eventFunction)
except dBError as e:
    print(e.code, e.source, e.message) 

# Binding to channel events on dbridgeObject 
try {
    dbridge.channel.bind('eventName', eventFunction)
except dBError as e:
    print(e.code, e.source, e.message) 
//  Binding to channel events on channelObject using Anonymous function.
Action<object,object> iChannelStatus;
try {
    channelObject.bind('eventName',  iChannelStatus = (object payload, object metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
// Binding to channel events on dbridgeObject 

try {
    dbridge.channel.bind('eventName', iChannelStatus = (object payload, object metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}

// Binding to channel events on channelObject using user function.
void channelStatus(object payload, object metadata){
    Console.WriteLine("{0} , {1} " , payload, metadata);
}

try {
    Action<object,object> iChannelStatus = channelStatus;
    dbridge.channel.bind('eventName', iChannelStatus);
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
// Binding to channel events on channelObject  
channelObject.bind(event , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
        Log.i("event: ", message);
        Log.i("event: ", metadata);
    }
});

//  Binding to channel events on dbridgeObject
dbridge.channel.bind(event , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
        Log.i("event: ", message);
        Log.i("event: ", metadata);
    }
});
// Binding to channel events on channelObject  
channelObject.bind(event , {  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata) 
})

//  Binding to channel events on dbridgeObject
dbridge.channel.bind(event , {  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata)
})
Parameter Description
event (string) event Name to which binding to be done.
Callback parameters
payload:

(string) Payload data sent by the publisher.

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "event",               // (string) eventName 
    "sourcesysid": "",                  // (string) Sender system identity, applicable only for presence or system channel.
    "sqnum": "1",                       // (string) user defined, sent during publish function.
    "sessionid": "",                    // (string) Sender sessionid, applicable only for presence or system channel.
    "intime": 1645554960732             // (string) EPOC time of the sender at time of publish.
}
Exceptions:
Source Code Description
DBLIB_CONNECT_BIND INVALID_EVENTNAME eventName cannot be blank or null.
DBLIB_CONNECT_BIND INVALID_CALLBACK If "callback function" is not declared or typeof() variable defined is not a "function".
DBLIB_CHANNEL_CONNECT INVALID_CHANNEL_TYPE_BINDING Invalid Event name. This binding is not allowed in channel.connect.

Unbind behavior varies depending on which parameters you provide it with. For example:

// Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind('eventName',handler);

// Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind('eventName');

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind();

// Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind('eventName',handler);

// Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind('eventName');

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind();
// Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind('eventName',handler);

// Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind('eventName');

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind();

// Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind('eventName',handler);

// Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind('eventName');

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind();
#  Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind("eventName",handler)

#  Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind("eventName")

# Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind()

#  Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName",handler)

#  Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName")

#  Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind()
// Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind("eventName",handler);

// Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind("eventName");

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind();

// Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName",handler);

// Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName");

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind();
//  Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind("eventName",eventHandler)

//  Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind("eventName")

// Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind()

//  Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName",eventHandler)

//  Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName")

//  Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind()
//  Remove just `handler` of the `event` in the subscribed/connected channel 
channelObject.unbind("eventName",eventHandler)

//  Remove all `handler` of the `event` in the subscribed/connected channel
channelObject.unbind("eventName")

// Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind()

//  Remove `handler` of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName",eventHandler)

//  Remove all handlers of the `event` for all events across all subscribed/connected channels
dbridge.channel.unbind("eventName")

//  Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind()

bind_all and unbind_all

bind_all and unbind_all work much like bind and unbind, but instead of only firing callbacks on a specific event, they fire callbacks on any event, and provide that event in the metadata to the handler along with the payload. bind_all and unbind_all is not available for connected_channel i.e. dbridge.channel.connect() object.

//  Binding to all channel events on channelObject  
try {
    channelObject.bind_all((payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to all channel events on dbridgeObject 

try {
    dbridge.channel.bind_all((payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}
//  Binding to all channel events on channelObject  
try {
    channelObject.bind_all((payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}

// Binding to all channel events on dbridgeObject 

try {
    dbridge.channel.bind_all((payload, metadata) => {
        console.log(payload, metadata);
    });
} catch(err){
     console.log(err.source, err.code, err.message);
}
# Binding to channel events on channelObject  
def eventFunction(payload ,  metadata):
  print(payload , metadata)

try:
    channelObject.bind_all('event',  eventFunction)
except dBError as e:
  print(e.code, e.source, e.message) 

# Binding to channel events on dbridgeObject 
try {
    dbridge.channel.bind_all('event', eventFunction)
except dBError as e:
  print(e.code, e.source, e.message) 
//  Binding to all channel events on channelObject  
try {
    Action<object , object> ichannelstatus;
    channelObject.bind_all(ichannelstatus =  (payload, metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}

// Binding to all channel events on dbridgeObject 

try {
    Action<object , object> ichannelstatus;
    dbridge.channel.bind_all(ichannelstatus =  (payload, metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
// Binding to channel events on channelObject  
channelObject.bind_all(event , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
      Log.i("event: ", message);
      Log.i("event: ", metadata);
    }
});
//  Binding to channel events on dbridgeObject
dbridge.channel.bind_all(event , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
      Log.i("event: ", message);
      Log.i("event: ", metadata);
    }
});
// Binding to channel events on channelObject
channelObject.bind_all(event , {  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata)
})

//  Binding to channel events on dbridgeObject
dbridge.channel.bind_all(event , {  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata)
})

Callback out parameter payload, metadata details are explained with each event below in this document.

Exceptions:
Source Code Description
DBLIB_CONNECT_BIND INVALID_CALLBACK If "callback function" is not declared or typeof() variable defined is not a "function".

unbind_all works similarly to unbind.

// Remove just `handler` across the channel 
channelObject.unbind_all(handler);

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all();

// Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(handler);

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all();
// Remove just `handler` across the channel 
channelObject.unbind_all(handler);

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all();

// Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(handler);

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all();
# Remove just `handler` across the channel 
channelObject.unbind_all(handler)

# Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all()

# Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(handler)

# Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all()
// Remove just `handler` across the channel 
channelObject.unbind_all(handler);

//Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all();

// Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(handler);

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all();
// Remove just `handler` across the channel 
channelObject.unbind_all(eventHandler)

// Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all()

// Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(eventHandler)

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all()
// Remove just `handler` across the channel 
channelObject.unbind_all(eventHandler)

// Remove all handlers for the all event in the subscribed/connected channel
channelObject.unbind_all()

// Remove `handler` across the subscribed/connected channels
dbridge.channel.unbind_all(eventHandler)

// Remove all handlers for all events across all subscribed/connected channels
dbridge.channel.unbind_all()

System events for channel object

There are a number of events which are triggered internally by the library, but can also be of use elsewhere. Below are the list of all events triggered by the library.

Below syntax is same for all system events.

//  Binding to systemevent on channelObject  
try {
    channelObject.bind('dbridges:subscribe.success', (payload, metadata) => {
        console.log( payload, metadata);
    });
} catch(err) {
     console.log(err.source, err.code, err.message);
}
//  Binding to systemevent on dbridgeObject  
try {
    dbridge.channel.bind('dbridges:subscribe.success', (payload, metadata) => {
        console.log( payload, metadata);
    });
} catch(err) {
     console.log(err.source, err.code, err.message);
}
//  Binding to systemevent on channelObject  
try {
    channelObject.bind('dbridges:subscribe.success', (payload, metadata) => {
        console.log( payload, metadata);
    });
} catch(err) {
     console.log(err.source, err.code, err.message);
}
//  Binding to systemevent on dbridgeObject  
try {
    dbridge.channel.bind('dbridges:subscribe.success', (payload, metadata) => {
        console.log( payload, metadata);
    });
} catch(err) {
     console.log(err.source, err.code, err.message);
}
# Binding to systemevent on channelObject  
def eventFunction(payload ,  metadata):
    print(payload , metadata)

try:
    channelObject.bind_all('dbridges:subscribe.success',  eventFunction)
except dBError as e:
    print(e.code, e.source, e.message) 

# Binding to systemevent on dbridgeObject 

try:
    dbridge.channel.bind_all('dbridges:subscribe.success', eventFunction)
except dBError as e:
    print(e.code, e.source, e.message) 
//  Binding to systemevent on channelObject  
Action<object,object> iChannelStatus;
try {
    channelObject.bind('dbridges:subscribe.success',  iChannelStatus = (object payload, object metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}

// Binding to systemevent on dbridgeObject 
try {
    dbridge.channel.bind('dbridges:subscribe.success', iChannelStatus = (object payload, object metadata) => {
        Console.WriteLine("{0} , {1} " , payload, metadata);
    });
} catch (dBError err) {
    Console.WriteLine("{0} ,  {1} , {2}" , err.source, err.code, err.message);
}
// Binding to channel events on channelObject  
channelObject.bind_all("dbridges:subscribe.success" , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
        Log.i("event: ", message);
        Log.i("event: ", metadata);
    }
});

//  Binding to channel events on dbridgeObject
dbridge.channel.bind_all("dbridges:subscribe.success" , new eventHandler() {
    @Override
    public void onEvent(Object message, metaData metadata) {
        Log.i("event: ", message);
        Log.i("event: ", metadata);
    }
});
// Binding to channel events on channelObject
channelObject.bind_all("dbridges:subscribe.success" , {  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata)
})

//  Binding to channel events on dbridgeObject
dbridge.channel.bind_all("dbridges:subscribe.success" ,{  (message: Any , metadata: Any ) in
    print("event: ", message)
    print("event: ", metadata)
})

dbridges:subscribe.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,          // (string) channelName to which subscription is done.
    "eventname": "dbridges:subscribe.success",// (string) eventName 
    "sourcesysid": "",                  // (string) Sender system identity, applicable only for presence or system channel.
    "sqnum": "1",                       // (string) user defined, sent during publish function.
    "sessionid": "",                    // (string) Sender sessionid, applicable only for presence or system channel.
    "intime": 1645554960732             // (string) EPOC time of the sender at time of publish.
}

dbridges:subscribe.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:subscribe.fail",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:channel.online

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:channel.online",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:channel.offline

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:channel.offline",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:channel.removed

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:channel.removed",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:unsubscribe.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:unsubscribe.success",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:unsubscribe.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:unsubscribe.fail",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:resubscribe.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:resubscribe.success",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:resubscribe.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:resubscribe.fail",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:participant.joined

This will be triggered only for presence (prs:) and system (sys:) channel subscription.

Callback parameters
payload: (dict)
{
  "sessionid": "ydR27s3Z92yQw7wjGY2lX",     // (string) Session id of the member who has subscribed/connected to channel
  "libtype": "nodejs",                      // (string) Library Lang of the member who has subscribed/connected to channel
  "sourceipv4": "0.0.0.0",                  // (string) IPv4 of the member who has subscribed/connected to channel
  "sourceipv6": "::1",                      // (string) Not Applicable in current version.
  "sysinfo": '{"sysid":"nameofcaller"}'     // (string) System Info of the member who has subscribed/connected to channel
}
metadata (dict):
{
    "channelname": "prs:channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:participant.joined",// (string) eventName 
    "sourcesysid": "nameofcaller",          // (string) Sys id of the member who has subscribed/connected to channel
    "sqnum": null,                          // (string) 
    "sessionid": "ydR27s3Z92yQw7wjGY2lX",   // (string) Session id of the member who has subscribed/connected to channel
    "intime": null                          // (string) 
}

dbridges:participant.left

This will be triggered only for presence (prs:) and system (sys:) channel subscription.

Callback parameters
payload: (dict)
{
  "sessionid": "ydR27s3Z92yQw7wjGY2lX",     // (string) Session id of the member who has subscribed/connected to channel
  "libtype": "nodejs",                      // (string) Library Lang of the member who has subscribed/connected to channel
  "sourceipv4": "0.0.0.0",                  // (string) IPv4 of the member who has subscribed/connected to channel
  "sourceipv6": "::1",                      // (string) Not Applicable in current version.
  "sysinfo": '{"sysid":"nameofcaller"}'     // (string) System Info of the member who has subscribed/connected to channel
}
metadata (dict):
{
    "channelname": "prs:channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:participant.left",// (string) eventName 
    "sourcesysid": "nameofcaller",          // (string) Sys id of the member who has subscribed/connected to channel
    "sqnum": null,                          // (string) 
    "sessionid": "ydR27s3Z92yQw7wjGY2lX",   // (string) Session id of the member who has subscribed/connected to channel
    "intime": null                          // (string) 
}

dbridges:connect.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:connect.success",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:connect.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:connect.fail",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:disconnect.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:disconnect.success",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:disconnect.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:disconnect.fail",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:reconnect.success

Callback parameters
payload:

null

metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:reconnect.success",// (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

dbridges:reconnect.fail

Callback parameters
payload: (dberror object)
{
    "source": "dberror.Source" ,        // (string) Error source, Refer dberror: for details
    "code": "dberror.Code",             // (string) Error code, Refer dberror: for details
    "message": ""                       // (string) Error message if applicable.
}
metadata (dict):
{
    "channelname": "channelName" ,      // (string) channelName to which subscription is done.
    "eventname": "dbridges:reconnect.fail",             // (string) eventName 
    "sourcesysid": "",                  // (string) 
    "sqnum": "",                        // (string) 
    "sessionid": "",                    // (string) 
    "intime":                           // (string) 
}

System events - payload (dberror object) - details:

Source Code Description
DBNET_CHANNEL_SUBSCRIBE ERR_FAIL_ERROR dataBrdiges network encountered error when subscribing to the channel.
DBNET_CHANNEL_SUBSCRIBE ERR_ACCESS_DENIED dBrdige network reported access violation with access_token function during subscription of this channel.
Verify if appKey has sufficient publish grants. Login to management portal. Select Edit Key option and check Allow key to publish messages to public channels is selected.
DBLIB_CHANNEL_SUBSCRIBE ACCESS_TOKEN dbridge.access_token function returned error.
DBNET_CHANNEL_UNSUBSCRIBE ERR_FAIL_ERROR dataBrdiges network encountered error when unsubscribing to the channel.
DBNET_CHANNEL_UNSUBSCRIBE ERR_ACCESS_DENIED dataBrdiges network reported access violation with access_token function during unsubscribing of this channel.
Verify if appKey has sufficient publish grants. Login to management portal. Select Edit Key option and check Allow key to publish messages to public channels is selected.
DBNET_CHANNEL_CONNECT ERR_FAIL_ERROR dataBrdiges network encountered error when subscribing to the channel.
DBNET_CHANNEL_CONNECT ERR_ACCESS_DENIED dataBrdiges network reported access violation with access_token function during subscription of this channel.
Verify if appKey has sufficient publish grants. Login to management portal. Select Edit Key option and check Allow key to publish messages to public channels is selected.
DBLIB_CHANNEL_CONNECT ACCESS_TOKEN dbridge.access_token function returned error.
DBLIB_CHANNEL_DISCONNECT ERR_FAIL_ERROR dataBrdiges network encountered error when unsubscribing to the channel..
DBLIB_CHANNEL_DISCONNECT ERR_ACCESS_DENIED dataBrdiges network reported access violation with access_token function during unsubscribing of this channel.
Verify if appKey has sufficient publish grants. Login to management portal. Select Edit Key option and check Allow key to publish messages to public channels is selected.