@poolse/sdk 2.21.0 → 2.22.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 CHANGED
@@ -962,6 +962,18 @@ var ConversationChannel = class {
962
962
  onMemberRead(fn) {
963
963
  return this.subscribe("member:read", fn);
964
964
  }
965
+ /** A call went live on this conversation (`call:started`). */
966
+ onCallStarted(fn) {
967
+ return this.subscribe("call:started", fn);
968
+ }
969
+ /** Someone joined or left the live call (`call:participants`): user ids in the room now. */
970
+ onCallParticipants(fn) {
971
+ return this.subscribe("call:participants", fn);
972
+ }
973
+ /** The call is over for everyone (`call:finished`). */
974
+ onCallFinished(fn) {
975
+ return this.subscribe("call:finished", fn);
976
+ }
965
977
  onPresenceState(fn) {
966
978
  let set = this.listeners.get("presence_state");
967
979
  if (!set) {
@@ -1659,6 +1671,28 @@ var CallTokensResource = class {
1659
1671
  }
1660
1672
  };
1661
1673
 
1674
+ // src/resources/live-calls.ts
1675
+ var LiveCallsResource = class {
1676
+ constructor(client) {
1677
+ this.client = client;
1678
+ }
1679
+ client;
1680
+ /** GET /v1/conversations/:conversationId/call — `null` when no call is live. */
1681
+ async get(conversationId, signal) {
1682
+ try {
1683
+ const res = await this.client.request({
1684
+ method: "GET",
1685
+ path: `/v1/conversations/${encodeURIComponent(conversationId)}/call`,
1686
+ ...signal ? { signal } : {}
1687
+ });
1688
+ return res.call.state === "live" ? res.call : null;
1689
+ } catch (err) {
1690
+ if (err instanceof ApiError && err.status === 404 && err.code === "no_live_call") return null;
1691
+ throw err;
1692
+ }
1693
+ }
1694
+ };
1695
+
1662
1696
  // src/voice/call-room.ts
1663
1697
  function toDevices(raw, kind) {
1664
1698
  const out = [];
@@ -2395,6 +2429,8 @@ var Poolse = class {
2395
2429
  iceServers;
2396
2430
  /** SFU credentials for a call's media — see `CallTokensResource`. */
2397
2431
  callTokens;
2432
+ /** Whether a call is running on a conversation — for a Join banner. */
2433
+ liveCalls;
2398
2434
  resolved;
2399
2435
  tokenCache;
2400
2436
  constructor(config) {
@@ -2413,6 +2449,7 @@ var Poolse = class {
2413
2449
  this.users = new UsersResource(cachedConfig);
2414
2450
  this.iceServers = new IceServersResource(this.rest);
2415
2451
  this.callTokens = new CallTokensResource(this.rest);
2452
+ this.liveCalls = new LiveCallsResource(this.rest);
2416
2453
  this.realtime = new PoolseRealtime(cachedConfig, this.tokenCache, {
2417
2454
  ...this.resolved.wsUrl !== void 0 ? { wsUrl: this.resolved.wsUrl } : {},
2418
2455
  socketPath: this.resolved.socketPath,
@@ -2455,7 +2492,7 @@ var Poolse = class {
2455
2492
  };
2456
2493
 
2457
2494
  // src/version.ts
2458
- var version = "2.20.0";
2495
+ var version = "2.22.0";
2459
2496
 
2460
2497
  // src/call-log.ts
2461
2498
  function parseCallLogBody(body) {
@@ -2477,12 +2514,25 @@ function parseCallLogBody(body) {
2477
2514
  const d = obj.duration_ms;
2478
2515
  const durationMs = typeof d === "number" && Number.isFinite(d) && d >= 0 ? d : null;
2479
2516
  const joined = Array.isArray(obj.joined_user_ids) ? obj.joined_user_ids.filter((u) => typeof u === "string") : [];
2517
+ const participants = Array.isArray(obj.participants) ? obj.participants.flatMap((p) => {
2518
+ if (!p || typeof p !== "object") return [];
2519
+ const { user_id: userId, status } = p;
2520
+ if (typeof userId !== "string" || !isParticipantStatus(status)) return [];
2521
+ return [{ userId, status }];
2522
+ }) : [];
2523
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
2480
2524
  return {
2481
2525
  kind: "call",
2482
2526
  callId,
2483
2527
  media: media ?? "audio",
2484
2528
  durationMs,
2485
- joinedUserIds: joined
2529
+ joinedUserIds: joined,
2530
+ version: obj.v === 2 ? 2 : 1,
2531
+ callerUserId: typeof obj.caller_user_id === "string" ? obj.caller_user_id : null,
2532
+ participants,
2533
+ endReason: isEndReason(obj.end_reason) ? obj.end_reason : null,
2534
+ startedAt: num(obj.started_at),
2535
+ endedAt: num(obj.ended_at)
2486
2536
  };
2487
2537
  }
2488
2538
  if (obj.kind === "call_missed") {
@@ -2491,6 +2541,12 @@ function parseCallLogBody(body) {
2491
2541
  }
2492
2542
  return null;
2493
2543
  }
2544
+ function isParticipantStatus(v) {
2545
+ return v === "joined" || v === "declined" || v === "busy" || v === "missed";
2546
+ }
2547
+ function isEndReason(v) {
2548
+ return v === "finished" || v === "declined_all" || v === "no_answer" || v === "cancelled";
2549
+ }
2494
2550
  function parseCallLog(message) {
2495
2551
  if (message.type !== "system" && message.type !== "custom") return null;
2496
2552
  if (message.deleted_at) return null;
@@ -2512,16 +2568,64 @@ function describeCallLog(log, currentUserId) {
2512
2568
  if (log.kind === "call_missed") {
2513
2569
  if (currentUserId === null || log.userId !== currentUserId) return null;
2514
2570
  const media = log.media ?? "audio";
2515
- return { media, title: "Missed call", detail: null, missed: true, summary: "Missed call" };
2571
+ return display(media, "Missed call", null, {
2572
+ missed: true,
2573
+ direction: "incoming",
2574
+ callBack: true
2575
+ });
2516
2576
  }
2517
- const title = log.media === "video" ? "Video call" : "Voice call";
2518
- const detail = log.durationMs !== null ? formatCallDuration(log.durationMs) : "No answer";
2577
+ const kind = log.media === "video" ? "video" : "voice";
2578
+ const duration = log.durationMs !== null ? formatCallDuration(log.durationMs) : null;
2579
+ const group = log.participants.length > 1;
2580
+ const me = currentUserId;
2581
+ const mine = me !== null ? log.participants.find((p) => p.userId === me) : void 0;
2582
+ const isCaller = me !== null && log.callerUserId === me;
2583
+ if (log.version === 1 || !isCaller && !mine) {
2584
+ const title = group ? `Group ${kind} call` : log.media === "video" ? "Video call" : "Voice call";
2585
+ return display(log.media, title, duration ?? "No answer", { direction: null, callBack: false });
2586
+ }
2587
+ if (isCaller) {
2588
+ const title = `Outgoing ${kind} call`;
2589
+ if (duration)
2590
+ return display(log.media, title, duration, { direction: "outgoing", callBack: false });
2591
+ const allBusy = log.participants.length > 0 && log.participants.every((p) => p.status === "busy");
2592
+ const detail = log.endReason === "cancelled" ? "Cancelled" : log.endReason === "declined_all" ? allBusy ? "Busy" : "Declined" : "No answer";
2593
+ return display(log.media, title, detail, { direction: "outgoing", callBack: true });
2594
+ }
2595
+ switch (mine.status) {
2596
+ case "joined":
2597
+ return display(log.media, group ? `Group ${kind} call` : `Incoming ${kind} call`, duration, {
2598
+ direction: "incoming",
2599
+ callBack: false
2600
+ });
2601
+ case "declined":
2602
+ return display(log.media, `Incoming ${kind} call`, "You declined", {
2603
+ direction: "incoming",
2604
+ callBack: true
2605
+ });
2606
+ case "busy":
2607
+ return display(log.media, `Missed ${kind} call`, "You were on another call", {
2608
+ missed: true,
2609
+ direction: "incoming",
2610
+ callBack: true
2611
+ });
2612
+ case "missed":
2613
+ return display(log.media, group ? `Missed group ${kind} call` : `Missed ${kind} call`, null, {
2614
+ missed: true,
2615
+ direction: "incoming",
2616
+ callBack: true
2617
+ });
2618
+ }
2619
+ }
2620
+ function display(media, title, detail, extra) {
2519
2621
  return {
2520
- media: log.media,
2622
+ media,
2521
2623
  title,
2522
2624
  detail,
2523
- missed: false,
2524
- summary: `${title} \xB7 ${detail}`
2625
+ missed: extra.missed ?? false,
2626
+ summary: detail ? `${title} \xB7 ${detail}` : title,
2627
+ direction: extra.direction,
2628
+ callBack: extra.callBack
2525
2629
  };
2526
2630
  }
2527
2631
  function callLogDisplayFor(message, currentUserId) {
@@ -2535,8 +2639,8 @@ function isMessageVisibleTo(message, currentUserId) {
2535
2639
  function formatCallLogPreview(preview, currentUserId) {
2536
2640
  const log = parseCallLogBody(preview);
2537
2641
  if (!log) return null;
2538
- const display = describeCallLog(log, currentUserId);
2539
- if (display) return display.summary;
2642
+ const display2 = describeCallLog(log, currentUserId);
2643
+ if (display2) return display2.summary;
2540
2644
  if (log.kind === "call_missed" && log.media) {
2541
2645
  return log.media === "video" ? "Video call" : "Voice call";
2542
2646
  }
@@ -2556,6 +2660,7 @@ exports.ConversationMessages = ConversationMessages;
2556
2660
  exports.ConversationsResource = ConversationsResource;
2557
2661
  exports.DevicesResource = DevicesResource;
2558
2662
  exports.IceServersResource = IceServersResource;
2663
+ exports.LiveCallsResource = LiveCallsResource;
2559
2664
  exports.MeResource = MeResource;
2560
2665
  exports.MessageHandle = MessageHandle;
2561
2666
  exports.MessagesResource = MessagesResource;