为所有快速路线分享socketio

时间:2015-09-14 07:50:07

标签: node.js express socket.io

App.js

 var io = socket_io();
 app.io = io;
 var socket = require('./config/socketio')(io);

 var routes = require('./app/routes/index');

socketio.js:

var config = require('./config');

module.exports = function(io){
    io.on('connection', function (socket, next) {
        socket.emit('hello', 'hello');
    });

    return io;
};

如何在不将套接字传递到每条路径的情况下使用socketio.js中的io?:

var socket = require('./config/socketio')(io);

var routes = require('./app/routes/index')(socket);

0 个答案:

没有答案