var jrpc = require('jrpc-schema')
var Websocket = require('ws');

//Create our connection
function init(host, port) {
	var queue = [];
	var running = 0;
	var closing = false;

	var connection_id = 'ws://'+host+':'+port+'/jsonrpc';
	var connection;

	jrpc.onId('schemarequest', connection_id, gotSchema);

	var ws = new Websocket(connection_id);

	//Bind our incoming messages to our jrpc handler
	ws.on('message',  function(msg) {
		if(typeof msg === 'string' && msg.length > 0) {
			jrpc.handleResponse(connection_id, msg);
		}
	});

	ws.on('open', getSchema);

	//Return our new connection object
	return {
		on: on,
		run: callMethod,
		close: close
	};

	/**********************
		Methods we need
	**********************/

	//Return a function to run our method
	function callMethod(method) {
		//Run or queue the message
		return function runMethod() {
			var params = Array.prototype.slice.call(arguments);

			if(typeof params[params.length-1] === 'function') {
				params[params.length-1] = wrapCallback(params[params.length-1]);
			}

			if(connection) {
				connection[method].apply(connection, params);
			} else {
				queue.push({
					method: method,
					params: params
				});
			}
		}
	}

	//Execute all pending requests
	function executeQueue() {
		var method;

		if(connection) {
			while(queue.length > 0) {
				method = queue.shift();
				connection.methods[method.method].apply(connection, method.params);
			}
		}
	}

	function close() {
		if(running !== 0) {
			closing = true;
		} else if(ws) {
			ws.close();
		}
	}

	function wrapCallback(cb) {
		running++;

		return function() {
			cb.apply(null, arguments);

			running--;
			if(closing) {
				close();
			}
		}
	}

	//Get our schema once we have a connection
	function getSchema() {
		var json = jrpc.methodToJSON('JSONRPC.Introspect', [], 'schemarequest');
		ws.send(json);
	}

	//Generate our jrpc methods from our schema
	function gotSchema(schema) {
		connection = jrpc.parse(schema, ws.send.bind(ws));
		executeQueue();
	}

	//Allow us to bind to a notification
	function on(notification, cb) {
		jrpc.onNotification(notification, connection_id, cb);
	}
}

module.exports = init;
@@ -399,20 +399,17 @@
 s.on
-('
 message
-',
  
+=
  fun
@@ -414,19 +414,20 @@
 unction(
-msg
+data
 ) %7B%0A%09%09if
@@ -431,48 +431,25 @@
 %09if(
-typeof msg === 'string' && msg
+data.data
 .length
- %3E 
+%3E
 0) %7B
@@ -491,11 +491,17 @@
 id, 
-msg
+data.data
 );%0A%09
@@ -509,18 +509,16 @@
 %7D%0A%09%7D
-);
 %0A%0A%09ws.on
 ('op
@@ -517,16 +517,14 @@
 s.on
-('
 open
-',
+ =
  get
@@ -525,25 +525,24 @@
  = getSchema
-)
 ;%0A%0A%09//Return

Use a websockets in a way that works in a browser