websocket-stream
Advanced tools
Comparing version 1.1.0 to 1.1.1
28
index.js
@@ -10,3 +10,3 @@ var through = require('through2') | ||
var proxy = through(socketWrite, socketEnd) | ||
// use existing WebSocket object that was passed in | ||
@@ -20,3 +20,3 @@ if (typeof target === 'object') { | ||
} | ||
// was already open when passed in | ||
@@ -28,4 +28,4 @@ if (socket.readyState === 1) { | ||
socket.addEventListener("open", onready) | ||
} | ||
} | ||
stream.socket = socket | ||
@@ -36,3 +36,5 @@ | ||
socket.addEventListener("message", onmessage) | ||
proxy.destroy = destroy; | ||
function socketWrite(chunk, enc, next) { | ||
@@ -42,3 +44,3 @@ socket.send(chunk) | ||
} | ||
function socketEnd(done) { | ||
@@ -48,3 +50,3 @@ socket.close() | ||
} | ||
function onready() { | ||
@@ -55,11 +57,11 @@ stream.setReadable(proxy) | ||
} | ||
function onclose() { | ||
stream.destroy() | ||
} | ||
function onerror(err) { | ||
stream.destroy(err) | ||
} | ||
function onmessage(event) { | ||
@@ -70,4 +72,8 @@ var data = event.data | ||
} | ||
function destroy() { | ||
socket.close() | ||
} | ||
return stream | ||
} |
{ | ||
"name": "websocket-stream", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Use websockets with the node streams API. Works in browser and node", | ||
@@ -5,0 +5,0 @@ "scripts": { |
20
test.js
@@ -74,1 +74,21 @@ var test = require('tape') | ||
}); | ||
test('destroy', function(t) { | ||
t.plan(1) | ||
echo.start(function() { | ||
var client = websocket(echo.url, echo.options) | ||
client.on('close', function() { | ||
echo.stop(function() { | ||
t.pass('destroyed') | ||
}) | ||
}) | ||
setTimeout(function() { | ||
client.destroy(); | ||
}, 200); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8692
181