stream-url
Advanced tools
Comparing version 0.0.10 to 0.0.12
{ | ||
"name": "stream-url", | ||
"version": "0.0.10", | ||
"version": "0.0.12", | ||
"homepage": "http://github.com/gritzko/stream-url", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -30,2 +30,5 @@ Stream URLs | ||
technical details and make it easily pluggable. | ||
Just replace `loopback://random_key` for `ws://myserver.com` or | ||
`tcp://10.10.10.10:1234` and the component/micro-service now works in | ||
a different setting. | ||
@@ -35,7 +38,9 @@ ## API | ||
* `listen(url [,options] [,callback])` start a server (stream factory) | ||
listening at the `url`, using `options`. Invoke `callback` when | ||
ready. The server will emit a `connection` event for every new | ||
listening at the `url`, using `options`. Invoke `callback(err, | ||
server)` when ready or failed. | ||
The server will emit a `connection` event for every new | ||
incoming connection/stream. | ||
* `connect(url [,options] [,callback])` connect to a server at (create | ||
a stream to) `url`. Invoke `callback` once ready to write. | ||
a stream to) `url`. Invoke `callback(err, stream)` once ready to | ||
write or failed to connect. | ||
The stream will emit all the [usual events][stream]: | ||
@@ -50,4 +55,20 @@ `data`, `end`, `error`. | ||
All "real" protocols are defined in separate packages, as those | ||
introduce non-trivial dependencies. | ||
- [x] [server-side WebSocket][su-ws] | ||
- [x] [TCP][su-node] | ||
- [ ] [HTTP][su-node] | ||
- [ ] [filesystem sockets][su-node] | ||
- [ ] [stdin/stdout][su-node] | ||
- [ ] [client-side WebSocket][su-bro] | ||
- [ ] [postMessage][su-bro] | ||
- [ ] [WebStorage][su-bro] | ||
- [x] [loopback streams][swarm-bat] | ||
[go]: https://gobyexample.com/channels | ||
[stream]: https://iojs.org/api/stream.html | ||
[test]: test/01_connect_listen.js | ||
[su-ws]: https://github.com/gritzko/stream-url-ws | ||
[su-node]: https://github.com/gritzko/stream-url-node | ||
[su-bro]: https://github.com/gritzko/stream-url-browser | ||
[swarm-bat]: https://github.com/gritzko/swarm |
@@ -20,2 +20,15 @@ "use strict"; | ||
ZeroStream.prototype.drainQueue = function () { | ||
try { | ||
while (this.data.length && this.on_data) { | ||
this.on_data(this.data.shift()); | ||
} | ||
} catch (ex) { | ||
console.error(ex.stack); | ||
if (this.pair.on_error) { | ||
this.pair.on_error(ex.message); | ||
} | ||
} | ||
}; | ||
ZeroStream.prototype.on = function (event, callback) { | ||
@@ -25,11 +38,4 @@ switch (event) { | ||
this.on_data = callback; | ||
try { | ||
while (this.data.length) { // fake buffering | ||
callback(this.data.shift()); | ||
} | ||
} catch (ex) { | ||
console.error(ex); | ||
if (this.pair.on_error) { | ||
this.pair.on_error(ex.message); | ||
} | ||
if (this.data.length) { | ||
setTimeout(this.drain_queue.bind(this), 1); | ||
} | ||
@@ -51,3 +57,3 @@ break; | ||
} catch (ex) { | ||
console.error(ex); | ||
console.error(ex.stack); | ||
if (this.on_error) { | ||
@@ -54,0 +60,0 @@ this.on_error(ex.message); |
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
13456
283
72