1 APE.Transport.WebSocket = new Class({
6 initialize: function(ape) {
12 this.ws = new WebSocket( (this.ape.options.secure ? 'wss' : 'ws') + '://' + this.ape.options.frequency + '.' + this.ape.options.server + '/' + this.ape.options.transport +'/');
13 this.connRunning = true;
14 this.ws.onmessage = this.readWs.bind(this);
15 this.ws.onopen = this.openWs.bind(this);
16 this.ws.onclose = this.closeWs.bind(this);
17 this.ws.onerror = this.errorWs.bind(this);
20 readWs: function(evt) {
21 this.ape.parseResponse(evt.data, this.callback);
26 if (this.stack.length > 0) {
27 for (var i = 0; i < this.stack.length; i++) this.send(this.stack[i].q, this.stack[i].options);
28 this.stack.length = 0;
33 this.connRunning = false;
37 this.connRunning = false;
40 send: function(queryString, options) {
41 if (this.ws.readyState == 1) {
42 if (options.requestCallback) this.callback = options.requestCallback;
43 this.ws.send(queryString);
44 } else {//ws not connect, stack request
45 this.stack.push({'q': queryString, 'options': options});
50 return this.connRunning;
59 APE.Transport.WebSocket.browserSupport = function() {
60 if ('WebSocket' in window) return true;
61 else return 1;//No websocket support switch to XHRStreaming