diff options
Diffstat (limited to 'public/js/lib/socket.js')
| -rw-r--r-- | public/js/lib/socket.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/public/js/lib/socket.js b/public/js/lib/socket.js new file mode 100644 index 0000000..4fd11a5 --- /dev/null +++ b/public/js/lib/socket.js @@ -0,0 +1,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." }) + } + } +}
\ No newline at end of file |
