lib/transport/websocket/WebSocketTransport.js
function WebSocketTransport(config) {
  this.id = config && config.id || null;
  this.networkId = this.id || null;
  this['default'] = config && config['default'] || false;
  this.localShortcut = (config && config.localShortcut === false) ? false : true;
  this.reconnectDelay = config && config.reconnectDelay || 10000;

  this.httpTransport = config && config.httpTransport;

  this.url = config && config.url || null;
  this.server = null;

  if (this.url != null) {
    var urlParts = urlModule.parse(this.url);

    if (urlParts.protocol != 'ws:') throw new Error('Invalid protocol, "ws:" expected');
    if (this.url.indexOf(':id') == -1) throw new Error('":id" placeholder missing in url');

    this.address = urlParts.protocol + '//' + urlParts.host; // the url without path, for example 'ws://localhost:3000'
    this.ready = this._initServer(this.url);
  }
  else {
    this.address = null;
    this.ready = Promise.resolve(this);
  }

  this.agents = {}; // WebSocketConnections of all registered agents. The keys are the urls of the agents
}
function WebSocketTransport(config) {
  this.id = config && config.id || null;
  this.networkId = this.id || null;
  this['default'] = config && config['default'] || false;
  this.localShortcut = (config && config.localShortcut === false) ? false : true;
  this.reconnectDelay = config && config.reconnectDelay || 10000;

  this.httpTransport = config && config.httpTransport;

  this.url = config && config.url || null;
  this.server = null;

  if (this.url != null) {
    var urlParts = urlModule.parse(this.url);

    if (urlParts.protocol != 'ws:') throw new Error('Invalid protocol, "ws:" expected');
    if (this.url.indexOf(':id') == -1) throw new Error('":id" placeholder missing in url');

    this.address = urlParts.protocol + '//' + urlParts.host; // the url without path, for example 'ws://localhost:3000'
    this.ready = this._initServer(this.url);
  }
  else {
    this.address = null;
    this.ready = Promise.resolve(this);
  }

  this.agents = {}; // WebSocketConnections of all registered agents. The keys are the urls of the agents
}
function WebSocketTransport ( config ) { this . id = config && config . id || null ; this . networkId = this . id || null ; this [ 'default' ] = config && config [ 'default' ] || false ; this . localShortcut = ( config && config . localShortcut === false ) ? false : true ; this . reconnectDelay = config && config . reconnectDelay || 10000 ; this . httpTransport = config && config . httpTransport ; this . url = config && config . url || null ; this . server = null ; if ( this . url != null ) { var urlParts = urlModule . parse ( this . url ) ; if ( urlParts . protocol != 'ws:' ) throw new Error ( 'Invalid protocol, "ws:" expected' ) ; if ( this . url . indexOf ( ':id' ) == - 1 ) throw new Error ( '":id" placeholder missing in url' ) ; this . address = urlParts . protocol + '//' + urlParts . host ; // the url without path, for example 'ws://localhost:3000' this . ready = this . _initServer ( this . url ) ; } else { this . address = null ; this . ready = Promise . resolve ( this ) ; } this . agents = { } ; // WebSocketConnections of all registered agents. The keys are the urls of the agents }
Create a web socket transport.
@param {Object} config         Config can contain the following properties:
- `id: string`. Optional
- `default: boolean`. Optional
- `url: string`. Optional. If provided,
A WebSocket server is started on given
url.
- `localShortcut: boolean`. Optional. If true
(default), messages to local agents are not
send via WebSocket but delivered immediately
- `reconnectDelay: number` Optional. Delay in
milliseconds for reconnecting a broken
connection. 10000 ms by default. Connections
are only automatically reconnected after
there has been an established connection.
@constructor
Create a web socket transport .