@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.d.cts CHANGED
@@ -1171,12 +1171,25 @@ interface VoipPushModule {
1171
1171
  addEventListener(event: string, handler: (payload: unknown) => void): void;
1172
1172
  removeEventListener(event: string): void;
1173
1173
  registerVoipToken(): void;
1174
+ /**
1175
+ * Releases the native PushKit completion handler for a push.
1176
+ *
1177
+ * iOS hands `didReceiveIncomingPushWith` a completion block and expects
1178
+ * it back once the call has been reported. Never calling it leaves the
1179
+ * app looking like it dropped the push, which is one of the ways iOS
1180
+ * stops delivering VoIP pushes to an app entirely.
1181
+ *
1182
+ * Optional because older versions of the module don't expose it.
1183
+ */
1184
+ onVoipNotificationCompleted?(uuid: string): void;
1174
1185
  }
1175
1186
  /** The slice of `react-native-callkeep` used here. */
1176
1187
  interface CallKeepModule {
1177
1188
  setup(options: unknown): Promise<unknown>;
1178
1189
  displayIncomingCall(uuid: string, handle: string, localizedCallerName?: string, handleType?: string, hasVideo?: boolean): unknown;
1179
1190
  endCall(uuid: string): unknown;
1191
+ /** Tell CallKit the call connected. Absent on older versions. */
1192
+ setCurrentCallActive?(uuid: string): unknown;
1180
1193
  addEventListener(event: string, handler: (payload: unknown) => void): void;
1181
1194
  removeEventListener(event: string): void;
1182
1195
  }
@@ -1217,9 +1230,13 @@ interface UseVoipCallsOptions {
1217
1230
  */
1218
1231
  apnsEnvironment?: 'production' | 'sandbox';
1219
1232
  /**
1220
- * How old a pushed call may be before it is ignored, in ms. Defaults
1221
- * to 45s, matching `useCalls`' ring timeout — past that the caller has
1222
- * already given up, so there is nothing live to answer.
1233
+ * How old a pushed call may be before it is reported and immediately
1234
+ * ended, in ms. Defaults to a deliberately generous 120s.
1235
+ *
1236
+ * The tight value this once used made clock skew between server and
1237
+ * handset enough to suppress live calls. The authoritative guard is
1238
+ * server-side anyway — accepting an ended call is refused — so this is
1239
+ * only here to spare the user a ring for something long dead.
1223
1240
  *
1224
1241
  * PushKit holds a push that lands before the JS bundle is up and
1225
1242
  * replays it on launch, so opening the app can ring you for a call the
@@ -1227,6 +1244,7 @@ interface UseVoipCallsOptions {
1227
1244
  */
1228
1245
  staleAfterMs?: number;
1229
1246
  }
1247
+ declare function isStalePush(sentAt: number | undefined, now: number, staleAfterMs: number): boolean;
1230
1248
  /**
1231
1249
  * Registers this device for VoIP pushes and drives the native call UI.
1232
1250
  *
@@ -1235,4 +1253,4 @@ interface UseVoipCallsOptions {
1235
1253
  */
1236
1254
  declare function useVoipCalls({ voipPush, callKeep, calls, onAnswer, onDecline, appName, apnsEnvironment, staleAfterMs, }: UseVoipCallsOptions): void;
1237
1255
 
1238
- export { AttachmentPicker, type AttachmentPickerProps, AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, type CallKeepModule, CallScreen, type CallScreenProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, DaySeparator, type DaySeparatorProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, ImageMosaic, type ImageMosaicProps, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, MessageList, type MessageListItem, type MessageListProps, MessageRow, type MessageRowProps, type NativeWebRtcModule, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, type PoolseRNTheme, type PoolseRNThemeOverrides, PoolseTheme, type PoolseThemeProps, primitives as Primitives, ReactionPicker, type ReactionPickerProps, ReactionStrip, type ReactionStripProps, type ThemeColors, type ThemeRadii, type ThemeShadows, type ThemeSpacing, type ThemeType, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, type UseVoipCallsOptions, UserName, type UserNameProps, VoiceRoomBar, type VoiceRoomBarProps, type VoipIncomingCall, type VoipPushModule, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
1256
+ export { AttachmentPicker, type AttachmentPickerProps, AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, type CallKeepModule, CallScreen, type CallScreenProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, DaySeparator, type DaySeparatorProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, ImageMosaic, type ImageMosaicProps, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, MessageList, type MessageListItem, type MessageListProps, MessageRow, type MessageRowProps, type NativeWebRtcModule, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, type PoolseRNTheme, type PoolseRNThemeOverrides, PoolseTheme, type PoolseThemeProps, primitives as Primitives, ReactionPicker, type ReactionPickerProps, ReactionStrip, type ReactionStripProps, type ThemeColors, type ThemeRadii, type ThemeShadows, type ThemeSpacing, type ThemeType, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, type UseVoipCallsOptions, UserName, type UserNameProps, VoiceRoomBar, type VoiceRoomBarProps, type VoipIncomingCall, type VoipPushModule, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, isStalePush, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
package/dist/index.d.ts CHANGED
@@ -1171,12 +1171,25 @@ interface VoipPushModule {
1171
1171
  addEventListener(event: string, handler: (payload: unknown) => void): void;
1172
1172
  removeEventListener(event: string): void;
1173
1173
  registerVoipToken(): void;
1174
+ /**
1175
+ * Releases the native PushKit completion handler for a push.
1176
+ *
1177
+ * iOS hands `didReceiveIncomingPushWith` a completion block and expects
1178
+ * it back once the call has been reported. Never calling it leaves the
1179
+ * app looking like it dropped the push, which is one of the ways iOS
1180
+ * stops delivering VoIP pushes to an app entirely.
1181
+ *
1182
+ * Optional because older versions of the module don't expose it.
1183
+ */
1184
+ onVoipNotificationCompleted?(uuid: string): void;
1174
1185
  }
1175
1186
  /** The slice of `react-native-callkeep` used here. */
1176
1187
  interface CallKeepModule {
1177
1188
  setup(options: unknown): Promise<unknown>;
1178
1189
  displayIncomingCall(uuid: string, handle: string, localizedCallerName?: string, handleType?: string, hasVideo?: boolean): unknown;
1179
1190
  endCall(uuid: string): unknown;
1191
+ /** Tell CallKit the call connected. Absent on older versions. */
1192
+ setCurrentCallActive?(uuid: string): unknown;
1180
1193
  addEventListener(event: string, handler: (payload: unknown) => void): void;
1181
1194
  removeEventListener(event: string): void;
1182
1195
  }
@@ -1217,9 +1230,13 @@ interface UseVoipCallsOptions {
1217
1230
  */
1218
1231
  apnsEnvironment?: 'production' | 'sandbox';
1219
1232
  /**
1220
- * How old a pushed call may be before it is ignored, in ms. Defaults
1221
- * to 45s, matching `useCalls`' ring timeout — past that the caller has
1222
- * already given up, so there is nothing live to answer.
1233
+ * How old a pushed call may be before it is reported and immediately
1234
+ * ended, in ms. Defaults to a deliberately generous 120s.
1235
+ *
1236
+ * The tight value this once used made clock skew between server and
1237
+ * handset enough to suppress live calls. The authoritative guard is
1238
+ * server-side anyway — accepting an ended call is refused — so this is
1239
+ * only here to spare the user a ring for something long dead.
1223
1240
  *
1224
1241
  * PushKit holds a push that lands before the JS bundle is up and
1225
1242
  * replays it on launch, so opening the app can ring you for a call the
@@ -1227,6 +1244,7 @@ interface UseVoipCallsOptions {
1227
1244
  */
1228
1245
  staleAfterMs?: number;
1229
1246
  }
1247
+ declare function isStalePush(sentAt: number | undefined, now: number, staleAfterMs: number): boolean;
1230
1248
  /**
1231
1249
  * Registers this device for VoIP pushes and drives the native call UI.
1232
1250
  *
@@ -1235,4 +1253,4 @@ interface UseVoipCallsOptions {
1235
1253
  */
1236
1254
  declare function useVoipCalls({ voipPush, callKeep, calls, onAnswer, onDecline, appName, apnsEnvironment, staleAfterMs, }: UseVoipCallsOptions): void;
1237
1255
 
1238
- export { AttachmentPicker, type AttachmentPickerProps, AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, type CallKeepModule, CallScreen, type CallScreenProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, DaySeparator, type DaySeparatorProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, ImageMosaic, type ImageMosaicProps, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, MessageList, type MessageListItem, type MessageListProps, MessageRow, type MessageRowProps, type NativeWebRtcModule, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, type PoolseRNTheme, type PoolseRNThemeOverrides, PoolseTheme, type PoolseThemeProps, primitives as Primitives, ReactionPicker, type ReactionPickerProps, ReactionStrip, type ReactionStripProps, type ThemeColors, type ThemeRadii, type ThemeShadows, type ThemeSpacing, type ThemeType, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, type UseVoipCallsOptions, UserName, type UserNameProps, VoiceRoomBar, type VoiceRoomBarProps, type VoipIncomingCall, type VoipPushModule, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
1256
+ export { AttachmentPicker, type AttachmentPickerProps, AttachmentPreview, type AttachmentPreviewProps, Avatar, type AvatarProps, type CallKeepModule, CallScreen, type CallScreenProps, ChatHeader, type ChatHeaderProps, ConversationList, type ConversationListProps, ConversationView, type ConversationViewProps, DaySeparator, type DaySeparatorProps, GroupDetailsSheet, type GroupDetailsSheetProps, type IconName, ImageMosaic, type ImageMosaicProps, type InboxUser, MemberList, type MemberListProps, MentionInput, type MentionInputProps, MessageActions, type MessageActionsProps, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerProps, MessageList, type MessageListItem, type MessageListProps, MessageRow, type MessageRowProps, type NativeWebRtcModule, PoolseIcon, type PoolseIconProps, PoolseInbox, type PoolseInboxHandle, type PoolseInboxProps, PoolseLogo, type PoolseLogoProps, type PoolseLogoVariant, type PoolseRNTheme, type PoolseRNThemeOverrides, PoolseTheme, type PoolseThemeProps, primitives as Primitives, ReactionPicker, type ReactionPickerProps, ReactionStrip, type ReactionStripProps, type ThemeColors, type ThemeRadii, type ThemeShadows, type ThemeSpacing, type ThemeType, ThreadView, type ThreadViewProps, TypingIndicator, type TypingIndicatorProps, UploadQueueStrip, type UseVoipCallsOptions, UserName, type UserNameProps, VoiceRoomBar, type VoiceRoomBarProps, type VoipIncomingCall, type VoipPushModule, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, isStalePush, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
package/dist/index.js CHANGED
@@ -5209,6 +5209,16 @@ var styles24 = StyleSheet.create({
5209
5209
  callBtnText: { color: "#ffffff", fontSize: 16, fontWeight: "600" },
5210
5210
  warn: { fontSize: 12, textAlign: "center", marginTop: 12 }
5211
5211
  });
5212
+ function isCallOver(phase) {
5213
+ if (phase === void 0) return false;
5214
+ return phase !== "ringing-in" && phase !== "ringing-out" && phase !== "active";
5215
+ }
5216
+ function isStalePush(sentAt, now, staleAfterMs) {
5217
+ if (typeof sentAt !== "number" || !Number.isFinite(sentAt)) return false;
5218
+ const age = now - sentAt;
5219
+ if (age < 0) return false;
5220
+ return age > staleAfterMs;
5221
+ }
5212
5222
  function useVoipCalls({
5213
5223
  voipPush,
5214
5224
  callKeep,
@@ -5217,15 +5227,15 @@ function useVoipCalls({
5217
5227
  onDecline,
5218
5228
  appName = "poolse",
5219
5229
  apnsEnvironment,
5220
- staleAfterMs = 45e3
5230
+ staleAfterMs = 12e4
5221
5231
  }) {
5222
5232
  const poolse = usePoolse();
5223
5233
  const shown = useRef(/* @__PURE__ */ new Map());
5224
- const seen = useRef(/* @__PURE__ */ new Set());
5225
5234
  const handlers = useRef({ onAnswer, onDecline, calls });
5226
5235
  handlers.current = { onAnswer, onDecline, calls };
5227
5236
  const staleRef = useRef(staleAfterMs);
5228
5237
  staleRef.current = staleAfterMs;
5238
+ const ready = useRef(Promise.resolve());
5229
5239
  const dismiss = useRef((callId) => {
5230
5240
  if (!shown.current.has(callId)) return;
5231
5241
  shown.current.delete(callId);
@@ -5235,11 +5245,28 @@ function useVoipCalls({
5235
5245
  }
5236
5246
  });
5237
5247
  const present = useRef((call, sentAt) => {
5238
- if (seen.current.has(call.callId)) return;
5239
- if (typeof sentAt === "number" && Date.now() - sentAt > staleRef.current) return;
5240
- seen.current.add(call.callId);
5241
5248
  shown.current.set(call.callId, call);
5242
- callKeep.displayIncomingCall(call.callId, call.callerUserId, call.callerName, "generic", false);
5249
+ const show = () => {
5250
+ try {
5251
+ callKeep.displayIncomingCall(
5252
+ call.callId,
5253
+ call.callerUserId,
5254
+ call.callerName,
5255
+ "generic",
5256
+ false
5257
+ );
5258
+ } catch {
5259
+ }
5260
+ };
5261
+ const done = () => {
5262
+ show();
5263
+ try {
5264
+ voipPush.onVoipNotificationCompleted?.(call.callId);
5265
+ } catch {
5266
+ }
5267
+ };
5268
+ void ready.current.then(done, done);
5269
+ if (isStalePush(sentAt, Date.now(), staleRef.current)) dismiss.current(call.callId);
5243
5270
  });
5244
5271
  useEffect(() => {
5245
5272
  let cancelled = false;
@@ -5257,7 +5284,7 @@ function useVoipCalls({
5257
5284
  payload.sent_at
5258
5285
  );
5259
5286
  };
5260
- void callKeep.setup({
5287
+ ready.current = callKeep.setup({
5261
5288
  ios: { appName },
5262
5289
  android: {
5263
5290
  alertTitle: "Permissions required",
@@ -5289,8 +5316,14 @@ function useVoipCalls({
5289
5316
  }));
5290
5317
  callKeep.addEventListener("answerCall", (({ callUUID }) => {
5291
5318
  const call = shown.current.get(callUUID);
5292
- if (!call) return;
5293
- shown.current.delete(callUUID);
5319
+ try {
5320
+ callKeep.setCurrentCallActive?.(callUUID);
5321
+ } catch {
5322
+ }
5323
+ if (!call) {
5324
+ void handlers.current.calls?.accept();
5325
+ return;
5326
+ }
5294
5327
  void handlers.current.calls?.accept({
5295
5328
  callId: call.callId,
5296
5329
  conversationId: call.conversationId,
@@ -5301,7 +5334,10 @@ function useVoipCalls({
5301
5334
  callKeep.addEventListener("endCall", (({ callUUID }) => {
5302
5335
  const call = shown.current.get(callUUID);
5303
5336
  shown.current.delete(callUUID);
5304
- if (!call) return;
5337
+ if (!call) {
5338
+ void handlers.current.calls?.hangUp();
5339
+ return;
5340
+ }
5305
5341
  void handlers.current.calls?.decline({
5306
5342
  callId: call.callId,
5307
5343
  conversationId: call.conversationId,
@@ -5332,7 +5368,7 @@ function useVoipCalls({
5332
5368
  }
5333
5369
  }, [phase, incoming]);
5334
5370
  useEffect(() => {
5335
- if (phase === "ringing-in" || phase === "ringing-out") return;
5371
+ if (!isCallOver(phase)) return;
5336
5372
  for (const callId of [...shown.current.keys()]) dismiss.current(callId);
5337
5373
  }, [phase]);
5338
5374
  }
@@ -5340,6 +5376,6 @@ function guessApnsEnvironment() {
5340
5376
  return __DEV__ ? "sandbox" : "production";
5341
5377
  }
5342
5378
 
5343
- export { AttachmentPicker, AttachmentPreview, Avatar, CallScreen, ChatHeader, ConversationList, ConversationView, DaySeparator, GroupDetailsSheet, ImageMosaic, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, MessageList, MessageRow, PoolseIcon, PoolseInbox, PoolseLogo, PoolseTheme, primitives as Primitives, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, VoiceRoomBar, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
5379
+ export { AttachmentPicker, AttachmentPreview, Avatar, CallScreen, ChatHeader, ConversationList, ConversationView, DaySeparator, GroupDetailsSheet, ImageMosaic, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, MessageList, MessageRow, PoolseIcon, PoolseInbox, PoolseLogo, PoolseTheme, primitives as Primitives, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, VoiceRoomBar, createNativeWebRtcAdapter, defaultDarkTheme, defaultLightTheme, isNativeWebRtcAvailable, isStalePush, useAppStateLifecycle, useDisplayName, usePoolseTheme, useVoipCalls };
5344
5380
  //# sourceMappingURL=index.js.map
5345
5381
  //# sourceMappingURL=index.js.map