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
|
var socket = function(){
var socket = {}
socket.connect: function () {
if (this.socket) return;
var socketPath = window.location.origin + '/' + posthang.room.subdomain
this.socket = io(socketPath);
// this.socket.on('connect', function(){ console.log(new Date(), "connected")});
this.socket.on('ready', $.proxy(this.socketReady, this));
this.socket.on('error', $.proxy(this.socketError, this));
this.socket.on('connect', $.proxy(this.socketConnected, this));
this.socket.on('reconnect', $.proxy(this.socketReconnected, this));
this.socket.on('disconnect', $.proxy(this.disconnected, this))
this.socket.on('users', $.proxy(this.updateUsers, this));
this.socket.on('message', $.proxy(this.chatView.append, this.chatView));
this.socket.on('info', $.proxy(this.chatView.appendInfo, this.chatView));
this.socket.on('mediaId', $.proxy(this.mediaView.updateMediaId, this.mediaView));
this.socket.on('messageId', $.proxy(this.chatView.updateMessageId, this.chatView));
this.socket.on('roomDeleted', $.proxy(this.roomDeleted, this));
this.socket.on('userBanned', $.proxy(this.userBanned, this));
this.socket.on('fave', $.proxy(this.faveView.faved, this.faveView))
$(window).on("scroll", $.proxy(this.didScroll, this))
$(window).on("focus", $.proxy(this.focus, this))
$(window).on("blur", $.proxy(this.blur, this))
this.chatView.fetchMessages();
this.mediaView.fetchMedia();
},
socketReady: function (obj) {
console.log(new Date(), "ready")
// presumably we might have reconnected?
if (this.socketIsReady) {
this.chatView.fetchAndDedupe()
}
else {
this.socketIsReady = true
this.checkIfLoaded()
}
},
socketError: function (a,b,c){
console.log(new Date(), "error", a, b, c)
},
socketConnected: function (){
console.log(new Date(), "connected")
},
socketReconnected: function (){
console.log(new Date(), "reconnected")
},
socketDisconnected: function (){
this.chatView.appendInfo({ content: "Disconnected." })
}
}
}
|