summaryrefslogtreecommitdiff
path: root/public/js/lib
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-05 12:49:58 -0400
committerJules Laplace <jules@okfoc.us>2015-08-05 12:49:58 -0400
commit21e31e46ff167ede7cb5ad4452cbd406236bc83d (patch)
tree385e85fa1b37468d2fd3a06fc9cbcc5e5efd776b /public/js/lib
parent2f63919b30583b440727b250c2d0503b24f3d666 (diff)
welp
Diffstat (limited to 'public/js/lib')
-rw-r--r--public/js/lib/ws.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/public/js/lib/ws.js b/public/js/lib/ws.js
new file mode 100644
index 0000000..4326585
--- /dev/null
+++ b/public/js/lib/ws.js
@@ -0,0 +1,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")
+ }
+} \ No newline at end of file