node-rtc-connection 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-rtc-connection",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "WebRTC DataChannel implementation for Node.js with STUN, TURN, NAT traversal, and encryption. Pure Node.js, no native dependencies.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -225,6 +225,16 @@ class RTCPeerConnection extends EventEmitter {
225
225
  * @private
226
226
  */
227
227
  _openDataChannels() {
228
+ // Check if network transport has active connections
229
+ const hasConnections = this._networkTransport &&
230
+ this._networkTransport.tcpTransport &&
231
+ this._networkTransport.tcpTransport.connections.size > 0;
232
+
233
+ if (!hasConnections) {
234
+ // Network not ready yet, channels will be opened when connection establishes
235
+ return;
236
+ }
237
+
228
238
  for (const channel of this._dataChannels.values()) {
229
239
  if (channel.readyState === 'connecting') {
230
240
  this._connectChannelToNetwork(channel);
@@ -614,15 +624,8 @@ class RTCPeerConnection extends EventEmitter {
614
624
  // Open data channels when connection is established
615
625
  this._sctpTransport.once('statechange', () => {
616
626
  if (this._sctpTransport.state === 'connected') {
617
- for (const channel of this._dataChannels.values()) {
618
- if (channel.readyState === 'connecting') {
619
- // Hook up channel to network transport first
620
- this._connectChannelToNetwork(channel);
621
-
622
- // Then set state to open (emits 'open' event)
623
- channel._setStateToOpen();
624
- }
625
- }
627
+ // Wait for network to be ready before opening channels
628
+ this._openDataChannels();
626
629
  }
627
630
  });
628
631
  }