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
|
var ws = function(){
var ws = {}
var ready = false
var socket
ws.connect = function () {
if (socket) return;
var path_name = window.location.pathname.replace(/\/$/,"").split("/")
var path = window.location.origin + '/' + path_name[path_name.length-1]
ws.socket = io(path)
ws.socket.on('ready', ws.ready)
ws.socket.on('error', ws.error)
ws.socket.on('connect', ws.connected)
ws.socket.on('reconnect', ws.reconnected)
ws.socket.on('disconnect', ws.disconnected)
}
ws.ready = function (data) {
console.log(new Date(), "ready")
// presumably we might have reconnected?
if (ready) {
}
else {
ready = true
ws.checkIfLoaded()
}
}
ws.error = function (a,b,c){
console.log(new Date(), "error", a, b, c)
}
ws.connected = function (){
console.log(new Date(), "connected")
}
ws.reconnected = function (){
console.log(new Date(), "reconnected")
}
ws.disconnected = function (){
console.log(new Date(), "disconnected")
}
}
|