Permalink
Browse files

Connect vfs in server to browser using smith.io transport.

  • Loading branch information...
1 parent 1d155cb commit 3bae242a42c6988e71c1ffd94a4361c6c27b8985 @creationix creationix committed Nov 13, 2012
Showing with 42 additions and 13 deletions.
  1. +1 −1 package.json
  2. +1 −0 server-plugin/package.json
  3. +20 −3 server-plugin/plugin.js
  4. +20 −9 server-plugin/www/client.js
View
@@ -14,7 +14,7 @@
},
"pm": "npm",
"dependencies": {
- "smith": "https://github.com/c9/smith/tarball/packing-fix",
+ "vfs-socket": "~0.3.11",
"msgpack-js-browser": "~0.1.3",
"engine.io": "https://github.com/c9/engine.io/tarball/5f6fb9e32caed4f3edbb9f8536a13a20435d3d69"
},
@@ -6,6 +6,7 @@
"plugin": {
"provides": ["smith.transport.server"],
"consumes": [
+ "vfs",
"log",
"http",
"connect",
View
@@ -2,9 +2,11 @@
const ASSERT = require("assert");
const PATH = require("path");
const FS = require("fs");
-const SMITH = require("smith");
const ENGINE_IO = require("engine.io");
const EVENTS = require("events");
+var Worker = require('vfs-socket/worker').Worker;
+var SMITH = require('vfs-socket/worker').smith;
+
// Switch from `away` to `disconnect` after this many milliseconds.
const RECONNECT_TIMEOUT = 60 * 1000;
@@ -49,6 +51,7 @@ module.exports = function startup(options, imports, register) {
}
var gee = new EVENTS.EventEmitter();
+ var worker = new Worker(imports.vfs);
if (options.messageRoute) {
@@ -82,9 +85,11 @@ module.exports = function startup(options, imports, register) {
return;
}
- var transport = new SMITH.EngineIoTransport(socket);
+ var transport = new SMITH.EngineIoTransport(socket, options.debug);
var id = false;
+ worker.connect(transport);
+
transport.on("legacy", function (message) {
if (typeof message === "object" && message.type === "__ANNOUNCE-ID__") {
id = message.id;
@@ -178,7 +183,7 @@ module.exports = function startup(options, imports, register) {
}]);
imports.static.addStatics([{
- path: PATH.dirname(require.resolve("smith")),
+ path: PATH.dirname(require.resolve("vfs-socket/node_modules/smith")),
mount: "/smith",
rjs: [
{
@@ -190,6 +195,18 @@ module.exports = function startup(options, imports, register) {
}]);
imports.static.addStatics([{
+ path: PATH.dirname(require.resolve("vfs-socket/consumer")),
+ mount: "/vfs-socket",
+ rjs: [
+ {
+ "name": "vfs-socket",
+ "location": "vfs-socket",
+ "main": "consumer.js"
+ }
+ ]
+ }]);
+
+ imports.static.addStatics([{
path: PATH.dirname(require.resolve("msgpack-js-browser")),
mount: "/msgpack-js",
rjs: [
@@ -3,13 +3,16 @@ define(function(require, exports, module) {
require("engine.io");
var ENGINE_IO = eio; // NOTE: `eio` is a global! See `npm info engine.io-client`.
- var SMITH = require("smith");
var EVENTS = require("smith/events-amd");
+ var Consumer = require('vfs-socket/consumer').Consumer;
+ var SMITH = require('vfs-socket/consumer').smith;
var transports = [];
var debugHandler = null;
var connectCounter = 0;
+ var consumer = new Consumer();
+
function inherits(Child, Parent) {
Child.prototype = Object.create(Parent.prototype, { constructor: { value: Child }});
}
@@ -41,8 +44,8 @@ define(function(require, exports, module) {
inherits(Transport, EVENTS.EventEmitter);
Transport.prototype.getUri = function() {
- return "http" + ((this.options.secure)?"s":"") + "://" +
- this.options.host +
+ return "http" + ((this.options.secure)?"s":"") + "://" +
+ this.options.host +
((this.options.port)?":"+this.options.port:"") +
this.options.path +
this.options.resource;
@@ -233,7 +236,14 @@ define(function(require, exports, module) {
log("Init new socket (" + _self.socket.id + ")");
}
- _self.transport = new SMITH.EngineIoTransport(_self.socket);
+ _self.transport = new SMITH.EngineIoTransport(_self.socket, _self.debug);
+
+ consumer.connect(_self.transport, function (err, vfs) {
+ if (err) throw err;
+ window.vfs = vfs;
+ console.log("vfs", vfs);
+ });
+
_self.transport.on("legacy", function (message) {
if (typeof message === "object" && message.type === "__ASSIGN-ID__") {
@@ -274,7 +284,7 @@ define(function(require, exports, module) {
_self.emit("disconnect", "long away (hibernate)");
} catch(err) {
console.error(err.stack);
- }
+ }
}
}
_self.away = false;
@@ -291,7 +301,7 @@ define(function(require, exports, module) {
_self.emit("back");
} catch(err) {
console.error(err.stack);
- }
+ }
}
options.reconnectAttempt = 0;
if (_self.buffer) {
@@ -302,10 +312,10 @@ define(function(require, exports, module) {
}
} else {
try {
- _self.emit("message", message);
+ _self.emit("legacy", message);
} catch(err) {
console.error(err.stack);
- }
+ }
}
});
@@ -366,8 +376,9 @@ define(function(require, exports, module) {
}
if (transport.debug) {
console.log(getLogTimestamp() + "[smith.io:" + transport.getUri() + "] New transport", options);
- }
+ }
transport.connect({}, callback);
+
return transport;
}

0 comments on commit 3bae242

Please sign in to comment.