lib/client/index.js
function RpcTunnel(url, sslSettings) {
		var self = this;
		if (! (this instanceof RpcTunnel)) {
			return new RpcTunnel(url, sslSettings);
		}

		this.transports = {};

		if (!url) {
			throw new Error('Missing url parameter, which should be either a URL or client transport.')
		}

		var transport = null;

		if (typeof url === 'string') {
			var HttpTransport = require('./transports/http');
			transport = new HttpTransport(url, sslSettings);

			// As a special case when adding an HTTP transport, set up the WebSocket transport
			// It is lazy-loaded, so the WebSocket connection is only created if/when the transport is used
			Object.defineProperty(this.transports, 'ws', {
				enumerable: true, // JSWS-47 ensure we can discover the ws transport
				get: (function () {
					var webSocketTransport;
					var WebSocketTransport = require('./transports/ws');
					return function () {
						if (!webSocketTransport) {
							webSocketTransport = new WebSocketTransport(url, sslSettings);
							webSocketTransport.on('event', function (e) {
								self.emit('event', e);
							});
						}
						return webSocketTransport;
					};
				}())
			});
		} else {
			transport = url;
			transport.on('event', function (e) {
				self.emit('event', e);
			});
		}

		transport.on('error', function(err) {
			self.emit('error', err);
		});

		this.url = transport.url;
		this.transports[transport.name] = transport;
	}
function RpcTunnel(url, sslSettings) {
		var self = this;
		if (! (this instanceof RpcTunnel)) {
			return new RpcTunnel(url, sslSettings);
		}

		this.transports = {};

		if (!url) {
			throw new Error('Missing url parameter, which should be either a URL or client transport.')
		}

		var transport = null;

		if (typeof url === 'string') {
			var HttpTransport = require('./transports/http');
			transport = new HttpTransport(url, sslSettings);

			// As a special case when adding an HTTP transport, set up the WebSocket transport
			// It is lazy-loaded, so the WebSocket connection is only created if/when the transport is used
			Object.defineProperty(this.transports, 'ws', {
				enumerable: true, // JSWS-47 ensure we can discover the ws transport
				get: (function () {
					var webSocketTransport;
					var WebSocketTransport = require('./transports/ws');
					return function () {
						if (!webSocketTransport) {
							webSocketTransport = new WebSocketTransport(url, sslSettings);
							webSocketTransport.on('event', function (e) {
								self.emit('event', e);
							});
						}
						return webSocketTransport;
					};
				}())
			});
		} else {
			transport = url;
			transport.on('event', function (e) {
				self.emit('event', e);
			});
		}

		transport.on('error', function(err) {
			self.emit('error', err);
		});

		this.url = transport.url;
		this.transports[transport.name] = transport;
	}
function RpcTunnel ( url , sslSettings ) { var self = this ; if ( ! ( this instanceof RpcTunnel ) ) { return new RpcTunnel ( url , sslSettings ) ; } this . transports = { } ; if ( ! url ) { throw new Error ( 'Missing url parameter, which should be either a URL or client transport.' ) } var transport = null ; if ( typeof url === 'string' ) { var HttpTransport = require ( './transports/http' ) ; transport = new HttpTransport ( url , sslSettings ) ; // As a special case when adding an HTTP transport, set up the WebSocket transport // It is lazy-loaded, so the WebSocket connection is only created if/when the transport is used Object . defineProperty ( this . transports , 'ws' , { enumerable : true , // JSWS-47 ensure we can discover the ws transport get : ( function ( ) { var webSocketTransport ; var WebSocketTransport = require ( './transports/ws' ) ; return function ( ) { if ( ! webSocketTransport ) { webSocketTransport = new WebSocketTransport ( url , sslSettings ) ; webSocketTransport . on ( 'event' , function ( e ) { self . emit ( 'event' , e ) ; } ) ; } return webSocketTransport ; } ; } ( ) ) } ) ; } else { transport = url ; transport . on ( 'event' , function ( e ) { self . emit ( 'event' , e ) ; } ) ; } transport . on ( 'error' , function ( err ) { self . emit ( 'error' , err ) ; } ) ; this . url = transport . url ; this . transports [ transport . name ] = transport ; }
Client RPC tunnel
Client RPC tunnel