providers/core/core.websocket.js
function (cap, dispatchEvent, url, protocols, socket) {
  var WSImplementation = null,
    error;
  this.isNode = nodeStyle;
  if (typeof socket !== 'undefined') {
    WSImplementation = socket;
  } else if (WSHandle !== null) {
    WSImplementation = WSHandle;
  } else if (typeof WebSocket !== 'undefined') {
    WSImplementation = WebSocket;
  } else {
    console.error('Platform does not support WebSocket');
  }

  this.dispatchEvent = dispatchEvent;
  try {
    if (protocols) {
      this.websocket = new WSImplementation(url, protocols);
    } else {
      this.websocket = new WSImplementation(url);
    }
    this.websocket.binaryType = 'arraybuffer';
  } catch (e) {
    error = {};
    if (e instanceof SyntaxError) {
      error.errcode = 'SYNTAX';
    } else {
      error.errcode = e.name;
    }
    error.message = e.message;
    dispatchEvent('onError', error);
    return;
  }

  if (this.isNode) {
    this.websocket.on('message', this.onMessage.bind(this));
    this.websocket.on('open', this.onOpen.bind(this));
    // node.js websocket implementation not compliant
    this.websocket.on('close', this.onClose.bind(this, {
      code: 0,
      reason: 'UNKNOWN',
      wasClean: true
    }));
    this.websocket.on('error', this.onError.bind(this));
  } else {
    this.websocket.onopen = this.onOpen.bind(this);
    this.websocket.onclose = this.onClose.bind(this);
    this.websocket.onmessage = this.onMessage.bind(this);
    this.websocket.onerror = this.onError.bind(this);
  }
}
function (cap, dispatchEvent, url, protocols, socket) {
  var WSImplementation = null,
    error;
  this.isNode = nodeStyle;
  if (typeof socket !== 'undefined') {
    WSImplementation = socket;
  } else if (WSHandle !== null) {
    WSImplementation = WSHandle;
  } else if (typeof WebSocket !== 'undefined') {
    WSImplementation = WebSocket;
  } else {
    console.error('Platform does not support WebSocket');
  }

  this.dispatchEvent = dispatchEvent;
  try {
    if (protocols) {
      this.websocket = new WSImplementation(url, protocols);
    } else {
      this.websocket = new WSImplementation(url);
    }
    this.websocket.binaryType = 'arraybuffer';
  } catch (e) {
    error = {};
    if (e instanceof SyntaxError) {
      error.errcode = 'SYNTAX';
    } else {
      error.errcode = e.name;
    }
    error.message = e.message;
    dispatchEvent('onError', error);
    return;
  }

  if (this.isNode) {
    this.websocket.on('message', this.onMessage.bind(this));
    this.websocket.on('open', this.onOpen.bind(this));
    // node.js websocket implementation not compliant
    this.websocket.on('close', this.onClose.bind(this, {
      code: 0,
      reason: 'UNKNOWN',
      wasClean: true
    }));
    this.websocket.on('error', this.onError.bind(this));
  } else {
    this.websocket.onopen = this.onOpen.bind(this);
    this.websocket.onclose = this.onClose.bind(this);
    this.websocket.onmessage = this.onMessage.bind(this);
    this.websocket.onerror = this.onError.bind(this);
  }
}
function ( cap , dispatchEvent , url , protocols , socket ) { var WSImplementation = null , error ; this . isNode = nodeStyle ; if ( typeof socket !== 'undefined' ) { WSImplementation = socket ; } else if ( WSHandle !== null ) { WSImplementation = WSHandle ; } else if ( typeof WebSocket !== 'undefined' ) { WSImplementation = WebSocket ; } else { console . error ( 'Platform does not support WebSocket' ) ; } this . dispatchEvent = dispatchEvent ; try { if ( protocols ) { this . websocket = new WSImplementation ( url , protocols ) ; } else { this . websocket = new WSImplementation ( url ) ; } this . websocket . binaryType = 'arraybuffer' ; } catch ( e ) { error = { } ; if ( e instanceof SyntaxError ) { error . errcode = 'SYNTAX' ; } else { error . errcode = e . name ; } error . message = e . message ; dispatchEvent ( 'onError' , error ) ; return ; } if ( this . isNode ) { this . websocket . on ( 'message' , this . onMessage . bind ( this ) ) ; this . websocket . on ( 'open' , this . onOpen . bind ( this ) ) ; // node.js websocket implementation not compliant this . websocket . on ( 'close' , this . onClose . bind ( this , { code : 0 , reason : 'UNKNOWN' , wasClean : true } ) ) ; this . websocket . on ( 'error' , this . onError . bind ( this ) ) ; } else { this . websocket . onopen = this . onOpen . bind ( this ) ; this . websocket . onclose = this . onClose . bind ( this ) ; this . websocket . onmessage = this . onMessage . bind ( this ) ; this . websocket . onerror = this . onError . bind ( this ) ; } }
A WebSocket core provider

@param {Object} cap Capabilities for the provider
@param {Function} dispatchEvent Function to dispatch events.
@param {String} url The Remote URL to connect with.
@param {String[]} protocols SubProtocols to open.
@param {WebSocket?} socket An alternative socket class to use.
A WebSocket core provider