Issue:
Local development in VS Code runs without problems or crashes.
However, when I upload the application to a server (node.js), it runs until a Socket.io connection is established or the connected web page is refreshed.
I don't know if this relates to the admin UI specifically as in the filepath below or if this is a Socket.io issue in general.
Perhaps this also has to do with the middleware which holds up a request until an action has completed so that non-existent data cannot be accessed.
I already tried to update the npm package, but nothing has changed.
// middleware is executed on every request
var Map = require('./file')
module.exports = (io, socket) => {
socket.use(async (packet, next) => {
var key = socket.handshake.auth.key
var data = Map.get(key)
while(!data.action) { // true for finished or false for loading
await new Promise(resolve => setTimeout(resolve,10))
}
socket.data = data
next()
})
}
Serverconsole:
/usr/src/app/node_modules/@socket.io/admin-ui/dist/index.js:233
socket.data._admin.transport = transport.name;
^
TypeError: Cannot set properties of undefined (setting 'transport')
at Socket.<anonymous> (/usr/src/app/node_modules/@socket.io/admin-ui/dist/index.js:233:42)
at Socket.emit (node:events:390:28)
at WebSocket.onPacket (/usr/src/app/node_modules/engine.io/build/socket.js:214:22)
at WebSocket.emit (node:events:390:28)
at WebSocket.onPacket (/usr/src/app/node_modules/engine.io/build/transport.js:92:14)
at WebSocket.onData (/usr/src/app/node_modules/engine.io/build/transport.js:101:14)
at WebSocket.<anonymous> (/usr/src/app/node_modules/engine.io/build/transports/websocket.js:20:19)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (/usr/src/app/node_modules/ws/lib/websocket.js:1022:20)
at Receiver.emit (node:events:390:28)
Node.js v17.3.1
CodePudding user response:
I also asked the developers the question on GitHub directly and I received an answer.
I was told that data is overwritten by using socket.data = value
.
If I change it to socket.socketDate
for example, then it works fine.
See the full answer on GitHub with the refered code of the socket.io admin ui:
github socket.io-admin-ui issue-55