-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this.children is undefined for ParentBroadcastAdapter broadcast #4985
Comments
Hi! That's weird, the socket.io/lib/parent-namespace.ts Lines 116 to 118 in b0568b2
In class ParentBroadcastAdapter extends socket_io_adapter_1.Adapter {
constructor(parentNsp, children) {
super(parentNsp);
this.children = children;
}
broadcast(packet, opts) {
this.children.forEach((nsp) => {
nsp.adapter.broadcast(packet, opts);
});
}
} So I'm not sure how |
Hi, |
Hi, is there an update on this? I believe the issue here is that Perhaps one way to change this would be: class ParentBroadcastAdapter extends socket_io_adapter_1.Adapter {
constructor(parentNsp) {
super(parentNsp);
this.parentNsp = parentNsp;
}
broadcast(packet, opts) {
this.parentNsp.children.forEach((nsp) => {
nsp.adapter.broadcast(packet, opts);
});
}
} |
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
Hi! I am using the latest version of the package. And I am facing this exact same issue!
|
@Hippopop I don't think the fix has been released yet. Let me check. |
@darrachequesne Yeah, I think that's the case. But I've been trying to to use the package/library directly from the GitHub. And use the #main brunch. Sadly that's not working either.
Is there anything I can do here?!? I'm a bit new with |
I am getting an error in my application after moving up to version
4.7.5
. When I run with previous versions, including4.7.4
, everything works properly. The error I receive is:When the following code was added in PR 4950 it appears that the code forgot to store or copy the
children
parameter.socket.io/lib/parent-namespace.ts
Line 121 in b0568b2
I think the code should be modified something like:
The text was updated successfully, but these errors were encountered: