/* Goal having something like: wsrpc.Connect("/ws"); wsrpc.Connect("ws://127.0.0.1/ws"); obj = { method1:function() { //Hello } } wsrpc.Export(obj); */ function WsRpc() { var ctx = this this._requests = {} this.connect = function(loc) { var ws = this.ws = new WebSocket(loc) ws.onopen = function() { ctx._requests = {} ctx.connected = true; if(ctx.onopen != undefined) { ctx.onopen(ctx) } } ws.onmessage = function(evt) { //console.log("RCV:",evt.data) var obj = JSON.parse(evt.data) var arrObj = [].concat(obj); // if object add, if array concat for( var i = 0; i