This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dcacb29
Showing
11 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
demo/www/jam/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2012 ajax.org B.V | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
architect-smith-transport | ||
========================= | ||
|
||
[Smith](https://github.com/c9/smith)-based transport layer (via [engine.io](https://github.com/LearnBoost/engine.io)) | ||
for [architect](https://github.com/c9/architect). | ||
|
||
Features: | ||
|
||
* Architect server plugin | ||
* `requirejs` compatible browser client module | ||
* Architect browser plugin (**COMING SOON**) | ||
* WebSockets by default with long-poll fallback | ||
* Automatic reconnect | ||
* `socket.io` compatible API | ||
* All major browsers supported (**TO BE VERIFIED**) | ||
|
||
Development | ||
=========== | ||
|
||
npm install | ||
cd demo | ||
npm install | ||
node server | ||
open http://localhost:8080/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "architect-smith-transport-demo", | ||
"version": "0.0.1", | ||
"main": "server-plugin.js", | ||
"private": true, | ||
"plugin": { | ||
"provides": [], | ||
"consumes": [ | ||
"smith.transport.server", | ||
"connect" | ||
] | ||
}, | ||
"dependencies": { | ||
"architect": "0.1.x", | ||
"connect-architect": "0.0.x" | ||
}, | ||
"scripts": { | ||
"postinstall": "cd www && jam install smith events msgpack-js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
const PATH = require("path"); | ||
const ARCHITECT = require("architect"); | ||
|
||
var port = process.env.PORT || 8080; | ||
|
||
var plugins = [ | ||
{ | ||
packagePath: "connect-architect/connect", | ||
host: "localhost", | ||
port: port | ||
}, | ||
{ | ||
packagePath: "connect-architect/connect.session", | ||
key: "connect.architect." + port, | ||
secret: "1234" | ||
}, | ||
{ | ||
packagePath: "connect-architect/connect.session.memory" | ||
}, | ||
{ | ||
packagePath: "architect/plugins/architect.log" | ||
}, | ||
{ | ||
packagePath: "./../server-plugin", | ||
prefix: "/transport/server" | ||
}, | ||
{ | ||
provides: [], | ||
consumes: [ | ||
"smith.transport.server", | ||
"connect" | ||
], | ||
setup: function(options, imports, register) { | ||
|
||
imports.connect.useStart(imports.connect.getModule().static(PATH.join(__dirname, "www"))); | ||
|
||
register(null, {}); | ||
} | ||
} | ||
]; | ||
|
||
ARCHITECT.createApp(ARCHITECT.resolveConfig(plugins, __dirname), function (err, app) { | ||
if (err) { | ||
console.error("While starting!"); | ||
throw err; | ||
} | ||
console.log("Started!"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
require(["transport/client"], function (TRANSPORT_CLIENT) { | ||
|
||
console.log("Connecting"); | ||
|
||
TRANSPORT_CLIENT.connect({ | ||
host: "localhost", | ||
port: 8080, | ||
prefix: "/transport/server" | ||
}, function(err, transport) { | ||
|
||
console.log("Connected"); | ||
|
||
transport.on("channel1", function(data) { | ||
console.log("Channel 1 message", data); | ||
transport.emit("channel1", data); | ||
}); | ||
transport.on("channel2", function(data) { | ||
console.log("Channel 2 message", data); | ||
transport.emit("channel2", data); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Smith Transport Demo</title> | ||
</head> | ||
<body> | ||
<h1>Smith Transport Demo</h1> | ||
<script src="jam/require.js"></script> | ||
<script> | ||
requirejs.config({ | ||
baseUrl: "/", | ||
paths: { | ||
"transport": "/transport/server" | ||
} | ||
}); | ||
</script> | ||
<script src="app.js"></script> | ||
<p>Check your console for messages.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "architect-smith-transport", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"smith": "~0.1.7", | ||
"engine.io": "~0.1.2", | ||
"engine.io-client": "~0.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "architect-smith-transport-server-plugin", | ||
"version": "0.0.1", | ||
"main": "plugin.js", | ||
"private": true, | ||
"plugin": { | ||
"provides": ["smith.transport.server"], | ||
"consumes": [ | ||
"log", | ||
"http", | ||
"connect" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
const PATH = require("path"); | ||
const FS = require("fs"); | ||
const SMITH = require("smith"); | ||
const ENGINE_IO = require("engine.io"); | ||
|
||
|
||
module.exports = function startup(options, imports, register) { | ||
|
||
var channels = options.channels || {}; | ||
var sources = { | ||
"client": FS.readFileSync(PATH.join(__dirname, "www", "client.js")), | ||
"engine.io": FS.readFileSync(require.resolve("engine.io-client/dist/engine.io.js")) | ||
}; | ||
|
||
var prefix = (options.prefix || "/"); | ||
|
||
imports.connect.useSession(imports.connect.getModule().router(function(app) { | ||
|
||
// Serve the transport client. | ||
app.get(prefix + "/client.js", function(req, res) { | ||
res.writeHead(200, { | ||
"Content-Type": "application/javascript" | ||
}); | ||
res.end(sources["client"]); | ||
}); | ||
|
||
// Serve transport dependencies. | ||
app.get(prefix + "/engine.io.js", function(req, res) { | ||
res.writeHead(200, { | ||
"Content-Type": "application/javascript" | ||
}); | ||
res.end(sources["engine.io"]); | ||
}); | ||
})); | ||
|
||
|
||
var engine = ENGINE_IO.attach(imports.http.getServer(), { | ||
path: prefix | ||
}); | ||
engine.on("connection", function (socket) { | ||
|
||
var transport = new SMITH.EngineIoTransport(socket); | ||
|
||
transport.send({hello:"World"}); | ||
|
||
transport.on("legacy", function (message) { | ||
console.log("legacy", message); | ||
}); | ||
|
||
transport.on("message", function (message) { | ||
console.log("message", message); | ||
}) | ||
|
||
}); | ||
|
||
|
||
register(null, { | ||
"smith.transport.server": {} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
define(function(require, exports, module) { | ||
|
||
var ENGINE_IO = require("./engine.io"); | ||
var SMITH = require("smith"); | ||
|
||
|
||
var Transport = function(options, connectedCallback) { | ||
this.options = options; | ||
this.options.path = this.options.prefix; | ||
delete this.options.prefix; | ||
this.connect(connectedCallback); | ||
} | ||
Transport.prototype.connect = function(callback) { | ||
var _self = this; | ||
|
||
// NOTE: `eio` comes from `require("./engine.io");`. | ||
_self.socket = new eio.Socket(_self.options); | ||
_self.socket.on("open", function () { | ||
|
||
var transport = new SMITH.EngineIoTransport(_self.socket); | ||
|
||
transport.on("message", function (message) { | ||
console.log("message", message); | ||
}); | ||
|
||
transport.on("legacy", function (message) { | ||
console.log("legacy", message); | ||
|
||
transport.send([message]); | ||
}); | ||
|
||
transport.on("disconnect", function (reason) { | ||
|
||
console.log("disconnect", reason); | ||
console.log("TODO: Reconnect!"); | ||
|
||
}); | ||
}); | ||
} | ||
Transport.prototype.emit = function(channel, message) { | ||
|
||
console.log("Sending", message, "to channel", channel); | ||
|
||
} | ||
Transport.prototype.on = function(channel, handler) { | ||
|
||
console.log("Registering handler", handler, "for channel", channel); | ||
|
||
} | ||
|
||
var connections = {}; | ||
exports.connect = function(options, callback) { | ||
if (connections[options.prefix]) { | ||
return callback(null, connections[options.prefix]); | ||
} | ||
connections[options.prefix] = new Transport(options, callback); | ||
} | ||
|
||
}); |