Tuesday 15 March 2016

Socket.io typeof error, any help please?

Here's the relevant part of my codesocket.on('disconnect', function(){ console.log(rooms.length) var destroyThis = null if (typeof socket.store.data.roomi == 'undefined') { for (var i in rooms) { if (rooms[i].roomSocket.id == socket.id) { destroyThis = rooms[i] } } if (destroyThis !== null){ rooms.splice(destroyThis, 1) } console.log(rooms.length) } else { var roomID = socket.store.data.roomi for (var i in rooms[roomID].clientSockets) { destroyThis = i } } if (destroyThis !== null) { rooms[roomID].clientSockets.splice(destroyThis, 1) } rooms[roomID].roomSocket.emit('remove user', socket.id) }) and I get the error if (typeof socket.store.data.roomi == 'undefined') { ^ TypeError: Cannot read property 'data' of undefined To me this makes no sense, I'm trying to check if it's undefined and it's throwing an error because it's undefined?

Submitted March 15, 2016 at 06:42PM by Tomus

No comments:

Post a Comment