@hive-p2p/server 1.0.77 → 1.0.78
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/core/ice-offer-manager.mjs +10 -4
- package/core/node.mjs +11 -1
- package/package.json +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { CLOCK } from '../services/clock.mjs';
|
|
2
2
|
import { NODE, TRANSPORTS, LOG_CSS } from './config.mjs';
|
|
3
3
|
import { xxHash32 } from '../libs/xxhash32.mjs';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
// WE SHOULD LOAD WRTC ONLY WHEN NEEDED ! => Now done in node.mjs
|
|
6
|
+
/*async function getWrtc() {
|
|
5
7
|
if (typeof globalThis.RTCPeerConnection !== 'undefined') return undefined;
|
|
6
8
|
return (await import('wrtc')).default;
|
|
7
9
|
}
|
|
8
|
-
const wrtc = await getWrtc()
|
|
10
|
+
const wrtc = await getWrtc();*/
|
|
9
11
|
|
|
10
12
|
/** - 'OfferObj' Definition
|
|
11
13
|
* @typedef {Object} OfferObj
|
|
@@ -20,6 +22,7 @@ const wrtc = await getWrtc();
|
|
|
20
22
|
|
|
21
23
|
export class OfferManager { // Manages the creation of SDP offers and handling of answers
|
|
22
24
|
id;
|
|
25
|
+
wrtc;
|
|
23
26
|
verbose;
|
|
24
27
|
stunUrls;
|
|
25
28
|
|
|
@@ -36,6 +39,9 @@ export class OfferManager { // Manages the creation of SDP offers and handling o
|
|
|
36
39
|
offersToCreate = TRANSPORTS.MAX_SDP_OFFERS;
|
|
37
40
|
/** @type {Record<string, OfferObj>} key: offerHash **/ offers = {};
|
|
38
41
|
|
|
42
|
+
/** WRTC assignment, this is made to avoid import of wrtc while importing hive-p2P lib */
|
|
43
|
+
assignTransportWrtc(w) { this.wrtc = w; }
|
|
44
|
+
/** WRTC Should be assigned before calling tick() */
|
|
39
45
|
tick() { // called in peerStore to avoid multiple intervals
|
|
40
46
|
const now = CLOCK.time;
|
|
41
47
|
// CLEAR EXPIRED CREATOR OFFER INSTANCES
|
|
@@ -90,7 +96,7 @@ export class OfferManager { // Manages the creation of SDP offers and handling o
|
|
|
90
96
|
};
|
|
91
97
|
#createOffererInstance(expiration) {
|
|
92
98
|
const iceCompleteTimeout = TRANSPORTS.ICE_COMPLETE_TIMEOUT || 1_000;
|
|
93
|
-
const instance = new TRANSPORTS.PEER({ initiator: true, trickle: false, iceCompleteTimeout, wrtc, config: { iceServers: this.stunUrls } });
|
|
99
|
+
const instance = new TRANSPORTS.PEER({ initiator: true, trickle: false, iceCompleteTimeout, wrtc: this.wrtc, config: { iceServers: this.stunUrls } });
|
|
94
100
|
instance.on('error', error => this.#onError(error));
|
|
95
101
|
instance.on('signal', data => { // trickle: false => only one signal event with the full offer
|
|
96
102
|
const { candidate, type } = data; // with trickle, we need to adapt the approach.
|
|
@@ -183,7 +189,7 @@ export class OfferManager { // Manages the creation of SDP offers and handling o
|
|
|
183
189
|
|
|
184
190
|
// type === 'offer' => CREATE ANSWERER INSTANCE
|
|
185
191
|
const iceCompleteTimeout = TRANSPORTS.ICE_COMPLETE_TIMEOUT || 1_000;
|
|
186
|
-
const instance = new TRANSPORTS.PEER({ initiator: false, trickle: false, iceCompleteTimeout, wrtc, config: { iceServers: this.stunUrls } });
|
|
192
|
+
const instance = new TRANSPORTS.PEER({ initiator: false, trickle: false, iceCompleteTimeout, wrtc: this.wrtc, config: { iceServers: this.stunUrls } });
|
|
187
193
|
instance.on('error', (error) => this.#onError(error));
|
|
188
194
|
instance.on('signal', (data) => this.onSignalAnswer(remoteId, data, offerHash));
|
|
189
195
|
instance.on('connect', () => this.onConnect(remoteId, instance));
|
package/core/node.mjs
CHANGED
|
@@ -144,13 +144,23 @@ export class Node {
|
|
|
144
144
|
get publicUrl() { return this.services?.publicUrl; }
|
|
145
145
|
get time() { return CLOCK.time; }
|
|
146
146
|
|
|
147
|
+
async #getWrtc() {
|
|
148
|
+
if (typeof RTCPeerConnection !== 'undefined') return undefined;
|
|
149
|
+
return (await import('wrtc')).default;
|
|
150
|
+
}
|
|
147
151
|
async start() {
|
|
152
|
+
const w = await this.#getWrtc();
|
|
153
|
+
this.offerManager.assignTransportWrtc(w);
|
|
154
|
+
|
|
148
155
|
await CLOCK.sync(this.verbose);
|
|
149
156
|
this.started = true;
|
|
150
157
|
if (SIMULATION.AVOID_INTERVALS) return true; // SIMULATOR CASE
|
|
151
158
|
|
|
152
159
|
this.arbiterInterval = setInterval(() => this.arbiter.tick(), 1000);
|
|
153
|
-
this.peerStoreInterval = setInterval(() => {
|
|
160
|
+
this.peerStoreInterval = setInterval(() => {
|
|
161
|
+
this.peerStore.cleanupExpired();
|
|
162
|
+
this.peerStore.offerManager.tick();
|
|
163
|
+
}, 2500);
|
|
154
164
|
if (this.publicUrl) return true;
|
|
155
165
|
|
|
156
166
|
this.enhancerInterval = setInterval(() => this.topologist.tick(), DISCOVERY.LOOP_DELAY);
|