summaryrefslogtreecommitdiff
path: root/public/js/lib/ws.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-04 23:54:12 -0400
committerJules Laplace <jules@okfoc.us>2015-08-04 23:54:12 -0400
commit18648921f75a7c458cf0c951c249b28a48f08a6b (patch)
tree4842285de287da85b820ed878b363175293e34f7 /public/js/lib/ws.js
parent82f90cffd91b0a68e9e60a41192d7e775f523843 (diff)
ws shit
Diffstat (limited to 'public/js/lib/ws.js')
-rw-r--r--public/js/lib/ws.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/public/js/lib/ws.js b/public/js/lib/ws.js
new file mode 100644
index 0000000..37a8248
--- /dev/null
+++ b/public/js/lib/ws.js
@@ -0,0 +1,43 @@
+var ws = function(){
+ var ws = {}
+ var socket, socketIsReady
+ ws.connect = function () {
+ if (this.socket) return;
+ var socketPath = window.location.origin + '/' + posthang.room.subdomain
+
+ ws.socket = socket = io(socketPath)
+ // this.socket.on('connect', function(){ console.log(new Date(), "connected")})
+ socket.on('ready', ws.ready)
+ socket.on('error', ws.error)
+ socket.on('connect', ws.connected)
+ socket.on('reconnect', ws.reconnected)
+ socket.on('disconnect', ws.disconnected)
+ }
+
+ ws.ready = function (obj) {
+ console.log(new Date(), "ready")
+
+ // presumably we might have reconnected?
+ if (socketIsReady) {
+ this.chatView.fetchAndDedupe()
+ }
+ else {
+ socketIsReady = true
+ this.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")
+ // this.chatView.appendInfo({ content: "Disconnected." })
+ }
+} \ No newline at end of file