rajgoel / reveal.js-plugins

Plugins for reveal.js
MIT License
739 stars 248 forks source link

Bug crashing the server (Cannot read properties of undefined (reading 'id')) #145

Closed heia-fr-maeder closed 2 years ago

heia-fr-maeder commented 2 years ago

Hi I had quite a lot of crashes with socket.io server. Unfortunately I am not at all a JavaScript person and thus a little bit lost.

I have the followings:

/code/server.js:330
socketio_1  |       if ( hosts[i].findIndex(host => host.id === socket.id) !== -1 ) {
socketio_1  |                                            ^
socketio_1  |
socketio_1  | TypeError: Cannot read properties of undefined (reading 'id')
socketio_1  |     at /code/server.js:330:40

and also at another place:

socketio_1  | /code/server.js:192
socketio_1  | const chair = ( user.id == hosts[i][0].id );
socketio_1  |                            ^
socketio_1  |
socketio_1  | TypeError: Cannot read properties of undefined (reading 'id')
socketio_1  |     at leaveRoom (/code/server.js:192:24)
socketio_1  |     at Socket.<anonymous> (/code/server.js:299:3)
socketio_1  |     at Socket.emit (node:events:527:28)
socketio_1  |     at /code/node_modules/socket.io/lib/socket.js:528:12
socketio_1  |     at processTicksAndRejections (node:internal/process/task_queues:78:11)
socketio_1  |
socketio_1  | Node.js v17.7.1

Reproduce the case:

I assume that the variable user (host respectively) are empty and therefore the 'id' can not be accessed. What would be the best remediation ? Try-catch?

Thanks for your help

heia-fr-maeder commented 2 years ago

Sorry, wrong place