Permalink
Browse files

first

  • Loading branch information...
1 parent c5594c2 commit dcf038062afcab4c97793603f80b245de8cfb033 @Raynos committed Aug 4, 2012
Showing with 192 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +19 −0 LICENCE
  3. +48 −0 README.md
  4. +83 −0 browser.js
  5. +10 −0 example/client.js
  6. +28 −0 example/server.js
  7. +1 −0 index.js
View
@@ -0,0 +1,3 @@
+node_modules
+*.log
+*.err
View
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -0,0 +1,48 @@
+# boot
+
+An automatic reconnect mux-demux-shoe
+
+The mdm connection you get from shoe will magically handle reconnection
+logic for you under the hood. You just play with streams
+
+## Client Example
+
+ var shoe = require('../browser.js')
+ , mdm = shoe("/shoe")
+
+ var one = window.one = mdm.createStream("one")
+
+ one.on("data", function (data) {
+ console.log("message", data)
+ })
+
+ one.write("hello world")
+
+## Server Example
+
+ var shoe = require("..")
+ , through = require("through")
+ , echoStream = through()
+
+ var sock = shoe(function (stream) {
+ // stream from MuxDemux with the meta property set
+ if (stream.meta === "one") {
+ stream.on("data", console.log.bind(console))
+ stream.pipe(echoStream).pipe(stream)
+ }
+ })
+
+ sock.install(server, "/shoe")
+
+## Installation
+
+`npm install boot`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+ [1]: https://secure.travis-ci.org/Raynos/boot.png
+ [2]: http://travis-ci.org/Raynos/boot
View
@@ -0,0 +1,83 @@
+var shoe = require("mux-demux-shoe")
+ , through = require("through")
+ , PauseStream = require("pause-stream")
+ , es = require("event-stream")
+
+module.exports = shoeProxy
+
+function shoeProxy(uri) {
+ var proxyWrite = PauseStream()
+ , proxyRead = through()
+ , proxy = es.duplex(proxyWrite, proxyRead)
+ , metaStreams = []
+ , stream
+
+ proxy.createStream = createStream
+ proxy.createWriteStream = createWriteStream
+ proxy.createReadStream = createReadStream
+
+ createShoeStream()
+
+ return proxy
+
+ function createShoeStream() {
+ stream = shoe(uri)
+
+ metaStreams.forEach(function (details) {
+ var proxyWrite = details.proxyWrite
+ , proxyRead = details.proxyRead
+
+ var mdm = stream.createStream(details.meta, details.opts)
+
+ proxyWrite.pipe(mdm).pipe(proxyRead)
+ })
+
+ stream.on("connect", function () {
+ proxyWrite.resume()
+ proxy.emit("connect")
+ })
+
+ proxyWrite.pipe(stream).pipe(proxyRead)
+
+ stream.on("end", function () {
+ console.log("stream ended")
+ proxyWrite.pause()
+ proxy.emit("disconnect")
+ createShoeStream()
+ })
+ }
+
+ function createStream(meta, opts) {
+ var proxyWrite = PauseStream()
+ , proxyRead = through()
+ , proxy = es.duplex(proxyWrite, proxyRead)
+
+ var mdm = stream.createStream(meta, opts)
+
+ proxyWrite.pipe(mdm).pipe(proxyRead)
+
+ metaStreams.push({
+ proxy: proxy
+ , proxyRead: proxyRead
+ , proxyWrite: proxyWrite
+ , meta: meta
+ , opts: opts
+ })
+
+ return proxy
+ }
+
+ function createWriteStream(meta) {
+ createStream(meta, {
+ writable: true
+ , readable: false
+ })
+ }
+
+ function createReadStream(meta) {
+ createStream(meta, {
+ writable: false
+ , readable: true
+ })
+ }
+}
View
@@ -0,0 +1,10 @@
+var shoe = require('../browser.js')
+ , mdm = shoe("/shoe")
+
+var one = window.one = mdm.createStream("one")
+
+one.on("data", function (data) {
+ console.log("message", data)
+})
+
+one.write("hello world")
View
@@ -0,0 +1,28 @@
+var http = require('http')
+ , path = require("path")
+ , through = require("through")
+ , browserify = require("browserify")
+
+var server = http.createServer(function (req, res) {
+ if (req.url === "/bundle.js") {
+ var b = browserify()
+ b.addEntry(path.join(__dirname, "./client.js"))
+ res.end(b.bundle())
+ } else {
+ res.end("<script src='bundle.js'></script>")
+ }
+})
+server.listen(8081)
+
+var shoe = require("..")
+ , echoStream = through()
+
+var sock = shoe(function (stream) {
+ // stream from MuxDemux with the meta property set
+ if (stream.meta === "one") {
+ stream.on("data", console.log.bind(console))
+ stream.pipe(echoStream).pipe(stream)
+ }
+})
+
+sock.install(server, "/shoe")
View
@@ -0,0 +1 @@
+module.exports = require("mux-demux-shoe")

0 comments on commit dcf0380

Please sign in to comment.