Open murat-dogan opened 5 days ago
All objects in the wrapper behave like that currently, as soon as they are not reachable anymore they can be garbage collected (even for globals), so you have to keep a reachable reference. Maybe it could be changed.
If I write only 1 line like this
let wsServer = new nodeDataChannel.WebSocketServer({ bindAddress: '127.0.0.1', port: 8000 });
It will be directly deleted by the garbage collector, this is normal. No reference, callback etc.
If I write this line
let peer1 = new nodeDataChannel.PeerConnection('Peer1', { iceServers: ['stun:stun.l.google.com:19302'] });
It will not be deleted by the garbage collector, because we have a callback created here https://github.com/murat-dogan/node-datachannel/blob/63ec3215063931aae772f2acfa2c2199bfeca2b3/src/peer-connection-wrapper.cpp#L252
Here I am setting a callback. Like this
const wsServer = new nodeDataChannel.WebSocketServer({ bindAddress: '127.0.0.1', port: 8000 });
wsServer.onClient((ws) => {
....
}
And it is not garbage collected(because we have a callback), until a client is connected. When a client connects, it is being deleted. I don't see any difference on the binding side.
Do you have any idea?
Hopefully this will be fixed soon. Workaround is an eyesore.
https://github.com/murat-dogan/node-datachannel/blob/websocket-examples/examples/client-server/signaling-server.js
In this example after 1 client connection, the garbage collector deletes
wsServer
.Workaround; https://github.com/murat-dogan/node-datachannel/blob/c311c111bdd1b3c20d056f6f46a7c3c12610f8ce/examples/client-server/signaling-server.js#L40-L44
Here is the log
@ptesavol Could you please also check?