@poolse/sdk 2.20.0 → 2.21.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 +94 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +87 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2457,6 +2457,92 @@ var Poolse = class {
|
|
|
2457
2457
|
// src/version.ts
|
|
2458
2458
|
var version = "2.20.0";
|
|
2459
2459
|
|
|
2460
|
+
// src/call-log.ts
|
|
2461
|
+
function parseCallLogBody(body) {
|
|
2462
|
+
if (typeof body !== "string") return null;
|
|
2463
|
+
const trimmed = body.trim();
|
|
2464
|
+
if (!trimmed.startsWith("{") || !trimmed.includes('"kind"')) return null;
|
|
2465
|
+
let raw;
|
|
2466
|
+
try {
|
|
2467
|
+
raw = JSON.parse(trimmed);
|
|
2468
|
+
} catch {
|
|
2469
|
+
return null;
|
|
2470
|
+
}
|
|
2471
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
2472
|
+
const obj = raw;
|
|
2473
|
+
const callId = typeof obj.call_id === "string" ? obj.call_id : null;
|
|
2474
|
+
if (!callId) return null;
|
|
2475
|
+
const media = obj.media === "audio" || obj.media === "video" ? obj.media : null;
|
|
2476
|
+
if (obj.kind === "call") {
|
|
2477
|
+
const d = obj.duration_ms;
|
|
2478
|
+
const durationMs = typeof d === "number" && Number.isFinite(d) && d >= 0 ? d : null;
|
|
2479
|
+
const joined = Array.isArray(obj.joined_user_ids) ? obj.joined_user_ids.filter((u) => typeof u === "string") : [];
|
|
2480
|
+
return {
|
|
2481
|
+
kind: "call",
|
|
2482
|
+
callId,
|
|
2483
|
+
media: media ?? "audio",
|
|
2484
|
+
durationMs,
|
|
2485
|
+
joinedUserIds: joined
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
if (obj.kind === "call_missed") {
|
|
2489
|
+
if (typeof obj.user_id !== "string" || obj.user_id === "") return null;
|
|
2490
|
+
return { kind: "call_missed", callId, userId: obj.user_id, media };
|
|
2491
|
+
}
|
|
2492
|
+
return null;
|
|
2493
|
+
}
|
|
2494
|
+
function parseCallLog(message) {
|
|
2495
|
+
if (message.type !== "system" && message.type !== "custom") return null;
|
|
2496
|
+
if (message.deleted_at) return null;
|
|
2497
|
+
return parseCallLogBody(message.body);
|
|
2498
|
+
}
|
|
2499
|
+
function isCallLogMessage(message) {
|
|
2500
|
+
return parseCallLog(message) !== null;
|
|
2501
|
+
}
|
|
2502
|
+
function formatCallDuration(ms) {
|
|
2503
|
+
const total = Math.max(0, Math.round(ms / 1e3));
|
|
2504
|
+
const h = Math.floor(total / 3600);
|
|
2505
|
+
const m = Math.floor(total % 3600 / 60);
|
|
2506
|
+
const s = total % 60;
|
|
2507
|
+
const ss = String(s).padStart(2, "0");
|
|
2508
|
+
if (h > 0) return `${h}:${String(m).padStart(2, "0")}:${ss}`;
|
|
2509
|
+
return `${m}:${ss}`;
|
|
2510
|
+
}
|
|
2511
|
+
function describeCallLog(log, currentUserId) {
|
|
2512
|
+
if (log.kind === "call_missed") {
|
|
2513
|
+
if (currentUserId === null || log.userId !== currentUserId) return null;
|
|
2514
|
+
const media = log.media ?? "audio";
|
|
2515
|
+
return { media, title: "Missed call", detail: null, missed: true, summary: "Missed call" };
|
|
2516
|
+
}
|
|
2517
|
+
const title = log.media === "video" ? "Video call" : "Voice call";
|
|
2518
|
+
const detail = log.durationMs !== null ? formatCallDuration(log.durationMs) : "No answer";
|
|
2519
|
+
return {
|
|
2520
|
+
media: log.media,
|
|
2521
|
+
title,
|
|
2522
|
+
detail,
|
|
2523
|
+
missed: false,
|
|
2524
|
+
summary: `${title} \xB7 ${detail}`
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
function callLogDisplayFor(message, currentUserId) {
|
|
2528
|
+
const log = parseCallLog(message);
|
|
2529
|
+
if (!log) return void 0;
|
|
2530
|
+
return describeCallLog(log, currentUserId);
|
|
2531
|
+
}
|
|
2532
|
+
function isMessageVisibleTo(message, currentUserId) {
|
|
2533
|
+
return callLogDisplayFor(message, currentUserId) !== null;
|
|
2534
|
+
}
|
|
2535
|
+
function formatCallLogPreview(preview, currentUserId) {
|
|
2536
|
+
const log = parseCallLogBody(preview);
|
|
2537
|
+
if (!log) return null;
|
|
2538
|
+
const display = describeCallLog(log, currentUserId);
|
|
2539
|
+
if (display) return display.summary;
|
|
2540
|
+
if (log.kind === "call_missed" && log.media) {
|
|
2541
|
+
return log.media === "video" ? "Video call" : "Voice call";
|
|
2542
|
+
}
|
|
2543
|
+
return "Call";
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2460
2546
|
exports.ApiError = ApiError;
|
|
2461
2547
|
exports.AttachmentHandle = AttachmentHandle;
|
|
2462
2548
|
exports.AttachmentsResource = AttachmentsResource;
|
|
@@ -2482,8 +2568,16 @@ exports.RateLimitedError = RateLimitedError;
|
|
|
2482
2568
|
exports.UserChannel = UserChannel;
|
|
2483
2569
|
exports.UsersResource = UsersResource;
|
|
2484
2570
|
exports.VoiceRoom = VoiceRoom;
|
|
2571
|
+
exports.callLogDisplayFor = callLogDisplayFor;
|
|
2485
2572
|
exports.createBrowserWebRtcAdapter = createBrowserWebRtcAdapter;
|
|
2573
|
+
exports.describeCallLog = describeCallLog;
|
|
2574
|
+
exports.formatCallDuration = formatCallDuration;
|
|
2575
|
+
exports.formatCallLogPreview = formatCallLogPreview;
|
|
2576
|
+
exports.isCallLogMessage = isCallLogMessage;
|
|
2577
|
+
exports.isMessageVisibleTo = isMessageVisibleTo;
|
|
2486
2578
|
exports.isWebRtcAvailable = isWebRtcAvailable;
|
|
2579
|
+
exports.parseCallLog = parseCallLog;
|
|
2580
|
+
exports.parseCallLogBody = parseCallLogBody;
|
|
2487
2581
|
exports.safeUuid = safeUuid;
|
|
2488
2582
|
exports.version = version;
|
|
2489
2583
|
//# sourceMappingURL=index.cjs.map
|