@yz-social/webrtc 0.1.3 → 0.1.4
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/index.js +5 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -80,7 +80,9 @@ export class WebRTC {
|
|
|
80
80
|
// Do not try to close or wait for data channels. It confuses Safari.
|
|
81
81
|
const pc = this.pc;
|
|
82
82
|
if (!pc) return null;
|
|
83
|
-
pc.
|
|
83
|
+
const state = pc.connectionState;
|
|
84
|
+
if (state === 'connected' || state === 'failed') pc.close();
|
|
85
|
+
else this.flog("WebRTC close in unexpected state", state);
|
|
84
86
|
this.closed.resolve(pc); // We do not automatically receive 'connectionstatechange' when our side explicitly closes. (Only if the other does.)
|
|
85
87
|
this.cleanup();
|
|
86
88
|
return this.closed;
|
|
@@ -233,7 +235,8 @@ export class WebRTC {
|
|
|
233
235
|
this.log('setupChannel:', label, dc.id, readyState, 'negotiated:', dc.negotiated);
|
|
234
236
|
const kind = isTheirs ? 'Theirs' : 'Ours';
|
|
235
237
|
dc.webrtc = this;
|
|
236
|
-
dc.onopen =
|
|
238
|
+
dc.onopen = () => { // Idempotent (except for logging), if we do not bash dataChannePromises[label] multiple times.
|
|
239
|
+
dc.onopen = null;
|
|
237
240
|
this.log('channel onopen:', label, dc.id, readyState, 'negotiated:', dc.negotiated);
|
|
238
241
|
this[this.restrictablePromiseKey()][label]?.resolve(dc);
|
|
239
242
|
this[this.restrictablePromiseKey(kind)][label]?.resolve(dc);
|
|
@@ -246,7 +249,6 @@ export class WebRTC {
|
|
|
246
249
|
// This our chance to setupChannel, just as if we had called createChannel
|
|
247
250
|
this.log('ondatachannel:', dc.label, dc.id, dc.readyState, dc.negotiated);
|
|
248
251
|
this.setupChannel(dc);
|
|
249
|
-
dc.onopen(); // It had been opened before we setup, so invoke handler now.
|
|
250
252
|
}
|
|
251
253
|
channelId = 128; // Non-negotiated channel.id get assigned at open by the peer, starting with 0. This avoids conflicts.
|
|
252
254
|
createChannel(name = 'data', {negotiated = false, id = this.channelId++, ...options} = {}) { // Explicitly create channel and set it up.
|