WS Test
by JQ Purfect
HTML
<div>Hello<div>
JavaScript
var WSRoot = {
CONSTANT_1: 1,
CONSTANT_2: 2,
/*get binaryType() {
return this.socket.binaryType;
},
set binaryType(binaryType) {
this.socket.binaryType = binaryType;
}*/
}
function WSObj(url) {
//WSRoot.call(this);
//this.prototype = Object.create(WSRoot);
//this.prototype.constructor = WSObj;
this.socket = new WebSocket(url);
/*Object.defineProperty(this, "binaryType",
{ get: function() {
return this.socket.binaryType;
},
set: function(binaryType) {
this.socket.binaryType = binaryType;
}});*/
}
WSObj.prototype = Object.create(WSRoot);
WSObj.prototype.constructor = WSObj;
Object.defineProperty(WSObj.prototype, "binaryType", {
get: function() {
return this.socket.binaryType;
},
set: function(binaryType) {
this.socket.binaryType = binaryType;
}});
WSObj.prototype.addEventListener =
function(type, listener, useCapture) {
this.socket.addEventListener(type, listener, useCapture);
console.log("this.CONSTANT_2: " + this.CONSTANT_2 + "<br/>");
console.log("this.get binaryType(): " + this.binaryType + "<br/>");
this.binaryType = "arraybuffer";
console.log("this.get binaryType(): " + this.binaryType + "<br/>");
};
WSObj.prototype.removeEventListener =
function(type, listener, useCapture) {
this.socket.removeEventListener(type, listener, useCapture);
};
WSObj.prototype.dispatchEvent =
function(event) {
this.socket.dispatchEvent(event);
};
//var wsObj = new WebSocket("ws://echo.websocket.org");
var wsObj = new WSObj("ws://echo.websocket.org");
wait();
function wait() {
console.log("wait() was called<br/>");
wsObj.addEventListener("open", onOpen, false);
wsObj.addEventListener("close", on2, false);
wsObj.addEventListener("error", on2, false);
wsObj.addEventListener("message", on2, false);
...