@poolse/react-native 2.3.0 → 2.4.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 +76 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +76 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -5221,6 +5221,81 @@ var styles24 = reactNative.StyleSheet.create({
|
|
|
5221
5221
|
callBtnText: { color: "#ffffff", fontSize: 16, fontWeight: "600" },
|
|
5222
5222
|
warn: { fontSize: 12, textAlign: "center", marginTop: 12 }
|
|
5223
5223
|
});
|
|
5224
|
+
function useVoipCalls({
|
|
5225
|
+
voipPush,
|
|
5226
|
+
callKeep,
|
|
5227
|
+
onAnswer,
|
|
5228
|
+
onDecline,
|
|
5229
|
+
appName = "poolse"
|
|
5230
|
+
}) {
|
|
5231
|
+
const poolse = react$1.usePoolse();
|
|
5232
|
+
const pending = react.useRef(/* @__PURE__ */ new Map());
|
|
5233
|
+
const handlers = react.useRef({ onAnswer, onDecline });
|
|
5234
|
+
handlers.current = { onAnswer, onDecline };
|
|
5235
|
+
react.useEffect(() => {
|
|
5236
|
+
let cancelled = false;
|
|
5237
|
+
const reportCall = (payload) => {
|
|
5238
|
+
const callId = payload.call_id;
|
|
5239
|
+
const conversationId = payload.conversation_id;
|
|
5240
|
+
if (!callId || !conversationId) return;
|
|
5241
|
+
const call = {
|
|
5242
|
+
callId,
|
|
5243
|
+
conversationId,
|
|
5244
|
+
callerUserId: payload.caller_user_id ?? "",
|
|
5245
|
+
callerName: payload.caller_name ?? "Incoming call"
|
|
5246
|
+
};
|
|
5247
|
+
pending.current.set(callId, call);
|
|
5248
|
+
callKeep.displayIncomingCall(callId, call.callerUserId, call.callerName, "generic", false);
|
|
5249
|
+
};
|
|
5250
|
+
void callKeep.setup({
|
|
5251
|
+
ios: { appName },
|
|
5252
|
+
android: {
|
|
5253
|
+
alertTitle: "Permissions required",
|
|
5254
|
+
alertDescription: "Allow calls from this app",
|
|
5255
|
+
cancelButton: "Cancel",
|
|
5256
|
+
okButton: "ok",
|
|
5257
|
+
additionalPermissions: []
|
|
5258
|
+
}
|
|
5259
|
+
}).catch(() => {
|
|
5260
|
+
});
|
|
5261
|
+
voipPush.addEventListener("register", ((token) => {
|
|
5262
|
+
if (cancelled || !token) return;
|
|
5263
|
+
void poolse.devices.register({ token, platform: "ios", environment: apnsEnvironment() }).catch(() => {
|
|
5264
|
+
});
|
|
5265
|
+
}));
|
|
5266
|
+
voipPush.addEventListener("notification", ((payload) => {
|
|
5267
|
+
reportCall(payload);
|
|
5268
|
+
}));
|
|
5269
|
+
voipPush.addEventListener("didLoadWithEvents", ((events) => {
|
|
5270
|
+
for (const event of events ?? []) {
|
|
5271
|
+
if (event.name === "RNVoipPushRemoteNotificationReceivedEvent") {
|
|
5272
|
+
reportCall(event.data);
|
|
5273
|
+
}
|
|
5274
|
+
}
|
|
5275
|
+
}));
|
|
5276
|
+
callKeep.addEventListener("answerCall", (({ callUUID }) => {
|
|
5277
|
+
const call = pending.current.get(callUUID);
|
|
5278
|
+
if (call) handlers.current.onAnswer?.(call);
|
|
5279
|
+
}));
|
|
5280
|
+
callKeep.addEventListener("endCall", (({ callUUID }) => {
|
|
5281
|
+
const call = pending.current.get(callUUID);
|
|
5282
|
+
pending.current.delete(callUUID);
|
|
5283
|
+
if (call) handlers.current.onDecline?.(call);
|
|
5284
|
+
}));
|
|
5285
|
+
voipPush.registerVoipToken();
|
|
5286
|
+
return () => {
|
|
5287
|
+
cancelled = true;
|
|
5288
|
+
voipPush.removeEventListener("register");
|
|
5289
|
+
voipPush.removeEventListener("notification");
|
|
5290
|
+
voipPush.removeEventListener("didLoadWithEvents");
|
|
5291
|
+
callKeep.removeEventListener("answerCall");
|
|
5292
|
+
callKeep.removeEventListener("endCall");
|
|
5293
|
+
};
|
|
5294
|
+
}, [poolse, voipPush, callKeep, appName]);
|
|
5295
|
+
}
|
|
5296
|
+
function apnsEnvironment() {
|
|
5297
|
+
return __DEV__ ? "sandbox" : "production";
|
|
5298
|
+
}
|
|
5224
5299
|
|
|
5225
5300
|
exports.AttachmentPicker = AttachmentPicker;
|
|
5226
5301
|
exports.AttachmentPreview = AttachmentPreview;
|
|
@@ -5258,5 +5333,6 @@ exports.isNativeWebRtcAvailable = isNativeWebRtcAvailable;
|
|
|
5258
5333
|
exports.useAppStateLifecycle = useAppStateLifecycle;
|
|
5259
5334
|
exports.useDisplayName = useDisplayName;
|
|
5260
5335
|
exports.usePoolseTheme = usePoolseTheme;
|
|
5336
|
+
exports.useVoipCalls = useVoipCalls;
|
|
5261
5337
|
//# sourceMappingURL=index.cjs.map
|
|
5262
5338
|
//# sourceMappingURL=index.cjs.map
|