@poolse/sdk 2.8.3 → 2.9.0
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/dist/index.cjs +52 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -3
- package/dist/index.d.ts +55 -3
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -336,6 +336,7 @@ var VoiceRoom = class {
|
|
|
336
336
|
socket;
|
|
337
337
|
webrtc;
|
|
338
338
|
iceServers;
|
|
339
|
+
iceServersProvider;
|
|
339
340
|
detectSpeaking;
|
|
340
341
|
channel = null;
|
|
341
342
|
localStream = null;
|
|
@@ -367,6 +368,7 @@ var VoiceRoom = class {
|
|
|
367
368
|
this.socket = socket;
|
|
368
369
|
this.webrtc = opts.webrtc ?? createBrowserWebRtcAdapter();
|
|
369
370
|
this.iceServers = opts.iceServers ?? DEFAULT_ICE_SERVERS;
|
|
371
|
+
this.iceServersProvider = opts.iceServersProvider ?? null;
|
|
370
372
|
this.detectSpeaking = opts.detectSpeaking ?? true;
|
|
371
373
|
}
|
|
372
374
|
// ── observation ────────────────────────────────────────────────────
|
|
@@ -401,6 +403,7 @@ var VoiceRoom = class {
|
|
|
401
403
|
}
|
|
402
404
|
this.holders += 1;
|
|
403
405
|
this.setStatus("connecting");
|
|
406
|
+
await this.resolveIceServers();
|
|
404
407
|
try {
|
|
405
408
|
this.localStream = await this.webrtc.getUserMedia();
|
|
406
409
|
} catch (err) {
|
|
@@ -514,6 +517,23 @@ var VoiceRoom = class {
|
|
|
514
517
|
this.emitError(new Error(`voice error: ${payload?.reason ?? "unknown"}`));
|
|
515
518
|
});
|
|
516
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Refresh ICE servers from the provider, if there is one.
|
|
522
|
+
*
|
|
523
|
+
* Never throws. A room that refused to connect because the ICE
|
|
524
|
+
* endpoint was briefly unreachable would be a worse outcome than one
|
|
525
|
+
* that connects without TURN — which is exactly how calls behaved
|
|
526
|
+
* before TURN existed, and works on most networks.
|
|
527
|
+
*/
|
|
528
|
+
async resolveIceServers() {
|
|
529
|
+
if (!this.iceServersProvider) return;
|
|
530
|
+
try {
|
|
531
|
+
const servers = await this.iceServersProvider();
|
|
532
|
+
if (servers.length > 0) this.iceServers = servers;
|
|
533
|
+
} catch (err) {
|
|
534
|
+
this.emitError(new Error(`ice servers unavailable, continuing without: ${String(err)}`));
|
|
535
|
+
}
|
|
536
|
+
}
|
|
517
537
|
// ── negotiation ────────────────────────────────────────────────────
|
|
518
538
|
/**
|
|
519
539
|
* Glare control: both sides learn about each other simultaneously, so
|
|
@@ -696,6 +716,7 @@ var PoolseRealtime = class {
|
|
|
696
716
|
config;
|
|
697
717
|
tokenCache;
|
|
698
718
|
socketPath;
|
|
719
|
+
iceServersProvider;
|
|
699
720
|
wsUrl;
|
|
700
721
|
socket = null;
|
|
701
722
|
conversations = /* @__PURE__ */ new Map();
|
|
@@ -708,6 +729,7 @@ var PoolseRealtime = class {
|
|
|
708
729
|
this.config = config;
|
|
709
730
|
this.tokenCache = tokenCache;
|
|
710
731
|
this.socketPath = opts.socketPath ?? "/socket";
|
|
732
|
+
this.iceServersProvider = opts.iceServersProvider ?? null;
|
|
711
733
|
this.wsUrl = opts.wsUrl ?? deriveWsUrl(config.apiUrl);
|
|
712
734
|
}
|
|
713
735
|
/** Current connection status. */
|
|
@@ -833,7 +855,10 @@ var PoolseRealtime = class {
|
|
|
833
855
|
if (!this.socket) {
|
|
834
856
|
throw new PoolseError("socket not initialised \u2014 call connect() first");
|
|
835
857
|
}
|
|
836
|
-
const room = new VoiceRoom(conversationId, this.socket,
|
|
858
|
+
const room = new VoiceRoom(conversationId, this.socket, {
|
|
859
|
+
...this.iceServersProvider ? { iceServersProvider: this.iceServersProvider } : {},
|
|
860
|
+
...opts
|
|
861
|
+
});
|
|
837
862
|
this.voiceRooms.set(conversationId, room);
|
|
838
863
|
return room;
|
|
839
864
|
}
|
|
@@ -1597,6 +1622,22 @@ var UsersResource = class {
|
|
|
1597
1622
|
}
|
|
1598
1623
|
};
|
|
1599
1624
|
|
|
1625
|
+
// src/resources/ice-servers.ts
|
|
1626
|
+
var IceServersResource = class {
|
|
1627
|
+
constructor(client) {
|
|
1628
|
+
this.client = client;
|
|
1629
|
+
}
|
|
1630
|
+
client;
|
|
1631
|
+
/** GET /v1/ice-servers */
|
|
1632
|
+
list(signal) {
|
|
1633
|
+
return this.client.request({
|
|
1634
|
+
method: "GET",
|
|
1635
|
+
path: "/v1/ice-servers",
|
|
1636
|
+
...signal ? { signal } : {}
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
|
|
1600
1641
|
// src/rest-client.ts
|
|
1601
1642
|
var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET"]);
|
|
1602
1643
|
var RestClient = class {
|
|
@@ -1847,6 +1888,8 @@ var Poolse = class {
|
|
|
1847
1888
|
* `config.wsUrl`.
|
|
1848
1889
|
*/
|
|
1849
1890
|
realtime;
|
|
1891
|
+
/** STUN/TURN servers for WebRTC — see `IceServersResource`. */
|
|
1892
|
+
iceServers;
|
|
1850
1893
|
resolved;
|
|
1851
1894
|
tokenCache;
|
|
1852
1895
|
constructor(config) {
|
|
@@ -1863,9 +1906,14 @@ var Poolse = class {
|
|
|
1863
1906
|
this.messages = new MessagesResource(this.rest);
|
|
1864
1907
|
this.attachments = new AttachmentsResource(this.rest, cachedConfig.fetch);
|
|
1865
1908
|
this.users = new UsersResource(cachedConfig);
|
|
1909
|
+
this.iceServers = new IceServersResource(this.rest);
|
|
1866
1910
|
this.realtime = new PoolseRealtime(cachedConfig, this.tokenCache, {
|
|
1867
1911
|
...this.resolved.wsUrl !== void 0 ? { wsUrl: this.resolved.wsUrl } : {},
|
|
1868
|
-
socketPath: this.resolved.socketPath
|
|
1912
|
+
socketPath: this.resolved.socketPath,
|
|
1913
|
+
// Re-fetched on every room join rather than cached here: TURN
|
|
1914
|
+
// credentials expire, and a stale one is rejected silently — the
|
|
1915
|
+
// call connects and carries no media.
|
|
1916
|
+
iceServersProvider: async () => (await this.iceServers.list()).ice_servers
|
|
1869
1917
|
});
|
|
1870
1918
|
}
|
|
1871
1919
|
/**
|
|
@@ -1880,7 +1928,7 @@ var Poolse = class {
|
|
|
1880
1928
|
};
|
|
1881
1929
|
|
|
1882
1930
|
// src/version.ts
|
|
1883
|
-
var version = "2.
|
|
1931
|
+
var version = "2.9.0";
|
|
1884
1932
|
|
|
1885
1933
|
exports.ApiError = ApiError;
|
|
1886
1934
|
exports.AttachmentHandle = AttachmentHandle;
|
|
@@ -1892,6 +1940,7 @@ exports.ConversationHandle = ConversationHandle;
|
|
|
1892
1940
|
exports.ConversationMessages = ConversationMessages;
|
|
1893
1941
|
exports.ConversationsResource = ConversationsResource;
|
|
1894
1942
|
exports.DevicesResource = DevicesResource;
|
|
1943
|
+
exports.IceServersResource = IceServersResource;
|
|
1895
1944
|
exports.MeResource = MeResource;
|
|
1896
1945
|
exports.MessageHandle = MessageHandle;
|
|
1897
1946
|
exports.MessagesResource = MessagesResource;
|