Permalink
Browse files

first

  • Loading branch information...
0 parents commit ae76fcc9129f3ee52632ed329265bbafae50db33 @Raynos committed Jul 31, 2012
@@ -0,0 +1,3 @@
+node_modules
+*.log
+*.err
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
19 LICENCE
@@ -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.
@@ -0,0 +1,10 @@
+node-test:
+ ./node_modules/.bin/tap --stderr ./test
+
+test:
+ ./node_modules/.bin/testem \
+ --file testem.json \
+ --debuglog testem.log \
+ --debug 2> testem.err
+
+.PHONY: test
@@ -0,0 +1,67 @@
+# seaport-proxy [![build status][1]][2]
+
+Seaport in the browser!
+
+## Example
+
+// browser.js
+var seaport = require("seaport-proxy")
+ , ports = seaport.connect("/winning")
+ , dnode = require("dnode")
+
+ports.get('magic@1.2.x', function (stream) {
+ var d = dnode()
+ d.on("remote", function (remote) {
+ remote.magic(function (magic) {
+ console.log("beep boop", magic)
+ })
+ })
+ d.pipe(stream).pipe(d)
+})
+
+// server.js
+var seaport = require("seaport")
+ , http = require("http")
+ , server = http.createServer()
+ , ports = seaport.connect(9090, { secret: 'beep boop' })
+
+var seaportProxy = require("seaport-proxy")
+ , seaportServer = seaportProxy.createServer(ports)
+
+seaportServer.install(server, "/winning")
+
+// magic.js
+var seaport = require("seaport")
+ , ports = seaport.connect(9090, { secret: 'beep boop' })
+ , net = require("net")
+ , dnode = require("dnode")
+
+var server = net.createServer(function (stream) {
+ var d = dnode({
+ magic: function (cb) {
+ cb("magic!")
+ }
+ })
+ d.pipe(stream).pipe(d)
+})
+
+ports.service('magic@1.2.3', function (port, ready) {
+ server.listen(port, ready)
+})
+
+## Installation
+
+`npm install seaport-proxy`
+
+## Tests
+
+`make test`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
+
+ [1]: https://secure.travis-ci.org/Raynos/seaport-proxy.png
+ [2]: http://travis-ci.org/Raynos/seaport-proxy
@@ -0,0 +1,48 @@
+var shoe = require("shoe")
+ , MuxDemux = require("mux-demux")
+ , upnode = require("upnode")
+ , uuid = require("node-uuid")
+ , mdm = MuxDemux()
+
+module.exports = {
+ connect: connect
+}
+
+function connect(uri) {
+ var stream = shoe(uri)
+ mdm.pipe(stream).pipe(mdm)
+ var upnodeStream = mdm.createStream("upnode")
+ var up = upnode.connect({
+ createStream: function () {
+ return upnodeStream
+ }
+ })
+
+ return {
+ get: get
+ , query: query
+ }
+
+ function get(role, callback) {
+ var key = uuid()
+ , stream = mdm.createStream(key)
+
+ callback(stream)
+
+ up(function (remote) {
+ console.log("remote", remote, remote.get, key)
+ remote.get(role, key)
+ })
+ }
+
+ function query(role, callback) {
+ var key = uuid()
+ , stream = mdm.createStream(key)
+
+ callback(stream)
+
+ up(function (remote) {
+ remote.query(role, key)
+ })
+ }
+}
@@ -0,0 +1,2 @@
+all:
+ node_modules/.bin/browserify browser.js -o static/bundle.js
@@ -0,0 +1,21 @@
+var seaport = require("../..")
+ , ports = seaport.connect("/winning")
+ , dnode = require("dnode")
+
+ports.get('magic@1.2.x', function (stream) {
+ console.log("connected to magic ports", stream)
+ console.dir(stream)
+
+ var d = dnode()
+ , result = document.getElementById("result")
+
+ d.on("remote", function (remote) {
+ console.log("got the remote!", remote, remote.magic)
+ console.dir(remote)
+ remote.magic(function (err, magic) {
+ console.log("got magic result!", magic)
+ result.textContent += magic
+ })
+ })
+ d.pipe(stream).pipe(d)
+})
@@ -0,0 +1,20 @@
+var seaport = require("seaport")
+ , ports = seaport.connect(9090, { secret: 'beep boop' })
+ , net = require("net")
+ , dnode = require("dnode")
+
+var server = net.createServer(function (stream) {
+ console.log("got incoming request!")
+ var d = dnode({
+ magic: function (cb) {
+ console.log("someone called magic!")
+ cb(null, "magic!")
+ }
+ })
+ d.pipe(stream).pipe(d)
+})
+
+ports.service('magic@1.2.3', function (port, ready) {
+ console.log("registered magic service")
+ server.listen(port, ready)
+})
@@ -0,0 +1,17 @@
+{
+ "name": "simple",
+ "version": "0.0.0",
+ "main": "browser.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1",
+ "start": "node server.js"
+ },
+ "license": "BSD",
+ "description": "ERROR: No README.md file found!",
+ "dependencies": {
+ "ecstatic": "~0.1.6",
+ "seaport": "~0.8.0",
+ "dnode": "~1.0.1",
+ "browserify": "~1.13.6"
+ }
+}
@@ -0,0 +1,13 @@
+var seaport = require("seaport")
+ , http = require("http")
+ , path = require("path")
+ , ecstatic = require("ecstatic")(path.join(__dirname, "static"))
+ , server = http.createServer(ecstatic)
+ , ports = seaport.connect(9090, { secret: 'beep boop' })
+ , seaportProxy = require("../..")
+
+server.listen(8080)
+
+console.log("listening on port 8080")
+
+seaportProxy(ports, server, "/winning")
Oops, something went wrong.

0 comments on commit ae76fcc

Please sign in to comment.