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