Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix broadcasting from a parent namespace (#5009)
Following [1], emitting from a dynamic namespace to a room would throw this error: > node_modules/socket.io/dist/parent-namespace.js:88 > this.children.forEach((nsp) => { > ^ > > TypeError: Cannot read properties of undefined (reading 'forEach') > at ParentBroadcastAdapter.broadcast (node_modules/socket.io/dist/parent-namespace.js:88:23) > at BroadcastOperator.emit (node_modules/socket.io/dist/broadcast-operator.js:169:26) > at Socket.<anonymous> (server.js:60:33) > at Socket.emit (node:events:520:28) > at Socket.emitReserved (node_modules/socket.io/dist/typed-events.js:56:22) > at Socket._onclose (node_modules/socket.io/dist/socket.js:547:14) > at Client.onclose (node_modules/socket.io/dist/client.js:247:20) > at Socket.emit (node:events:532:35) > at Socket.onClose (node_modules/engine.io/build/socket.js:304:18) > at Object.onceWrapper (node:events:639:28) Previous output code: ```js class ParentNamespace extends namespace_1.Namespace { constructor(server) { super(server, "/_" + ParentNamespace.count++); this.children = new Set(); } _initAdapter() { this.adapter = new ParentBroadcastAdapter(this, this.children); } } ``` Here, `super()` calls `Namespace._initAdapter()`, but `this.children` is not defined yet, hence the problem. [1]: b9ce6a2 Related: #4985
- Loading branch information