0
我目前的工作中,我發送一些參數envents簡單socketio應用程序中獲得的屬性,我將它們存儲到每個插座。Socketio 1.0從所有客戶
socket.on('add user', function (data) {
if (addedUser) return;
// we store the username in the socket session for this client.
socket.nickname = data.nickname;
socket.userId = data.userId;
...
然後我得到全部採用VAR io.engine.clients socketio客戶和我試圖獲得在其他事件參數是這樣的:
socket.on('new message', function (data) {
var clientsRoom = io.engine.clients;
for(var c in clientsRoom){
console.log(" Client: " + c.userId); //Error
console.log(" Client: " + c); //outputs the socket ID
console.log(" Client: " + c['userId']); //Error
}
...
,但我無法得到我的用戶ID以前存儲爲所有套接字。我究竟做錯了什麼?
謝謝。
如果我把我的代碼一個日誌後socket.userId = data.userId;打印socket.userId它打印我的用戶ID。但隨着你的代碼,試圖得到它時,將返回我:客戶:未定義:-( – walolinux
@walolinux我把我的要點與測試代碼:https://gist.github.com/robertklep/080f62fc6d7a506d8f5a55bc3bf61252 – robertklep
沒錯,是工作,但我意識到我需要列出所有連接的插座在一個房間裏,不是一般的,然後獲得用戶id ... – walolinux