Gau*_*pta 14 logging node.js socket.io
我想记录的event name和parameter我的节点服务器上的每个事件.为此我用过
io.use(function(socket, next){
// how to get event name out of socket.
});
Run Code Online (Sandbox Code Playgroud)
现在,我在试图获取事件名称和参数时遇到困难.对我来说,它似乎是API开发人员的共同需求,所以我很确定必须有一些方法来获取它,我试图阅读文档和源代码,但我无法得到这些东西.
套接字事件需要正确处理,无论如何,如果事件不处理,将不会有响应。
var io = require('socket.io')(server);
var sessionMiddleWare=(session({secret: 'secret key', resave: true, saveUninitialized: true,cookie: { path: '/', httpOnly: true, maxAge: 300000 },rolling: true}));
app.use(sessionMiddleWare)
io.use(function(socket, next) {
sessionMiddleWare(socket.request, socket.request.res, next);
});
io.on('connection', function(socket) { // On Socket connection.
// inside this you can use different events
//event name and parameters can be found in socket variable.
console.log(socket.id) // prints the id sent from the client.
console.log(socket.data) // prints the data sent from the client.
// example event
socket.on('subscribe', function(room) { // Event sample.
console.log('joining room', room);
socket.room=room;
socket.join(room);
});
})
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
1466 次 |
| 最近记录: |