libp2r2p 0.10.24 → 0.10.25

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": "libp2r2p",
3
- "version": "0.10.24",
3
+ "version": "0.10.25",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",
@@ -136,13 +136,23 @@ export class RelayPool {
136
136
  #liveSubCounts = new Map() // url -> number of active live subscriptions
137
137
  #timeout = 30000 // 30 seconds
138
138
  #createRelay
139
+ #WebSocket
139
140
  #admission
140
141
 
141
- constructor ({ _createRelay = url => new RelayConnection(url), ...capacity } = {}) {
142
- this.#createRelay = _createRelay
142
+ constructor ({ _createRelay, WebSocket: WebSocketImpl, ...capacity } = {}) {
143
+ this.#WebSocket = WebSocketImpl
144
+ this.#createRelay = _createRelay ?? (url => new RelayConnection(url, this.#WebSocket ? { WebSocket: this.#WebSocket } : undefined))
143
145
  this.#admission = new ReadAdmission(capacity)
144
146
  }
145
147
 
148
+ // Injects the WebSocket implementation used by new pooled connections (e.g.
149
+ // a launcher-owned relay multiplexer). Existing connections keep the
150
+ // implementation they were created with.
151
+ setWebSocket (WebSocketImpl) {
152
+ if (typeof WebSocketImpl !== 'function') throw new ValidationError('INVALID_WEBSOCKET_IMPLEMENTATION')
153
+ this.#WebSocket = WebSocketImpl
154
+ }
155
+
146
156
  #scheduleIdleDisconnect (url) {
147
157
  clearTimeout(this.#relayTimeouts.get(url))
148
158
  this.#relayTimeouts.set(url, maybeUnref(setTimeout(() => {