Signaling Events in Beebotte

Beebotte provides a signaling channel where user connection activity is streamed. The Signaling channel provides a real time stream of the following events:

  • connect event: when a user connects via Websocket (socketio) or MQTT.
  • disconnect event: when a user disconnects from Websocket (socketio) or MQTT.
  • subscribe event: when a user subscribes to a channel resource.
  • unsubscribe event: when a user unsubscribes from a channel resource.
  • join event: when a user subscribes to a presence channel.
  • leave event: when a user unsubscribes from a presence channel.

Signaling channels allow to:

  • monitor client activity from a central location
  • identify anomalous behaviour like frequent connections and disconnections
  • help detect compromised Tokens by comparing client IP addresses of connections to those of your legitimate devices (if this case, you can revoke compromised tokens)

The signaling channel makes it easy for clients to monitor their activity using a centralized private channel. All messages streamed to the signaling channel are transient: this means they will not be stored in Beebotte.

Signaling channel is like any other channel you can subscribe to with channel set to signaling (private-signaling when using WebSockets) and resource to any of the events listed above.

Beebotte considers signaling events as private resources that require explicit authentication to get subscribed to.

/* To subscribe to any signaling event */
bbt.subscribe({
  channel: 'private-signaling', //Note the 'private-' prefix
  resource: '*'
}, function (err, evt){
  /* Do something here */
});

/* To subscribe to a specific signaling event */
bbt.subscribe({
  channel: 'private-signaling', //Note the 'private-' prefix
  resource: 'connect'
}, function (err, evt) {
  /* will get here anytime a new connection is made */
  /* Do something here */
});

The callback function has two parameters, the first indicates an error if it's not null, while the second is a JSON object with the following format:

{
  "channel": "private-signaling",
  "resource": "event name",
  "ts": "timestamp is milliseconds since epoche",
  "data": {
    "protocol": "socketio or mqtt",
    "owner": "beebotte account owner username",
    "event": "event name, same as resource value",
    "clientid": "mqtt client id or websocket user id",
    "userid": "mqtt client id or websocket user id. Contains The same value as clientid",
    "sid": "websocket session id. For mqtt, it will be the same as clientid",
    "clientip": "IP address of the client connection",
    "ts": "timestamp is milliseconds since epoch",
    "channel": "channel name, NA for connect and disconnect events",
    "resource": "resource name, NA for connect and disconnect events",
    "topic": "the mqtt topic, will not be present for websocket connections",
    "sig": "signature to authorize subscribe and join events on websocket connections, will not be present for mqtt connections",
    "ttl": "for subscribe and join events will always be set to 0, ttl is reserved for future use",
    "read": "true or false: will only be received for subscribe and join events on websockets connections",
    "write": "true or false: will only be received for subscribe and join events on websockets connections"
  }
}

Sample Signaling messages:

// Example subscribe signaling event
{
  "channel": "private-signaling",
  "resource": "subscribe",
  "data": {
    "protocol": "socketio",
    "owner": "beebotte",
    "event": "subscribe",
    "clientid": "_e_j4YLLn5aw3ECXAMAC",
    "userid": "_e_j4YLLn5aw3ECXAMAC",
    "sid": "_e_j4YLLn5aw3ECXAMAC",
    "clientip": "::ffff:10.0.0.46",
    "ts": 1536445530643,
    "channel": "chat_demo",
    "resource": "chat_msg",
    "ttl": 0,
    "read": true,
    "write": true,
    "sig": "502bxxxxxxxxxxxxxxx9c1e:xfuxxxxxxxxxxxxxxxx3NPQ="
  }
}

// Example connect signaling event
{
  "channel": "private-signaling",
  "resource": "connect",
  "ts": 1536451073384,
  "data": {
    "protocol": "mqtt",
    "owner": "beebotte",
    "event": "connect",
    "clientid": "beebotte-aaaaaaaaaaaaaa",
    "userid": "beebotte-aaaaaaaaaaaaaa",
    "sid": "beebotte-aaaaaaaaaaaaaa",
    "clientip": "::ffff:10.0.0.46",
    "ts": 1536451073384,
    "channel": "NA",
    "resource": "NA"
  }
}