UBNotifierWSProtocol

UBNotifierWSProtocol

WebSocket connection to UnityBase server using ubNotifier protocol. The property supported indicate ubNotifier protocol is supported by server. Class mixes an EventEmitter. After got a command from a server the event with command code is fired.

The event flow are:

  • just after webSocket connection is established connected event are fired, when
  • after server accept (verify a user credential) accepted are fired - here you can got a connectionID of a current connection
  • next is a series of protocol events ( test_command for example )
  • in case of protocol error error are fired
  • when WebSocket connection are closed disconnected event are fired

You do not need to connect or reconnect a WebSocket manually - UBNotifierWSProtocol recreate a WebSocket automatically just after corresponding UBConnection fires a authorized event.

For adminUI instance of this class is accessible from $App.ubNotifier just after $App.launch

Usage sample:

 // Server side
 var notifier = UB.getWSNotifier();
 if (notifier) {
     notifier.broadcast('test_command', {name: 'Homer', like: 'donuts'});
 }

 // Client side
 // Will output 'Homer like donuts' after got a `test_command` from server
 $App.ubNotifier.on('test_command', function(params}{
     console.debug(params.name, 'like', params.like)
 }

Constructor

new UBNotifierWSProtocol(connection)

Arguments:
  1. connection (UBConnection)  Warning - only one instance of UBNotifierWSProtocol for a connection is valid.
Mixes In:

Members

supported: boolean

Indicate ubNotifier protocol is supported by server. If not supported all calls to send() will be ignored.

Methods

sendCommand(command, params)

Sand a command to server

  • if WS connection is not accepted yet will buffer the commands and send it just after connection is accepted
  • if ubNotifier protocol not supported by server will do nothing
Arguments:
  1. command (string)
  2. params (*)

listenerCount(emitter, type)Number

Return the number of listeners for a given event.
Arguments:
  1. emitter (EventEmitter)
  2. type (String)
Mixes In: