Git Repository Public Repository

namibia

URLs

Copy to Clipboard
 
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
APE.Transport.WebSocket = new Class({

	stack: [],
	connRunning: false,

	initialize: function(ape) {
		this.ape = ape;
		this.initWs();
	},

	initWs: function() {
		this.ws = new WebSocket( (this.ape.options.secure ? 'wss' : 'ws') + '://' + this.ape.options.frequency + '.' + this.ape.options.server + '/' + this.ape.options.transport +'/');
		this.connRunning = true;
		this.ws.onmessage = this.readWs.bind(this);
		this.ws.onopen = this.openWs.bind(this);
		this.ws.onclose = this.closeWs.bind(this);
		this.ws.onerror = this.errorWs.bind(this);
	},

	readWs: function(evt) {
		this.ape.parseResponse(evt.data, this.callback);
		this.callback = null;
	},

	openWs: function() {
		if (this.stack.length > 0) {
			for (var i = 0; i < this.stack.length; i++) this.send(this.stack[i].q, this.stack[i].options);
			this.stack.length = 0;
		}
	},

	closeWs: function() {
		this.connRunning = false;
	},

	errorWs: function() {
		this.connRunning = false;
	},

	send: function(queryString, options) {
		if (this.ws.readyState == 1) {
			if (options.requestCallback) this.callback = options.requestCallback;
			this.ws.send(queryString);
		} else {//ws not connect, stack request
			this.stack.push({'q': queryString, 'options': options});
		}
	},

	running: function() {
		return this.connRunning;
	},

	cancel: function() {
		this.ws.close();
	}

});

APE.Transport.WebSocket.browserSupport = function() {
	if ('WebSocket' in window) return true;
	else return 1;//No websocket support switch to XHRStreaming
}

Commits for namibiapublic/ape-source/Transport/Transport.WebSocket.js

Diff revisions: vs.
Revision Author Commited Message
df0489 ... Mark Fri 14 Oct, 2016 10:01:00 +0000

initial commit