npmtest-jssip (v0.0.1)

Code coverage report for node-npmtest-jssip/node_modules/jssip/lib/Socket.js

Statements: 23.33% (7 / 30)      Branches: 0% (0 / 12)      Functions: 0% (0 / 3)      Lines: 23.33% (7 / 30)      Ignored: none     

All files » node-npmtest-jssip/node_modules/jssip/lib/ » Socket.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 791                                                 1 1 1 1   1   1                                                                                            
module.exports = Socket;
 
/**
 * Interface documentation: http://jssip.net/documentation/$last_version/api/socket/
 *
 * interface Socket {
 *  attribute String via_transport
 *  attribute String url
 *  attribute String sip_uri
 *
 *  method connect();
 *  method disconnect();
 *  method send(data);
 *
 *  attribute EventHandler onconnect
 *  attribute EventHandler ondisconnect
 *  attribute EventHandler ondata
 * }
 *
 */
 
 
/**
 * Dependencies.
 */
var Utils = require('./Utils');
var Grammar = require('./Grammar');
var debugerror = require('debug')('JsSIP:ERROR:Socket');
debugerror.log = console.warn.bind(console);
 
function Socket() {}
 
Socket.isSocket = function(socket) {
  // Ignore if an array is given
  if (Array.isArray(socket)) {
    return false;
  }
 
  if (typeof socket === 'undefined') {
    debugerror('undefined JsSIP.Socket instance');
    return false;
  }
 
  // Check Properties
  try {
    if (!Utils.isString(socket.url)) {
      debugerror('missing or invalid JsSIP.Socket url property');
      throw new Error();
    }
 
    if (!Utils.isString(socket.via_transport)) {
      debugerror('missing or invalid JsSIP.Socket via_transport property');
      throw new Error();
    }
 
    if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
      debugerror('missing or invalid JsSIP.Socket sip_uri property');
      throw new Error();
    }
  } catch(e) {
    return false;
  }
 
  // Check Methods
  try {
    ['connect', 'disconnect', 'send'].forEach(function(method) {
      if (!Utils.isFunction(socket[method])) {
        debugerror('missing or invalid JsSIP.Socket method: ' + method);
        throw new Error();
      }
    });
  } catch(e) {
    return false;
  }
 
  return true;
};