var mDelegateCommon = { socketConstruct: function(delegate, _url) { var url = '' + _url; log('socketConstruct', url); var jsWebSocket = new WebSocket(url); jsWebSocket.javaDelegate = delegate; jsWebSocket.onopen = function() { log("socket.onOpen", "->",this.javaDelegate); if (this.javaDelegate) this.javaDelegate.onEvent("onOpen"); }; jsWebSocket.onclose = function() { log("socket.onClose", "->",this.javaDelegate); if (this.javaDelegate) this.javaDelegate.onEvent("onClose"); }; jsWebSocket.onerror = function() { log("socket.onError", "->",this.javaDelegate); if (this.javaDelegate) this.javaDelegate.onEvent("onError"); }; jsWebSocket.onmessage = function(socketResponse) { log("socket.onMessage", socketResponse.data, "->",this.javaDelegate); var data = '' + socketResponse.data; if (this.javaDelegate) this.javaDelegate.onMessage(data); }; return jsWebSocket; }, socketSend: function(socket, message) { log("socketSend:", socket, message); socket.send(message); }, socketClose: function(socket) { log("socketClose:", socket); socket.javaDelegate = null; }, //-------------------------------------------------------------------------- executeURL: function(action, url, headers, binaryInput, binaryOutput, contents, callback) { // http://www.html5rocks.com/en/tutorials/file/xhr2/ // http://miskun.com/javascript/binary-file-loading-in-javascript/ log("delegate.executeURL ", action, url, headers, binaryOutput, binaryOutput, contents ? contents.length : 0); var disableWrite = false; if (disableWrite && (action == "PUT" || contents!=null)) { callback.invoke(null); return; } var req = new XMLHttpRequest(); req.open(action, url, true); req.timeout = 5000; if (headers != null) { for (var i=0; i