@poolse/react-native 2.8.0 → 2.8.2

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
@@ -5236,6 +5236,12 @@ 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 isStalePush(sentAt, now, staleAfterMs) {
5240
+ if (typeof sentAt !== "number" || !Number.isFinite(sentAt)) return false;
5241
+ const age = now - sentAt;
5242
+ if (age < 0) return false;
5243
+ return age > staleAfterMs;
5244
+ }
5239
5245
  function useVoipCalls({
5240
5246
  voipPush,
5241
5247
  callKeep,
@@ -5244,15 +5250,15 @@ function useVoipCalls({
5244
5250
  onDecline,
5245
5251
  appName = "poolse",
5246
5252
  apnsEnvironment,
5247
- staleAfterMs = 45e3
5253
+ staleAfterMs = 12e4
5248
5254
  }) {
5249
5255
  const poolse = react$1.usePoolse();
5250
5256
  const shown = react.useRef(/* @__PURE__ */ new Map());
5251
- const seen = react.useRef(/* @__PURE__ */ new Set());
5252
5257
  const handlers = react.useRef({ onAnswer, onDecline, calls });
5253
5258
  handlers.current = { onAnswer, onDecline, calls };
5254
5259
  const staleRef = react.useRef(staleAfterMs);
5255
5260
  staleRef.current = staleAfterMs;
5261
+ const ready = react.useRef(Promise.resolve());
5256
5262
  const dismiss = react.useRef((callId) => {
5257
5263
  if (!shown.current.has(callId)) return;
5258
5264
  shown.current.delete(callId);
@@ -5262,11 +5268,21 @@ function useVoipCalls({
5262
5268
  }
5263
5269
  });
5264
5270
  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
5271
  shown.current.set(call.callId, call);
5269
- callKeep.displayIncomingCall(call.callId, call.callerUserId, call.callerName, "generic", false);
5272
+ const show = () => {
5273
+ try {
5274
+ callKeep.displayIncomingCall(
5275
+ call.callId,
5276
+ call.callerUserId,
5277
+ call.callerName,
5278
+ "generic",
5279
+ false
5280
+ );
5281
+ } catch {
5282
+ }
5283
+ };
5284
+ void ready.current.then(show, show);
5285
+ if (isStalePush(sentAt, Date.now(), staleRef.current)) dismiss.current(call.callId);
5270
5286
  });
5271
5287
  react.useEffect(() => {
5272
5288
  let cancelled = false;
@@ -5284,7 +5300,7 @@ function useVoipCalls({
5284
5300
  payload.sent_at
5285
5301
  );
5286
5302
  };
5287
- void callKeep.setup({
5303
+ ready.current = callKeep.setup({
5288
5304
  ios: { appName },
5289
5305
  android: {
5290
5306
  alertTitle: "Permissions required",
@@ -5316,8 +5332,11 @@ function useVoipCalls({
5316
5332
  }));
5317
5333
  callKeep.addEventListener("answerCall", (({ callUUID }) => {
5318
5334
  const call = shown.current.get(callUUID);
5319
- if (!call) return;
5320
5335
  shown.current.delete(callUUID);
5336
+ if (!call) {
5337
+ void handlers.current.calls?.accept();
5338
+ return;
5339
+ }
5321
5340
  void handlers.current.calls?.accept({
5322
5341
  callId: call.callId,
5323
5342
  conversationId: call.conversationId,
@@ -5328,7 +5347,10 @@ function useVoipCalls({
5328
5347
  callKeep.addEventListener("endCall", (({ callUUID }) => {
5329
5348
  const call = shown.current.get(callUUID);
5330
5349
  shown.current.delete(callUUID);
5331
- if (!call) return;
5350
+ if (!call) {
5351
+ void handlers.current.calls?.hangUp();
5352
+ return;
5353
+ }
5332
5354
  void handlers.current.calls?.decline({
5333
5355
  callId: call.callId,
5334
5356
  conversationId: call.conversationId,
@@ -5400,6 +5422,7 @@ exports.createNativeWebRtcAdapter = createNativeWebRtcAdapter;
5400
5422
  exports.defaultDarkTheme = defaultDarkTheme;
5401
5423
  exports.defaultLightTheme = defaultLightTheme;
5402
5424
  exports.isNativeWebRtcAvailable = isNativeWebRtcAvailable;
5425
+ exports.isStalePush = isStalePush;
5403
5426
  exports.useAppStateLifecycle = useAppStateLifecycle;
5404
5427
  exports.useDisplayName = useDisplayName;
5405
5428
  exports.usePoolseTheme = usePoolseTheme;