Comparing version 0.13.2 to 0.14.0
@@ -6,3 +6,3 @@ 'use strict'; | ||
var Events = _interopDefault(require('./Events')); | ||
var Client = _interopDefault(require('ws')); | ||
var Client = _interopDefault(require('isomorphic-ws')); | ||
@@ -19,2 +19,4 @@ function Endpoint (ws, booth) | ||
var buffer = []; | ||
if (booth) | ||
@@ -36,5 +38,12 @@ { | ||
function send (kind, data) | ||
function send (kind, data = '') | ||
{ | ||
endp.ws.send('@' + kind + ':' + data); | ||
if (buffer) | ||
{ | ||
buffer.push([ kind, data ]); | ||
} | ||
else if (endp.ws) | ||
{ | ||
endp.ws.send('@' + kind + ':' + data); | ||
} | ||
@@ -66,3 +75,5 @@ return endp | ||
{ | ||
ev('open', flush); | ||
ev('close', reconnect); | ||
ev('open', check_reconnect); | ||
} | ||
@@ -77,2 +88,3 @@ | ||
{ | ||
buffer = null; | ||
events.emit('@open', void 0, endp); | ||
@@ -82,2 +94,15 @@ } | ||
function flush () | ||
{ | ||
if (! buffer) return | ||
var bf = buffer; | ||
buffer = null; | ||
bf.forEach(pair => | ||
{ | ||
send(...pair); | ||
}); | ||
} | ||
function reconnect () | ||
@@ -87,2 +112,3 @@ { | ||
buffer = []; | ||
endp.ws = null; | ||
@@ -93,2 +119,14 @@ | ||
function check_reconnect () | ||
{ | ||
if (check_reconnect.already) | ||
{ | ||
events.emit('@reconnect', void 0, endp); | ||
} | ||
else | ||
{ | ||
check_reconnect.already = true; | ||
} | ||
} | ||
function close () | ||
@@ -101,2 +139,4 @@ { | ||
buffer = null; | ||
booth = null; | ||
@@ -103,0 +143,0 @@ endp = null; |
{ | ||
"name": "booth", | ||
"version": "0.13.2", | ||
"version": "0.14.0", | ||
"license": "ISC", | ||
@@ -29,3 +29,5 @@ "author": "Strider <strange.transistor@gmail.com>", | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"isomorphic-ws": "4" | ||
} | ||
} |
6859
2
8
236
+ Addedisomorphic-ws@4
+ Addedisomorphic-ws@4.0.1(transitive)