@poolse/react-native 2.8.1 → 2.8.3
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 +48 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +48 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -5236,6 +5236,16 @@ var styles24 = reactNative.StyleSheet.create({
|
|
|
5236
5236
|
callBtnText: { color: "#ffffff", fontSize: 16, fontWeight: "600" },
|
|
5237
5237
|
warn: { fontSize: 12, textAlign: "center", marginTop: 12 }
|
|
5238
5238
|
});
|
|
5239
|
+
function isCallOver(phase) {
|
|
5240
|
+
if (phase === void 0) return false;
|
|
5241
|
+
return phase !== "ringing-in" && phase !== "ringing-out" && phase !== "active";
|
|
5242
|
+
}
|
|
5243
|
+
function isStalePush(sentAt, now, staleAfterMs) {
|
|
5244
|
+
if (typeof sentAt !== "number" || !Number.isFinite(sentAt)) return false;
|
|
5245
|
+
const age = now - sentAt;
|
|
5246
|
+
if (age < 0) return false;
|
|
5247
|
+
return age > staleAfterMs;
|
|
5248
|
+
}
|
|
5239
5249
|
function useVoipCalls({
|
|
5240
5250
|
voipPush,
|
|
5241
5251
|
callKeep,
|
|
@@ -5244,15 +5254,15 @@ function useVoipCalls({
|
|
|
5244
5254
|
onDecline,
|
|
5245
5255
|
appName = "poolse",
|
|
5246
5256
|
apnsEnvironment,
|
|
5247
|
-
staleAfterMs =
|
|
5257
|
+
staleAfterMs = 12e4
|
|
5248
5258
|
}) {
|
|
5249
5259
|
const poolse = react$1.usePoolse();
|
|
5250
5260
|
const shown = react.useRef(/* @__PURE__ */ new Map());
|
|
5251
|
-
const seen = react.useRef(/* @__PURE__ */ new Set());
|
|
5252
5261
|
const handlers = react.useRef({ onAnswer, onDecline, calls });
|
|
5253
5262
|
handlers.current = { onAnswer, onDecline, calls };
|
|
5254
5263
|
const staleRef = react.useRef(staleAfterMs);
|
|
5255
5264
|
staleRef.current = staleAfterMs;
|
|
5265
|
+
const ready = react.useRef(Promise.resolve());
|
|
5256
5266
|
const dismiss = react.useRef((callId) => {
|
|
5257
5267
|
if (!shown.current.has(callId)) return;
|
|
5258
5268
|
shown.current.delete(callId);
|
|
@@ -5262,11 +5272,28 @@ function useVoipCalls({
|
|
|
5262
5272
|
}
|
|
5263
5273
|
});
|
|
5264
5274
|
const present = react.useRef((call, sentAt) => {
|
|
5265
|
-
if (seen.current.has(call.callId)) return;
|
|
5266
|
-
if (typeof sentAt === "number" && Date.now() - sentAt > staleRef.current) return;
|
|
5267
|
-
seen.current.add(call.callId);
|
|
5268
5275
|
shown.current.set(call.callId, call);
|
|
5269
|
-
|
|
5276
|
+
const show = () => {
|
|
5277
|
+
try {
|
|
5278
|
+
callKeep.displayIncomingCall(
|
|
5279
|
+
call.callId,
|
|
5280
|
+
call.callerUserId,
|
|
5281
|
+
call.callerName,
|
|
5282
|
+
"generic",
|
|
5283
|
+
false
|
|
5284
|
+
);
|
|
5285
|
+
} catch {
|
|
5286
|
+
}
|
|
5287
|
+
};
|
|
5288
|
+
const done = () => {
|
|
5289
|
+
show();
|
|
5290
|
+
try {
|
|
5291
|
+
voipPush.onVoipNotificationCompleted?.(call.callId);
|
|
5292
|
+
} catch {
|
|
5293
|
+
}
|
|
5294
|
+
};
|
|
5295
|
+
void ready.current.then(done, done);
|
|
5296
|
+
if (isStalePush(sentAt, Date.now(), staleRef.current)) dismiss.current(call.callId);
|
|
5270
5297
|
});
|
|
5271
5298
|
react.useEffect(() => {
|
|
5272
5299
|
let cancelled = false;
|
|
@@ -5284,7 +5311,7 @@ function useVoipCalls({
|
|
|
5284
5311
|
payload.sent_at
|
|
5285
5312
|
);
|
|
5286
5313
|
};
|
|
5287
|
-
|
|
5314
|
+
ready.current = callKeep.setup({
|
|
5288
5315
|
ios: { appName },
|
|
5289
5316
|
android: {
|
|
5290
5317
|
alertTitle: "Permissions required",
|
|
@@ -5316,8 +5343,14 @@ function useVoipCalls({
|
|
|
5316
5343
|
}));
|
|
5317
5344
|
callKeep.addEventListener("answerCall", (({ callUUID }) => {
|
|
5318
5345
|
const call = shown.current.get(callUUID);
|
|
5319
|
-
|
|
5320
|
-
|
|
5346
|
+
try {
|
|
5347
|
+
callKeep.setCurrentCallActive?.(callUUID);
|
|
5348
|
+
} catch {
|
|
5349
|
+
}
|
|
5350
|
+
if (!call) {
|
|
5351
|
+
void handlers.current.calls?.accept();
|
|
5352
|
+
return;
|
|
5353
|
+
}
|
|
5321
5354
|
void handlers.current.calls?.accept({
|
|
5322
5355
|
callId: call.callId,
|
|
5323
5356
|
conversationId: call.conversationId,
|
|
@@ -5328,7 +5361,10 @@ function useVoipCalls({
|
|
|
5328
5361
|
callKeep.addEventListener("endCall", (({ callUUID }) => {
|
|
5329
5362
|
const call = shown.current.get(callUUID);
|
|
5330
5363
|
shown.current.delete(callUUID);
|
|
5331
|
-
if (!call)
|
|
5364
|
+
if (!call) {
|
|
5365
|
+
void handlers.current.calls?.hangUp();
|
|
5366
|
+
return;
|
|
5367
|
+
}
|
|
5332
5368
|
void handlers.current.calls?.decline({
|
|
5333
5369
|
callId: call.callId,
|
|
5334
5370
|
conversationId: call.conversationId,
|
|
@@ -5359,7 +5395,7 @@ function useVoipCalls({
|
|
|
5359
5395
|
}
|
|
5360
5396
|
}, [phase, incoming]);
|
|
5361
5397
|
react.useEffect(() => {
|
|
5362
|
-
if (phase
|
|
5398
|
+
if (!isCallOver(phase)) return;
|
|
5363
5399
|
for (const callId of [...shown.current.keys()]) dismiss.current(callId);
|
|
5364
5400
|
}, [phase]);
|
|
5365
5401
|
}
|
|
@@ -5400,6 +5436,7 @@ exports.createNativeWebRtcAdapter = createNativeWebRtcAdapter;
|
|
|
5400
5436
|
exports.defaultDarkTheme = defaultDarkTheme;
|
|
5401
5437
|
exports.defaultLightTheme = defaultLightTheme;
|
|
5402
5438
|
exports.isNativeWebRtcAvailable = isNativeWebRtcAvailable;
|
|
5439
|
+
exports.isStalePush = isStalePush;
|
|
5403
5440
|
exports.useAppStateLifecycle = useAppStateLifecycle;
|
|
5404
5441
|
exports.useDisplayName = useDisplayName;
|
|
5405
5442
|
exports.usePoolseTheme = usePoolseTheme;
|