@poolse/sdk 2.7.0 → 2.8.1

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 CHANGED
@@ -114,6 +114,7 @@ var CallsResource = class {
114
114
  declined = /* @__PURE__ */ new Set();
115
115
  busy = /* @__PURE__ */ new Set();
116
116
  cancelled = /* @__PURE__ */ new Set();
117
+ ended = /* @__PURE__ */ new Set();
117
118
  bound = false;
118
119
  constructor(getChannel) {
119
120
  this.getChannel = getChannel;
@@ -166,6 +167,20 @@ var CallsResource = class {
166
167
  caller_user_id: call.callerUserId
167
168
  });
168
169
  }
170
+ /**
171
+ * End a call that is already connected.
172
+ *
173
+ * Distinct from {@link cancel}, which withdraws an unanswered invite.
174
+ * Without this a connected call has no end signal, so hanging up
175
+ * leaves the other side sitting in the room with a call screen it has
176
+ * no reason to close.
177
+ */
178
+ async hangUp(call) {
179
+ await this.request("call:hangup", {
180
+ call_id: call.callId,
181
+ conversation_id: call.conversationId
182
+ });
183
+ }
169
184
  /** Withdraw an invite you placed — hung up before anyone answered. */
170
185
  async cancel(call) {
171
186
  await this.request("call:cancel", {
@@ -198,6 +213,12 @@ var CallsResource = class {
198
213
  this.busy.add(fn);
199
214
  return () => this.busy.delete(fn);
200
215
  }
216
+ /** The other side ended a connected call. */
217
+ onEnded(fn) {
218
+ this.bind();
219
+ this.ended.add(fn);
220
+ return () => this.ended.delete(fn);
221
+ }
201
222
  /** An inbound ring was withdrawn before you answered. */
202
223
  onCancelled(fn) {
203
224
  this.bind();
@@ -245,6 +266,14 @@ var CallsResource = class {
245
266
  };
246
267
  this.busy.forEach((l) => l(call));
247
268
  });
269
+ channel.on("call:ended", (p) => {
270
+ const call = {
271
+ callId: p.call_id,
272
+ conversationId: p.conversation_id,
273
+ userId: p.user_id
274
+ };
275
+ this.ended.forEach((l) => l(call));
276
+ });
248
277
  channel.on("call:cancelled", (p) => {
249
278
  const call = {
250
279
  callId: p.call_id,
@@ -318,6 +347,16 @@ var VoiceRoom = class {
318
347
  /** Candidates that landed before their offer/answer did. */
319
348
  pendingIce = /* @__PURE__ */ new Map();
320
349
  roster = /* @__PURE__ */ new Map();
350
+ /**
351
+ * How many callers currently hold this room open.
352
+ *
353
+ * `PoolseRealtime` hands out ONE room per conversation, so a call
354
+ * screen and an always-on voice bar for the same conversation share
355
+ * this instance — which is correct, since a user is in one audio
356
+ * session, not two. Without counting, whichever of them tore down
357
+ * first would cut the audio out from under the other.
358
+ */
359
+ holders = 0;
321
360
  speakingTimer = null;
322
361
  stopSpeakingDetection = null;
323
362
  statusListeners = /* @__PURE__ */ new Set();
@@ -356,11 +395,16 @@ var VoiceRoom = class {
356
395
  // ── lifecycle ──────────────────────────────────────────────────────
357
396
  /** Acquire the mic, join the channel, and start negotiating. */
358
397
  async join() {
359
- if (this.channel) return;
398
+ if (this.channel) {
399
+ this.holders += 1;
400
+ return;
401
+ }
402
+ this.holders += 1;
360
403
  this.setStatus("connecting");
361
404
  try {
362
405
  this.localStream = await this.webrtc.getUserMedia();
363
406
  } catch (err) {
407
+ this.holders = Math.max(0, this.holders - 1);
364
408
  this.setStatus("error");
365
409
  this.emitError(new Error(`microphone unavailable: ${String(err)}`));
366
410
  throw err;
@@ -389,6 +433,8 @@ var VoiceRoom = class {
389
433
  }
390
434
  /** Announce departure, then drop every peer connection and the mic. */
391
435
  leave() {
436
+ if (this.holders > 0) this.holders -= 1;
437
+ if (this.holders > 0) return;
392
438
  this.channel?.push("voice:leave", {});
393
439
  this.teardown();
394
440
  this.setStatus("idle");
@@ -609,6 +655,7 @@ var VoiceRoom = class {
609
655
  this.pendingIce.delete(peerId);
610
656
  }
611
657
  teardown() {
658
+ this.holders = 0;
612
659
  for (const peerId of [...this.peers.keys()]) this.closePeer(peerId);
613
660
  if (this.speakingTimer) clearInterval(this.speakingTimer);
614
661
  this.speakingTimer = null;
@@ -1833,7 +1880,7 @@ var Poolse = class {
1833
1880
  };
1834
1881
 
1835
1882
  // src/version.ts
1836
- var version = "2.7.0";
1883
+ var version = "2.8.1";
1837
1884
 
1838
1885
  exports.ApiError = ApiError;
1839
1886
  exports.AttachmentHandle = AttachmentHandle;