Permalink
Browse files

[plugins] Removed socket.io plugin for now. It seems easier to just m…

…anually setup socket.io
  • Loading branch information...
1 parent 47b825b commit 4026d795a3aa68259d393396197117a394698366 @Marak Marak committed Aug 20, 2012
Showing with 13 additions and 124 deletions.
  1. +13 −11 examples/socket.io/server.js
  2. +0 −113 lib/flatiron/plugins/socketio.js
@@ -15,22 +15,24 @@ app.use(flatiron.plugins.http, {
res.writeHead(200);
res.end(data);
});
+
}]
});
-app.use(flatiron.plugins.socketio)
// Set the server to listen on port `8080`.
// It is important to do this first, as app.server
// isn't actually created until you start()
-app.start(8080, function(){
- // Socket.io
- // -------------------------------------------------- //
- app.io.sockets.on('connection', function(socket) {
- socket.emit('news', { hello: 'world' });
- socket.on('my other event', function(data) {
- console.log(data);
- });
- });
-});
+app.start(8080);
+// Socket.io
+// -------------------------------------------------- //
+
+var io = require('socket.io').listen(app.server);
+
+io.sockets.on('connection', function(socket) {
+ socket.emit('news', { hello: 'world' });
+ socket.on('my other event', function(data) {
+ console.log(data);
+ });
+});
@@ -1,113 +0,0 @@
-/*
- * socketio.js: Top-level plugin for using socket.io in a Flatiron app
- *
- * (C) 2012, Nodejitsu, Inc.
- * MIT LICENSE
- *
- */
-
-var path = require('path'),
- flatiron = require('../../flatiron'),
- common = flatiron.common,
- socketio;
-
-
-//
-// TODO: Refactor the try / catch / require pattern here
-// see: https://github.com/flatiron/broadway/issues/34
-//
-try {
- //
- // Attempt to require socketio.
- //
- socketio = require('socket.io');
-}
-catch (ex) {
- //
- // Do nothing since this is a progressive enhancement
- //
- console.warn('flatiron.plugins.socketio requires the `socket.io` module from npm');
- console.warn('install using `npm install socket.io`.');
- console.trace();
- process.exit(1);
-}
-
-var union;
-
-try {
- //
- // Attempt to require union.
- //
- union = require('union');
-}
-catch (ex) {
- //
- // Do nothing since this is a progressive enhancement
- //
- console.warn('flatiron.plugins.http requires the `union` module from npm');
- console.warn('install using `npm install union`.');
- console.trace();
- process.exit(1);
-}
-
-exports.name = 'socketio';
-
-exports.attach = function (options) {
- var app = this;
-
- options = options || {};
-
- app.start = function (port, host, callback) {
- if (!callback && typeof host === 'function') {
- callback = host;
- host = null;
- }
- app.init(function (err) {
- if (err) {
- if (callback) {
- return callback(err);
- }
- throw err;
- }
- app.listen(port, host, callback);
- });
- };
-
- app.createServer = function(){
- app.server = union.createServer({
- after: app.http.after,
- before: app.http.before.concat(function (req, res) {
- if (!app.router.dispatch(req, res, app.http.onError || union.errorHandler)) {
- if (!app.http.onError) res.emit('next');
- }
- }),
- headers: app.http.headers,
- limit: app.http.limit,
- https: app.http.https
- });
- };
-
- app.listen = function (port, host, callback) {
- if (!callback && typeof host === 'function') {
- callback = host;
- host = null;
- }
- app.createServer();
- app.io = socketio.listen(app.server);
- return host
- ? app.server.listen(port, host, callback)
- : app.server.listen(port, callback);
- };
-
- //
- // Attempt to merge defaults passed to `app.use(flatiron.plugins.socketio)`
- // with any additional configuration that may have been loaded
- options = common.mixin(
- {},
- options,
- app.config.get('socketio') || {}
- );
-
- app.config.set('socketio', options);
-
-}

0 comments on commit 4026d79

Please sign in to comment.