diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-04 11:45:16 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-04 11:45:16 -0400 |
| commit | 0b47720bad6a9c3b3447da97a89b91a1f8ab7d71 (patch) | |
| tree | dedc9f331618eb656a4148b8009e766558de8028 | |
| parent | 1a882d4adf6307dfbd764ae6aaf1a62a724851f1 (diff) | |
stub in socket from posthang
| -rw-r--r-- | public/js/lib/chat.js | 4 | ||||
| -rw-r--r-- | public/js/lib/socket.js | 59 |
2 files changed, 63 insertions, 0 deletions
diff --git a/public/js/lib/chat.js b/public/js/lib/chat.js index 946954b..6c227eb 100644 --- a/public/js/lib/chat.js +++ b/public/js/lib/chat.js @@ -18,6 +18,10 @@ var ChatView = View.extend({ }, send: function(){ + var msg = {} + msg.room = room.name() + msg.msg = + // app.socket.send("message", msg) }, empty: function(){ 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 |
