0
我試圖向所有觀衆發送管理員通知。當一個管理員連接我加入('管理'),我想在該房間收聽通知消息並將其傳遞給所有用戶。這有效,但我做了用戶方面的測試,發現我仍然可以發送消息,就好像我是管理員一樣!只在特定房間監聽的Nodejs socketio
var express = require('express'),
app = express(),
http = require('http'),
connect = require('connect'),
cookieParser = express.cookieParser('fwefwefvccc'),
sessionStore = new connect.middleware.session.MemoryStore();
app.configure(function() {
app.use(cookieParser);
app.use(express.session({ store: sessionStore }));
});
var server = http.createServer(app),
io = require('socket.io').listen(server),
sessionSockets = require('session.socket.io'),
sessions = new sessionSockets(io, sessionStore, cookieParser);
sessions.on('connection', function (err, socket, session) {
// Client functions trimmed for SO
socket.on('adminJoin', function(data) {
if(data.password == "testing") {
socket.join('admin');
}
}
socket.in('admin').on('notification', function (data) {
io.sockets.emit("notification", {
'type': data.type,
'msg': data.msg
});
});
});
這似乎忽略了一個事實,用戶不在/管理/房間