@xtr-dev/rondevu-webtorrent 0.0.1 → 0.0.2
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/README.md +33 -0
- package/dist/RondevuConnectionManager.d.ts +11 -0
- package/dist/RondevuConnectionManager.js +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,6 +147,14 @@ interface RondevuConnectionManagerOptions {
|
|
|
147
147
|
RTCSessionDescription: typeof RTCSessionDescription;
|
|
148
148
|
RTCIceCandidate: typeof RTCIceCandidate;
|
|
149
149
|
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Optional prefix to add to all topics
|
|
153
|
+
* Allows creating separate discovery pools for different environments or applications
|
|
154
|
+
* @default '' (empty string - uses infoHash directly)
|
|
155
|
+
* @example 'dev.xtr.player:' would create topics like 'dev.xtr.player:abc123...'
|
|
156
|
+
*/
|
|
157
|
+
topicPrefix?: string;
|
|
150
158
|
}
|
|
151
159
|
```
|
|
152
160
|
|
|
@@ -216,6 +224,31 @@ connectionManager.destroy();
|
|
|
216
224
|
|
|
217
225
|
## Advanced Usage
|
|
218
226
|
|
|
227
|
+
### Topic Prefix for Separate Discovery Pools
|
|
228
|
+
|
|
229
|
+
Use a custom topic prefix to create isolated peer discovery pools. This is useful for:
|
|
230
|
+
- Separating development, staging, and production environments
|
|
231
|
+
- Creating application-specific discovery pools
|
|
232
|
+
- Preventing peers from different versions/contexts from discovering each other
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// Production environment
|
|
236
|
+
const prodManager = new RondevuConnectionManager(client, {
|
|
237
|
+
topicPrefix: 'prod.myapp:',
|
|
238
|
+
debug: false
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Development environment
|
|
242
|
+
const devManager = new RondevuConnectionManager(client, {
|
|
243
|
+
topicPrefix: 'dev.myapp:',
|
|
244
|
+
debug: true
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Now torrents with the same infoHash in prod and dev won't discover each other
|
|
248
|
+
// Production uses topics like: 'prod.myapp:abc123...'
|
|
249
|
+
// Development uses topics like: 'dev.myapp:abc123...'
|
|
250
|
+
```
|
|
251
|
+
|
|
219
252
|
### Custom RTCConfiguration
|
|
220
253
|
|
|
221
254
|
Provide custom STUN/TURN servers for WebRTC connections:
|
|
@@ -41,6 +41,13 @@ export interface RondevuConnectionManagerOptions {
|
|
|
41
41
|
* Required for WebRTC functionality in Node.js environments
|
|
42
42
|
*/
|
|
43
43
|
wrtc?: WebRTCPolyfill;
|
|
44
|
+
/**
|
|
45
|
+
* Optional prefix to add to all topics. This allows creating separate discovery pools
|
|
46
|
+
* for different environments or applications.
|
|
47
|
+
* For example: 'dev.xtr.player:' would make topics like 'dev.xtr.player:abc123...'
|
|
48
|
+
* (default: empty string - uses infoHash directly)
|
|
49
|
+
*/
|
|
50
|
+
topicPrefix?: string;
|
|
44
51
|
}
|
|
45
52
|
/**
|
|
46
53
|
* Connection manager that uses Rondevu for WebTorrent peer discovery via WebRTC.
|
|
@@ -61,6 +68,10 @@ export declare class RondevuConnectionManager {
|
|
|
61
68
|
* Initialize the connection manager by setting up event listeners and registering with rondevu
|
|
62
69
|
*/
|
|
63
70
|
private initialize;
|
|
71
|
+
/**
|
|
72
|
+
* Build the full topic string from an infoHash, applying the configured prefix if any
|
|
73
|
+
*/
|
|
74
|
+
private buildTopic;
|
|
64
75
|
/**
|
|
65
76
|
* Handle a torrent being added to the WebTorrent client
|
|
66
77
|
*/
|
|
@@ -19,6 +19,7 @@ export class RondevuConnectionManager {
|
|
|
19
19
|
refreshInterval: options.refreshInterval ?? 30000,
|
|
20
20
|
rtcConfig: options.rtcConfig,
|
|
21
21
|
wrtc: options.wrtc,
|
|
22
|
+
topicPrefix: options.topicPrefix ?? '',
|
|
22
23
|
};
|
|
23
24
|
this.rondevu = new Rondevu({
|
|
24
25
|
baseUrl: options.rondevuServer,
|
|
@@ -56,6 +57,12 @@ export class RondevuConnectionManager {
|
|
|
56
57
|
this.handleTorrentAdded(torrent);
|
|
57
58
|
});
|
|
58
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Build the full topic string from an infoHash, applying the configured prefix if any
|
|
62
|
+
*/
|
|
63
|
+
buildTopic(infoHash) {
|
|
64
|
+
return `${this.options.topicPrefix}${infoHash}`;
|
|
65
|
+
}
|
|
59
66
|
/**
|
|
60
67
|
* Handle a torrent being added to the WebTorrent client
|
|
61
68
|
*/
|
|
@@ -134,7 +141,7 @@ export class RondevuConnectionManager {
|
|
|
134
141
|
const peer = this.rondevu.createPeer(this.options.rtcConfig);
|
|
135
142
|
this.log(`Creating offer for torrent ${infoHash}`);
|
|
136
143
|
const offerId = await peer.createOffer({
|
|
137
|
-
topics: [infoHash],
|
|
144
|
+
topics: [this.buildTopic(infoHash)],
|
|
138
145
|
ttl: 300000, // 5 minutes in milliseconds
|
|
139
146
|
createDataChannel: true,
|
|
140
147
|
dataChannelLabel: 'webtorrent',
|
|
@@ -145,7 +152,7 @@ export class RondevuConnectionManager {
|
|
|
145
152
|
// Discover other peers' offers for this torrent
|
|
146
153
|
this.log(`Discovering peers for torrent ${infoHash}`);
|
|
147
154
|
const bloomFilter = this.torrentBloomFilters.get(infoHash);
|
|
148
|
-
const offers = await this.rondevu.offers.findByTopic(infoHash, {
|
|
155
|
+
const offers = await this.rondevu.offers.findByTopic(this.buildTopic(infoHash), {
|
|
149
156
|
limit: this.options.maxPeersPerTorrent - currentPeerCount,
|
|
150
157
|
bloomFilter: bloomFilter?.toBytes(),
|
|
151
158
|
});
|
|
@@ -167,7 +174,7 @@ export class RondevuConnectionManager {
|
|
|
167
174
|
const answerPeer = this.rondevu.createPeer(this.options.rtcConfig);
|
|
168
175
|
this.log(`Answering offer ${remoteOffer.id} for torrent ${infoHash}`);
|
|
169
176
|
await answerPeer.answer(remoteOffer.id, remoteOffer.sdp, {
|
|
170
|
-
topics: [infoHash],
|
|
177
|
+
topics: [this.buildTopic(infoHash)],
|
|
171
178
|
});
|
|
172
179
|
// Set up peer connection handlers
|
|
173
180
|
this.setupPeerHandlers(answerPeer, torrent, false);
|