@cobbai/react-native-sdk 1.0.0-beta.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/CobbaiMobileRnSdk.podspec +22 -0
- package/LICENSE +32 -0
- package/README.md +386 -0
- package/dist/ChatPlaceholder.d.ts +13 -0
- package/dist/ChatPlaceholder.d.ts.map +1 -0
- package/dist/ChatPlaceholder.js +87 -0
- package/dist/CobbaiChatScreen.d.ts +4 -0
- package/dist/CobbaiChatScreen.d.ts.map +1 -0
- package/dist/CobbaiChatScreen.js +196 -0
- package/dist/CobbaiInAppBanner.d.ts +15 -0
- package/dist/CobbaiInAppBanner.d.ts.map +1 -0
- package/dist/CobbaiInAppBanner.js +159 -0
- package/dist/CobbaiLauncher.d.ts +19 -0
- package/dist/CobbaiLauncher.d.ts.map +1 -0
- package/dist/CobbaiLauncher.js +149 -0
- package/dist/CobbaiWebView.d.ts +28 -0
- package/dist/CobbaiWebView.d.ts.map +1 -0
- package/dist/CobbaiWebView.js +141 -0
- package/dist/adapters/expoAdapter.d.ts +85 -0
- package/dist/adapters/expoAdapter.d.ts.map +1 -0
- package/dist/adapters/expoAdapter.js +152 -0
- package/dist/adapters/firebaseAdapter.d.ts +41 -0
- package/dist/adapters/firebaseAdapter.d.ts.map +1 -0
- package/dist/adapters/firebaseAdapter.js +139 -0
- package/dist/adapters/iosRelayAdapter.d.ts +26 -0
- package/dist/adapters/iosRelayAdapter.d.ts.map +1 -0
- package/dist/adapters/iosRelayAdapter.js +101 -0
- package/dist/androidKeyboardFrame.d.ts +16 -0
- package/dist/androidKeyboardFrame.d.ts.map +1 -0
- package/dist/androidKeyboardFrame.js +34 -0
- package/dist/bridge/messages.d.ts +20 -0
- package/dist/bridge/messages.d.ts.map +1 -0
- package/dist/bridge/messages.js +20 -0
- package/dist/bridge/nativeEvent.d.ts +10 -0
- package/dist/bridge/nativeEvent.d.ts.map +1 -0
- package/dist/bridge/nativeEvent.js +15 -0
- package/dist/bridge/parser.d.ts +29 -0
- package/dist/bridge/parser.d.ts.map +1 -0
- package/dist/bridge/parser.js +109 -0
- package/dist/chatPresentation.d.ts +19 -0
- package/dist/chatPresentation.d.ts.map +1 -0
- package/dist/chatPresentation.js +51 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts +22 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts.map +1 -0
- package/dist/chatScreen/useInAppBannerQueue.js +60 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts +14 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts.map +1 -0
- package/dist/chatScreen/useKeyboardFrame.js +63 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts +20 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useLauncherPresentation.js +76 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts +17 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts.map +1 -0
- package/dist/chatScreen/useNativeToWebSync.js +36 -0
- package/dist/chatScreen/usePushIntegration.d.ts +19 -0
- package/dist/chatScreen/usePushIntegration.d.ts.map +1 -0
- package/dist/chatScreen/usePushIntegration.js +129 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts +33 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts.map +1 -0
- package/dist/chatScreen/useReadyLifecycle.js +138 -0
- package/dist/chatScreen/useSheetPresentation.d.ts +25 -0
- package/dist/chatScreen/useSheetPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useSheetPresentation.js +98 -0
- package/dist/chatUnavailable.d.ts +23 -0
- package/dist/chatUnavailable.d.ts.map +1 -0
- package/dist/chatUnavailable.js +36 -0
- package/dist/externalLinks.d.ts +4 -0
- package/dist/externalLinks.d.ts.map +1 -0
- package/dist/externalLinks.js +48 -0
- package/dist/host/buildHostHtml.d.ts +7 -0
- package/dist/host/buildHostHtml.d.ts.map +1 -0
- package/dist/host/buildHostHtml.js +101 -0
- package/dist/host/hostPageKey.d.ts +7 -0
- package/dist/host/hostPageKey.d.ts.map +1 -0
- package/dist/host/hostPageKey.js +18 -0
- package/dist/inAppBanner.d.ts +19 -0
- package/dist/inAppBanner.d.ts.map +1 -0
- package/dist/inAppBanner.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/launcher.d.ts +25 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +55 -0
- package/dist/launcherGlyph.d.ts +2 -0
- package/dist/launcherGlyph.d.ts.map +1 -0
- package/dist/launcherGlyph.js +5 -0
- package/dist/openChatScreen.d.ts +13 -0
- package/dist/openChatScreen.d.ts.map +1 -0
- package/dist/openChatScreen.js +63 -0
- package/dist/push.d.ts +59 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +309 -0
- package/dist/pushIntegration.d.ts +76 -0
- package/dist/pushIntegration.d.ts.map +1 -0
- package/dist/pushIntegration.js +244 -0
- package/dist/pushLogout.d.ts +57 -0
- package/dist/pushLogout.d.ts.map +1 -0
- package/dist/pushLogout.js +225 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/ios/CobbaiPush.m +96 -0
- package/ios/CobbaiPushRelay.h +59 -0
- package/ios/CobbaiPushRelay.m +364 -0
- package/package.json +69 -0
- package/src/ChatPlaceholder.tsx +132 -0
- package/src/CobbaiChatScreen.tsx +348 -0
- package/src/CobbaiInAppBanner.tsx +237 -0
- package/src/CobbaiLauncher.tsx +223 -0
- package/src/CobbaiWebView.tsx +242 -0
- package/src/adapters/expoAdapter.ts +227 -0
- package/src/adapters/firebaseAdapter.ts +201 -0
- package/src/adapters/iosRelayAdapter.ts +137 -0
- package/src/androidKeyboardFrame.ts +56 -0
- package/src/bridge/messages.ts +24 -0
- package/src/bridge/nativeEvent.ts +12 -0
- package/src/bridge/parser.ts +159 -0
- package/src/chatPresentation.ts +73 -0
- package/src/chatScreen/useInAppBannerQueue.ts +91 -0
- package/src/chatScreen/useKeyboardFrame.ts +89 -0
- package/src/chatScreen/useLauncherPresentation.ts +121 -0
- package/src/chatScreen/useNativeToWebSync.ts +54 -0
- package/src/chatScreen/usePushIntegration.ts +191 -0
- package/src/chatScreen/useReadyLifecycle.ts +186 -0
- package/src/chatScreen/useSheetPresentation.ts +147 -0
- package/src/chatUnavailable.ts +58 -0
- package/src/externalLinks.ts +56 -0
- package/src/host/buildHostHtml.ts +117 -0
- package/src/host/hostPageKey.ts +17 -0
- package/src/inAppBanner.ts +58 -0
- package/src/index.ts +53 -0
- package/src/launcher.ts +79 -0
- package/src/launcherGlyph.ts +3 -0
- package/src/openChatScreen.ts +78 -0
- package/src/push.ts +424 -0
- package/src/pushIntegration.ts +338 -0
- package/src/pushLogout.ts +277 -0
- package/src/types.ts +46 -0
- package/src/version.ts +8 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNativeCobbaiPush = getNativeCobbaiPush;
|
|
4
|
+
exports.iosRelayAdapter = iosRelayAdapter;
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const push_1 = require("../push");
|
|
7
|
+
/** The iPhone relay's native module, or null (Android, or the pod not installed). */
|
|
8
|
+
function getNativeCobbaiPush() {
|
|
9
|
+
var _a;
|
|
10
|
+
if (react_native_1.Platform.OS !== 'ios')
|
|
11
|
+
return null;
|
|
12
|
+
return (_a = react_native_1.NativeModules.CobbaiPush) !== null && _a !== void 0 ? _a : null;
|
|
13
|
+
}
|
|
14
|
+
function warn(message) {
|
|
15
|
+
if (__DEV__) {
|
|
16
|
+
console.warn(`[cobbai][push][ios] ${message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function errorMessage(error) {
|
|
20
|
+
return error instanceof Error ? error.message : String(error);
|
|
21
|
+
}
|
|
22
|
+
function sameState(left, right) {
|
|
23
|
+
return (left !== null &&
|
|
24
|
+
left.mountedChatId === right.mountedChatId &&
|
|
25
|
+
left.connected === right.connected &&
|
|
26
|
+
left.bannerEnabled === right.bannerEnabled);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The SDK's own adapter on iPhone: token, taps (the launching one included) and
|
|
30
|
+
* foreground pushes come from the native relay, with no code in the app.
|
|
31
|
+
*/
|
|
32
|
+
function iosRelayAdapter(native) {
|
|
33
|
+
return {
|
|
34
|
+
name: 'ios-relay',
|
|
35
|
+
start(handlers) {
|
|
36
|
+
const emitter = new react_native_1.NativeEventEmitter(native);
|
|
37
|
+
const subscriptions = [
|
|
38
|
+
emitter.addListener('CobbaiPushToken', (event) => {
|
|
39
|
+
handlers.token({
|
|
40
|
+
token: event.token,
|
|
41
|
+
provider: 'apns',
|
|
42
|
+
apnsEnvironment: event.apnsEnvironment,
|
|
43
|
+
});
|
|
44
|
+
}),
|
|
45
|
+
emitter.addListener('CobbaiPushTap', (event) => {
|
|
46
|
+
handlers.tap(event.data);
|
|
47
|
+
}),
|
|
48
|
+
emitter.addListener('CobbaiPushForeground', (event) => {
|
|
49
|
+
handlers.foreground({ data: event.data, title: event.title, body: event.body });
|
|
50
|
+
}),
|
|
51
|
+
];
|
|
52
|
+
// Keep the relay told of the foreground state, so that it answers iOS at once.
|
|
53
|
+
let sentState = null;
|
|
54
|
+
const syncPresentationState = () => {
|
|
55
|
+
const state = (0, push_1.getForegroundPresentationState)();
|
|
56
|
+
if (sameState(sentState, state))
|
|
57
|
+
return;
|
|
58
|
+
sentState = state;
|
|
59
|
+
native.setPresentationState(state);
|
|
60
|
+
};
|
|
61
|
+
syncPresentationState();
|
|
62
|
+
const unsubscribeStore = (0, push_1.subscribePushStore)(syncPresentationState);
|
|
63
|
+
// The user can change the permission in Settings while the app is in the background.
|
|
64
|
+
const appStateSubscription = react_native_1.AppState.addEventListener('change', (nextState) => {
|
|
65
|
+
if (nextState !== 'active')
|
|
66
|
+
return;
|
|
67
|
+
native
|
|
68
|
+
.getPermissionStatus()
|
|
69
|
+
.then((status) => handlers.status(status))
|
|
70
|
+
.catch((error) => warn(`permission check failed: ${errorMessage(error)}`));
|
|
71
|
+
});
|
|
72
|
+
native
|
|
73
|
+
.start()
|
|
74
|
+
.then((initial) => {
|
|
75
|
+
handlers.status(initial.status);
|
|
76
|
+
if (initial.token) {
|
|
77
|
+
handlers.token({
|
|
78
|
+
token: initial.token,
|
|
79
|
+
provider: 'apns',
|
|
80
|
+
apnsEnvironment: initial.apnsEnvironment,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
initial.pendingTaps.forEach((data) => handlers.tap(data));
|
|
84
|
+
if (!initial.inPlace) {
|
|
85
|
+
warn('the notification relay is not installed: another library took the notification-centre ' +
|
|
86
|
+
'delegate without chaining, or CobbaiPushAutoInstall is NO. Call reinstallCobbaiPushRelay() ' +
|
|
87
|
+
'after that library has started.');
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => warn(`relay start failed: ${errorMessage(error)}`));
|
|
91
|
+
return () => {
|
|
92
|
+
subscriptions.forEach((subscription) => subscription.remove());
|
|
93
|
+
unsubscribeStore();
|
|
94
|
+
appStateSubscription.remove();
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
requestPermission() {
|
|
98
|
+
return native.requestPermission();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CobbaiSafeAreaInsets } from './types';
|
|
2
|
+
export type KeyboardFrameInput = {
|
|
3
|
+
chatVisible: boolean;
|
|
4
|
+
keyboardHeight: number;
|
|
5
|
+
keyboardScreenY: number;
|
|
6
|
+
windowHeight: number;
|
|
7
|
+
};
|
|
8
|
+
export type KeyboardFrame = {
|
|
9
|
+
isApplied: boolean;
|
|
10
|
+
overlayBottomInset: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function deriveKeyboardInsetFromHeight(keyboardHeight: number): number;
|
|
13
|
+
export declare function deriveKeyboardInsetFromScreenY(windowHeight: number, keyboardScreenY: number): number;
|
|
14
|
+
export declare function deriveKeyboardFrame(input: KeyboardFrameInput): KeyboardFrame;
|
|
15
|
+
export declare function withKeyboardSafeAreaBottom(safeArea: CobbaiSafeAreaInsets, keyboardFrameApplied: boolean): CobbaiSafeAreaInsets;
|
|
16
|
+
//# sourceMappingURL=androidKeyboardFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidKeyboardFrame.d.ts","sourceRoot":"","sources":["../src/androidKeyboardFrame.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAOF,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,wBAAgB,8BAA8B,CAC5C,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,GACtB,MAAM,CAER;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAiB5E;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,oBAAoB,EAC9B,oBAAoB,EAAE,OAAO,GAC5B,oBAAoB,CAGtB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveKeyboardInsetFromHeight = deriveKeyboardInsetFromHeight;
|
|
4
|
+
exports.deriveKeyboardInsetFromScreenY = deriveKeyboardInsetFromScreenY;
|
|
5
|
+
exports.deriveKeyboardFrame = deriveKeyboardFrame;
|
|
6
|
+
exports.withKeyboardSafeAreaBottom = withKeyboardSafeAreaBottom;
|
|
7
|
+
function normalizeInset(value) {
|
|
8
|
+
if (!Number.isFinite(value))
|
|
9
|
+
return 0;
|
|
10
|
+
return Math.max(0, Math.round(value));
|
|
11
|
+
}
|
|
12
|
+
function deriveKeyboardInsetFromHeight(keyboardHeight) {
|
|
13
|
+
return normalizeInset(keyboardHeight);
|
|
14
|
+
}
|
|
15
|
+
function deriveKeyboardInsetFromScreenY(windowHeight, keyboardScreenY) {
|
|
16
|
+
return normalizeInset(windowHeight - keyboardScreenY);
|
|
17
|
+
}
|
|
18
|
+
function deriveKeyboardFrame(input) {
|
|
19
|
+
if (!input.chatVisible) {
|
|
20
|
+
return { isApplied: false, overlayBottomInset: 0 };
|
|
21
|
+
}
|
|
22
|
+
const insetFromHeight = deriveKeyboardInsetFromHeight(input.keyboardHeight);
|
|
23
|
+
const insetFromScreenY = deriveKeyboardInsetFromScreenY(input.windowHeight, input.keyboardScreenY);
|
|
24
|
+
// A keyboard is considered visible only when both metrics agree it is shown.
|
|
25
|
+
if (insetFromHeight <= 0 || insetFromScreenY <= 0) {
|
|
26
|
+
return { isApplied: false, overlayBottomInset: 0 };
|
|
27
|
+
}
|
|
28
|
+
return { isApplied: true, overlayBottomInset: insetFromScreenY };
|
|
29
|
+
}
|
|
30
|
+
function withKeyboardSafeAreaBottom(safeArea, keyboardFrameApplied) {
|
|
31
|
+
if (!keyboardFrameApplied)
|
|
32
|
+
return safeArea;
|
|
33
|
+
return { ...safeArea, bottom: 0 };
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const WEB_TO_NATIVE_MESSAGES: {
|
|
2
|
+
readonly READY: "cobbai:ready";
|
|
3
|
+
readonly CLOSE: "cobbai:close";
|
|
4
|
+
readonly NEW_MESSAGE: "cobbai:new-message";
|
|
5
|
+
readonly UNREAD: "cobbai:unread";
|
|
6
|
+
readonly LAUNCHER: "cobbai:launcher";
|
|
7
|
+
readonly ERROR: "cobbai:error";
|
|
8
|
+
readonly PUSH_TOKEN_REGISTERED: "cobbai:push-token-registered";
|
|
9
|
+
};
|
|
10
|
+
export declare const NATIVE_TO_WEB_MESSAGES: {
|
|
11
|
+
readonly APP_STATE: "cobbai:app-state";
|
|
12
|
+
readonly NETWORK: "cobbai:network";
|
|
13
|
+
readonly OPEN_CONVERSATION: "cobbai:open-conversation";
|
|
14
|
+
readonly PUSH_TOKEN: "cobbai:push-token";
|
|
15
|
+
readonly SAFE_AREA: "cobbai:safe-area";
|
|
16
|
+
readonly VISIBILITY: "cobbai:visibility";
|
|
17
|
+
};
|
|
18
|
+
export type WebToNativeMessageType = (typeof WEB_TO_NATIVE_MESSAGES)[keyof typeof WEB_TO_NATIVE_MESSAGES];
|
|
19
|
+
export type NativeToWebMessageType = (typeof NATIVE_TO_WEB_MESSAGES)[keyof typeof NATIVE_TO_WEB_MESSAGES];
|
|
20
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/bridge/messages.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;;;;;CAQzB,CAAC;AAEX,eAAO,MAAM,sBAAsB;;;;;;;CAOzB,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAChC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvE,MAAM,MAAM,sBAAsB,GAChC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NATIVE_TO_WEB_MESSAGES = exports.WEB_TO_NATIVE_MESSAGES = void 0;
|
|
4
|
+
exports.WEB_TO_NATIVE_MESSAGES = {
|
|
5
|
+
READY: 'cobbai:ready',
|
|
6
|
+
CLOSE: 'cobbai:close',
|
|
7
|
+
NEW_MESSAGE: 'cobbai:new-message',
|
|
8
|
+
UNREAD: 'cobbai:unread',
|
|
9
|
+
LAUNCHER: 'cobbai:launcher',
|
|
10
|
+
ERROR: 'cobbai:error',
|
|
11
|
+
PUSH_TOKEN_REGISTERED: 'cobbai:push-token-registered',
|
|
12
|
+
};
|
|
13
|
+
exports.NATIVE_TO_WEB_MESSAGES = {
|
|
14
|
+
APP_STATE: 'cobbai:app-state',
|
|
15
|
+
NETWORK: 'cobbai:network',
|
|
16
|
+
OPEN_CONVERSATION: 'cobbai:open-conversation',
|
|
17
|
+
PUSH_TOKEN: 'cobbai:push-token',
|
|
18
|
+
SAFE_AREA: 'cobbai:safe-area',
|
|
19
|
+
VISIBILITY: 'cobbai:visibility',
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the script injected into the host page to deliver a native → web message.
|
|
3
|
+
*
|
|
4
|
+
* The envelope is serialized twice on purpose: the inner `JSON.stringify` builds the wire string
|
|
5
|
+
* (`MessageEvent.data`, parsed by the page with `JSON.parse`), the outer one turns that string into a
|
|
6
|
+
* valid JavaScript string literal. Escaping by hand (quotes only) corrupted `"`, `\` and line
|
|
7
|
+
* breaks, and A dropped the message silently.
|
|
8
|
+
*/
|
|
9
|
+
export declare function serializeNativeEvent(type: string, payload: Record<string, unknown>): string;
|
|
10
|
+
//# sourceMappingURL=nativeEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeEvent.d.ts","sourceRoot":"","sources":["../../src/bridge/nativeEvent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAG3F"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeNativeEvent = serializeNativeEvent;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the script injected into the host page to deliver a native → web message.
|
|
6
|
+
*
|
|
7
|
+
* The envelope is serialized twice on purpose: the inner `JSON.stringify` builds the wire string
|
|
8
|
+
* (`MessageEvent.data`, parsed by the page with `JSON.parse`), the outer one turns that string into a
|
|
9
|
+
* valid JavaScript string literal. Escaping by hand (quotes only) corrupted `"`, `\` and line
|
|
10
|
+
* breaks, and A dropped the message silently.
|
|
11
|
+
*/
|
|
12
|
+
function serializeNativeEvent(type, payload) {
|
|
13
|
+
const data = JSON.stringify({ type, payload });
|
|
14
|
+
return `window.dispatchEvent(new MessageEvent('message', { data: ${JSON.stringify(data)} })); true;`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type WebToNativeMessageType } from './messages';
|
|
2
|
+
import type { LauncherAppearance } from '../launcher';
|
|
3
|
+
export type BridgePayload = Record<string, unknown>;
|
|
4
|
+
export type ParsedBridgeMessage = {
|
|
5
|
+
type: WebToNativeMessageType;
|
|
6
|
+
payload: BridgePayload;
|
|
7
|
+
};
|
|
8
|
+
export type ValidatedNewMessagePayload = {
|
|
9
|
+
conversationId: number;
|
|
10
|
+
messageId: number;
|
|
11
|
+
speaker: 'agent' | 'auto';
|
|
12
|
+
senderName?: string;
|
|
13
|
+
preview?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ValidatedUnreadPayload = {
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
export type ValidatedPushTokenRegisteredPayload = {
|
|
19
|
+
token: string;
|
|
20
|
+
provider: 'apns' | 'fcm';
|
|
21
|
+
unregisterSecret: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function validateNewMessagePayload(payload: BridgePayload): ValidatedNewMessagePayload | null;
|
|
24
|
+
export declare function validateUnreadPayload(payload: BridgePayload): ValidatedUnreadPayload | null;
|
|
25
|
+
/** The secret that unregisters the token at logout. */
|
|
26
|
+
export declare function validatePushTokenRegisteredPayload(payload: BridgePayload): ValidatedPushTokenRegisteredPayload | null;
|
|
27
|
+
export declare function validateLauncherPayload(payload: BridgePayload): LauncherAppearance | null;
|
|
28
|
+
export declare function parseBridgeMessage(raw: string): ParsedBridgeMessage | null;
|
|
29
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/bridge/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAkCF,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,aAAa,GACrB,0BAA0B,GAAG,IAAI,CAsBnC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,GAAG,sBAAsB,GAAG,IAAI,CAQ3F;AAED,uDAAuD;AACvD,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,aAAa,GACrB,mCAAmC,GAAG,IAAI,CAU5C;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAiBzF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CA4B1E"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNewMessagePayload = validateNewMessagePayload;
|
|
4
|
+
exports.validateUnreadPayload = validateUnreadPayload;
|
|
5
|
+
exports.validatePushTokenRegisteredPayload = validatePushTokenRegisteredPayload;
|
|
6
|
+
exports.validateLauncherPayload = validateLauncherPayload;
|
|
7
|
+
exports.parseBridgeMessage = parseBridgeMessage;
|
|
8
|
+
const messages_1 = require("./messages");
|
|
9
|
+
const PUSH_TOKEN_PATTERN = /^[A-Za-z0-9:_\-.]{1,4096}$/;
|
|
10
|
+
const UNREGISTER_SECRET_PATTERN = /^[0-9a-f]{64}$/;
|
|
11
|
+
const HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
12
|
+
const VALID_TYPES = new Set(Object.values(messages_1.WEB_TO_NATIVE_MESSAGES));
|
|
13
|
+
function parsePositiveInteger(value) {
|
|
14
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value <= 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function parseOptionalTrimmedString(value, maxLength) {
|
|
20
|
+
if (typeof value !== 'string') {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = value.trim();
|
|
24
|
+
if (trimmed.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (Array.from(trimmed).length > maxLength) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return trimmed;
|
|
31
|
+
}
|
|
32
|
+
function validateNewMessagePayload(payload) {
|
|
33
|
+
const conversationId = parsePositiveInteger(payload.conversation_id);
|
|
34
|
+
const messageId = parsePositiveInteger(payload.message_id);
|
|
35
|
+
const speaker = payload.speaker;
|
|
36
|
+
const senderName = parseOptionalTrimmedString(payload.sender_name, 80);
|
|
37
|
+
const preview = parseOptionalTrimmedString(payload.preview, 160);
|
|
38
|
+
if (conversationId == null || messageId == null) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (speaker !== 'agent' && speaker !== 'auto') {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
conversationId,
|
|
46
|
+
messageId,
|
|
47
|
+
speaker,
|
|
48
|
+
...(senderName ? { senderName } : {}),
|
|
49
|
+
...(preview ? { preview } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function validateUnreadPayload(payload) {
|
|
53
|
+
const total = payload.total;
|
|
54
|
+
if (typeof total !== 'number' || !Number.isInteger(total) || total < 0) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return { total };
|
|
58
|
+
}
|
|
59
|
+
/** The secret that unregisters the token at logout. */
|
|
60
|
+
function validatePushTokenRegisteredPayload(payload) {
|
|
61
|
+
const { token, provider, unregister_secret: unregisterSecret } = payload;
|
|
62
|
+
if (typeof token !== 'string' || !PUSH_TOKEN_PATTERN.test(token))
|
|
63
|
+
return null;
|
|
64
|
+
if (provider !== 'apns' && provider !== 'fcm')
|
|
65
|
+
return null;
|
|
66
|
+
if (typeof unregisterSecret !== 'string' || !UNREGISTER_SECRET_PATTERN.test(unregisterSecret)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return { token, provider, unregisterSecret };
|
|
70
|
+
}
|
|
71
|
+
function validateLauncherPayload(payload) {
|
|
72
|
+
const backgroundColor = payload.background_color;
|
|
73
|
+
const textColor = payload.text_color;
|
|
74
|
+
if (typeof backgroundColor !== 'string' ||
|
|
75
|
+
typeof textColor !== 'string' ||
|
|
76
|
+
!HEX_COLOR_PATTERN.test(backgroundColor) ||
|
|
77
|
+
!HEX_COLOR_PATTERN.test(textColor)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
backgroundColor,
|
|
82
|
+
textColor,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function parseBridgeMessage(raw) {
|
|
86
|
+
var _a;
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(raw);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const type = parsed.type;
|
|
98
|
+
const payload = parsed.payload;
|
|
99
|
+
if (typeof type !== 'string' || !VALID_TYPES.has(type)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (payload != null && typeof payload !== 'object') {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
type: type,
|
|
107
|
+
payload: (_a = payload) !== null && _a !== void 0 ? _a : {},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CobbaiSafeAreaInsets } from './types';
|
|
2
|
+
export declare const SHEET_TRANSITION_DURATION_MS = 200;
|
|
3
|
+
export declare const LOADER_FADE_OUT_DURATION_MS = 150;
|
|
4
|
+
export declare const PROCESS_GONE_RETRY_LIMIT = 3;
|
|
5
|
+
export declare const PROCESS_GONE_RETRY_WINDOW_MS = 60000;
|
|
6
|
+
export type ProcessGoneRecoveryDecision = {
|
|
7
|
+
shouldRemount: boolean;
|
|
8
|
+
nextOccurrenceTimestampsMs: number[];
|
|
9
|
+
};
|
|
10
|
+
export declare function getOffscreenTranslateY(windowHeight: number): number;
|
|
11
|
+
export declare function getBackdropOpacityInterpolationRanges(offscreenTranslateY: number): {
|
|
12
|
+
inputRange: [number, number];
|
|
13
|
+
outputRange: [number, number];
|
|
14
|
+
};
|
|
15
|
+
export declare function toSheetSafeAreaInsetsForWeb(safeArea: CobbaiSafeAreaInsets): CobbaiSafeAreaInsets;
|
|
16
|
+
export declare function shouldRenderChatSurface(prewarm: boolean, visible: boolean, presented: boolean): boolean;
|
|
17
|
+
export declare function isChatSurfaceOnScreen(visible: boolean, presented: boolean): boolean;
|
|
18
|
+
export declare function getProcessGoneRecoveryDecision(occurrenceTimestampsMs: number[], nowMs: number): ProcessGoneRecoveryDecision;
|
|
19
|
+
//# sourceMappingURL=chatPresentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatPresentation.d.ts","sourceRoot":"","sources":["../src/chatPresentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,OAAO,CAAC;IACvB,0BAA0B,EAAE,MAAM,EAAE,CAAC;CACtC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMnE;AAED,wBAAgB,qCAAqC,CAAC,mBAAmB,EAAE,MAAM,GAAG;IAClF,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAQA;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,oBAAoB,GAAG,oBAAoB,CAOhG;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,OAAO,GACjB,OAAO,CAET;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAEnF;AAED,wBAAgB,8BAA8B,CAC5C,sBAAsB,EAAE,MAAM,EAAE,EAChC,KAAK,EAAE,MAAM,GACZ,2BAA2B,CAe7B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROCESS_GONE_RETRY_WINDOW_MS = exports.PROCESS_GONE_RETRY_LIMIT = exports.LOADER_FADE_OUT_DURATION_MS = exports.SHEET_TRANSITION_DURATION_MS = void 0;
|
|
4
|
+
exports.getOffscreenTranslateY = getOffscreenTranslateY;
|
|
5
|
+
exports.getBackdropOpacityInterpolationRanges = getBackdropOpacityInterpolationRanges;
|
|
6
|
+
exports.toSheetSafeAreaInsetsForWeb = toSheetSafeAreaInsetsForWeb;
|
|
7
|
+
exports.shouldRenderChatSurface = shouldRenderChatSurface;
|
|
8
|
+
exports.isChatSurfaceOnScreen = isChatSurfaceOnScreen;
|
|
9
|
+
exports.getProcessGoneRecoveryDecision = getProcessGoneRecoveryDecision;
|
|
10
|
+
exports.SHEET_TRANSITION_DURATION_MS = 200;
|
|
11
|
+
exports.LOADER_FADE_OUT_DURATION_MS = 150;
|
|
12
|
+
exports.PROCESS_GONE_RETRY_LIMIT = 3;
|
|
13
|
+
exports.PROCESS_GONE_RETRY_WINDOW_MS = 60000;
|
|
14
|
+
function getOffscreenTranslateY(windowHeight) {
|
|
15
|
+
if (!Number.isFinite(windowHeight) || windowHeight <= 0) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
return Math.ceil(windowHeight) + 1;
|
|
19
|
+
}
|
|
20
|
+
function getBackdropOpacityInterpolationRanges(offscreenTranslateY) {
|
|
21
|
+
const clampedOffscreenTranslateY = Number.isFinite(offscreenTranslateY) && offscreenTranslateY > 0 ? offscreenTranslateY : 1;
|
|
22
|
+
return {
|
|
23
|
+
inputRange: [0, clampedOffscreenTranslateY],
|
|
24
|
+
outputRange: [1, 0],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function toSheetSafeAreaInsetsForWeb(safeArea) {
|
|
28
|
+
return {
|
|
29
|
+
top: 0,
|
|
30
|
+
right: safeArea.right,
|
|
31
|
+
bottom: safeArea.bottom,
|
|
32
|
+
left: safeArea.left,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function shouldRenderChatSurface(prewarm, visible, presented) {
|
|
36
|
+
return prewarm || visible || presented;
|
|
37
|
+
}
|
|
38
|
+
function isChatSurfaceOnScreen(visible, presented) {
|
|
39
|
+
return visible || presented;
|
|
40
|
+
}
|
|
41
|
+
function getProcessGoneRecoveryDecision(occurrenceTimestampsMs, nowMs) {
|
|
42
|
+
const recentOccurrences = occurrenceTimestampsMs.filter((timestampMs) => Number.isFinite(timestampMs) &&
|
|
43
|
+
timestampMs <= nowMs &&
|
|
44
|
+
nowMs - timestampMs <= exports.PROCESS_GONE_RETRY_WINDOW_MS);
|
|
45
|
+
const nextOccurrenceTimestampsMs = [...recentOccurrences, nowMs];
|
|
46
|
+
return {
|
|
47
|
+
// Stop auto-remounting on the 3rd process death within the rolling 60-second window.
|
|
48
|
+
shouldRemount: nextOccurrenceTimestampsMs.length < exports.PROCESS_GONE_RETRY_LIMIT,
|
|
49
|
+
nextOccurrenceTimestampsMs,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CobbaiInAppBannerPayload } from '../inAppBanner';
|
|
2
|
+
type InAppBannerQueueInput = {
|
|
3
|
+
/** `inAppBanner` prop. */
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
/** Banners are never shown over the chat itself. */
|
|
6
|
+
chatSurfaceOnScreen: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type InAppBannerQueue = {
|
|
9
|
+
activeBanner: CobbaiInAppBannerPayload | null;
|
|
10
|
+
/** Shows a banner unless disabled, the chat is on screen, or this message was already shown. */
|
|
11
|
+
queueInAppBanner: (banner: CobbaiInAppBannerPayload) => void;
|
|
12
|
+
handleBannerAutoHide: () => void;
|
|
13
|
+
/** Opens the banner's conversation through the same path as a push tap. */
|
|
14
|
+
handleBannerPress: (banner: CobbaiInAppBannerPayload) => void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The in-app banner shown for new messages while the chat is closed, fed by live bridge events
|
|
18
|
+
* and by foreground pushes (registered as the push store's banner presenter).
|
|
19
|
+
*/
|
|
20
|
+
export declare function useInAppBannerQueue({ enabled, chatSurfaceOnScreen, }: InAppBannerQueueInput): InAppBannerQueue;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=useInAppBannerQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInAppBannerQueue.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useInAppBannerQueue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,wBAAwB,EAA4B,MAAM,gBAAgB,CAAC;AAGzF,KAAK,qBAAqB,GAAG;IAC3B,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAC9C,gGAAgG;IAChG,gBAAgB,EAAE,CAAC,MAAM,EAAE,wBAAwB,KAAK,IAAI,CAAC;IAC7D,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,2EAA2E;IAC3E,iBAAiB,EAAE,CAAC,MAAM,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAC/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,mBAAmB,GACpB,EAAE,qBAAqB,GAAG,gBAAgB,CA+D1C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInAppBannerQueue = useInAppBannerQueue;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const inAppBanner_1 = require("../inAppBanner");
|
|
6
|
+
const push_1 = require("../push");
|
|
7
|
+
/**
|
|
8
|
+
* The in-app banner shown for new messages while the chat is closed, fed by live bridge events
|
|
9
|
+
* and by foreground pushes (registered as the push store's banner presenter).
|
|
10
|
+
*/
|
|
11
|
+
function useInAppBannerQueue({ enabled, chatSurfaceOnScreen, }) {
|
|
12
|
+
const [activeBanner, setActiveBanner] = (0, react_1.useState)(null);
|
|
13
|
+
const shownBannerMessageKeysRef = (0, react_1.useRef)(new Set());
|
|
14
|
+
const chatSurfaceOnScreenRef = (0, react_1.useRef)(false);
|
|
15
|
+
const enabledRef = (0, react_1.useRef)(enabled);
|
|
16
|
+
const queueInAppBanner = (0, react_1.useCallback)((nextBanner) => {
|
|
17
|
+
if (!enabledRef.current) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (chatSurfaceOnScreenRef.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const key = (0, inAppBanner_1.getInAppBannerMessageKey)(nextBanner.conversationId, nextBanner.messageId);
|
|
24
|
+
if (shownBannerMessageKeysRef.current.has(key)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
shownBannerMessageKeysRef.current.add(key);
|
|
28
|
+
setActiveBanner(nextBanner);
|
|
29
|
+
}, []);
|
|
30
|
+
(0, react_1.useEffect)(() => {
|
|
31
|
+
chatSurfaceOnScreenRef.current = chatSurfaceOnScreen;
|
|
32
|
+
if (chatSurfaceOnScreen) {
|
|
33
|
+
setActiveBanner(null);
|
|
34
|
+
}
|
|
35
|
+
}, [chatSurfaceOnScreen]);
|
|
36
|
+
(0, react_1.useEffect)(() => {
|
|
37
|
+
enabledRef.current = enabled;
|
|
38
|
+
(0, push_1.setPushBannerEnabled)(enabled);
|
|
39
|
+
if (!enabled) {
|
|
40
|
+
setActiveBanner(null);
|
|
41
|
+
}
|
|
42
|
+
return () => {
|
|
43
|
+
(0, push_1.setPushBannerEnabled)(true);
|
|
44
|
+
};
|
|
45
|
+
}, [enabled]);
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
(0, push_1.setPushBannerPresenter)(queueInAppBanner);
|
|
48
|
+
return () => {
|
|
49
|
+
(0, push_1.setPushBannerPresenter)(null);
|
|
50
|
+
};
|
|
51
|
+
}, [queueInAppBanner]);
|
|
52
|
+
const handleBannerAutoHide = (0, react_1.useCallback)(() => {
|
|
53
|
+
setActiveBanner(null);
|
|
54
|
+
}, []);
|
|
55
|
+
const handleBannerPress = (0, react_1.useCallback)((banner) => {
|
|
56
|
+
setActiveBanner(null);
|
|
57
|
+
(0, push_1.openConversationFromBanner)(banner.chatId, banner.conversationId);
|
|
58
|
+
}, []);
|
|
59
|
+
return { activeBanner, queueInAppBanner, handleBannerAutoHide, handleBannerPress };
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type KeyboardFrame } from '../androidKeyboardFrame';
|
|
2
|
+
type KeyboardFrameInput = {
|
|
3
|
+
/** Listeners are attached only while the chat is open. */
|
|
4
|
+
visible: boolean;
|
|
5
|
+
/** The frame is applied only while the sheet is on screen. */
|
|
6
|
+
chatSurfaceOnScreen: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Tracks the software keyboard and derives how far the sheet must be lifted above it. */
|
|
9
|
+
export declare function useKeyboardFrame({ visible, chatSurfaceOnScreen }: KeyboardFrameInput): {
|
|
10
|
+
keyboardFrame: KeyboardFrame;
|
|
11
|
+
resetKeyboardMetrics: () => void;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=useKeyboardFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardFrame.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useKeyboardFrame.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAuBlF,KAAK,kBAAkB,GAAG;IACxB,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,kBAAkB,GAAG;IACtF,aAAa,EAAE,aAAa,CAAC;IAC7B,oBAAoB,EAAE,MAAM,IAAI,CAAC;CAClC,CAoDA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useKeyboardFrame = useKeyboardFrame;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const androidKeyboardFrame_1 = require("../androidKeyboardFrame");
|
|
7
|
+
const EMPTY_KEYBOARD_METRICS = {
|
|
8
|
+
height: 0,
|
|
9
|
+
screenY: 0,
|
|
10
|
+
windowHeight: 0,
|
|
11
|
+
};
|
|
12
|
+
function toKeyboardMetrics(event) {
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
|
+
const windowHeight = react_native_1.Dimensions.get('window').height;
|
|
15
|
+
return {
|
|
16
|
+
height: (_b = (_a = event.endCoordinates) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 0,
|
|
17
|
+
screenY: (_d = (_c = event.endCoordinates) === null || _c === void 0 ? void 0 : _c.screenY) !== null && _d !== void 0 ? _d : windowHeight,
|
|
18
|
+
windowHeight,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Tracks the software keyboard and derives how far the sheet must be lifted above it. */
|
|
22
|
+
function useKeyboardFrame({ visible, chatSurfaceOnScreen }) {
|
|
23
|
+
const [keyboardMetrics, setKeyboardMetrics] = (0, react_1.useState)(EMPTY_KEYBOARD_METRICS);
|
|
24
|
+
(0, react_1.useEffect)(() => {
|
|
25
|
+
if (react_native_1.Platform.OS !== 'android' && react_native_1.Platform.OS !== 'ios')
|
|
26
|
+
return;
|
|
27
|
+
if (!visible)
|
|
28
|
+
return;
|
|
29
|
+
const handleKeyboardFrame = (event) => {
|
|
30
|
+
setKeyboardMetrics(toKeyboardMetrics(event));
|
|
31
|
+
};
|
|
32
|
+
const handleKeyboardDidHide = () => {
|
|
33
|
+
setKeyboardMetrics(EMPTY_KEYBOARD_METRICS);
|
|
34
|
+
};
|
|
35
|
+
// iOS reports hides through keyboardWillChangeFrame too (screenY at the bottom edge).
|
|
36
|
+
const subscriptions = react_native_1.Platform.OS === 'android'
|
|
37
|
+
? [
|
|
38
|
+
react_native_1.Keyboard.addListener('keyboardDidShow', handleKeyboardFrame),
|
|
39
|
+
react_native_1.Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide),
|
|
40
|
+
]
|
|
41
|
+
: [react_native_1.Keyboard.addListener('keyboardWillChangeFrame', handleKeyboardFrame)];
|
|
42
|
+
return () => {
|
|
43
|
+
for (const subscription of subscriptions) {
|
|
44
|
+
subscription.remove();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, [visible]);
|
|
48
|
+
const keyboardFrame = (0, react_1.useMemo)(() => (0, androidKeyboardFrame_1.deriveKeyboardFrame)({
|
|
49
|
+
chatVisible: chatSurfaceOnScreen,
|
|
50
|
+
keyboardHeight: keyboardMetrics.height,
|
|
51
|
+
keyboardScreenY: keyboardMetrics.screenY,
|
|
52
|
+
windowHeight: keyboardMetrics.windowHeight,
|
|
53
|
+
}), [
|
|
54
|
+
chatSurfaceOnScreen,
|
|
55
|
+
keyboardMetrics.height,
|
|
56
|
+
keyboardMetrics.screenY,
|
|
57
|
+
keyboardMetrics.windowHeight,
|
|
58
|
+
]);
|
|
59
|
+
const resetKeyboardMetrics = (0, react_1.useCallback)(() => {
|
|
60
|
+
setKeyboardMetrics(EMPTY_KEYBOARD_METRICS);
|
|
61
|
+
}, []);
|
|
62
|
+
return { keyboardFrame, resetKeyboardMetrics };
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Animated } from 'react-native';
|
|
2
|
+
import { type LauncherAppearance } from '../launcher';
|
|
3
|
+
type LauncherPresentationInput = {
|
|
4
|
+
prewarm: boolean;
|
|
5
|
+
/** `launcherVisible` prop. */
|
|
6
|
+
launcherVisible: boolean;
|
|
7
|
+
visible: boolean;
|
|
8
|
+
presented: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type LauncherPresentation = {
|
|
11
|
+
/** null until the chat reports its colors (or the fallback delay elapses). */
|
|
12
|
+
launcherAppearance: LauncherAppearance | null;
|
|
13
|
+
setLauncherAppearance: (appearance: LauncherAppearance) => void;
|
|
14
|
+
showLauncher: boolean;
|
|
15
|
+
launcherOpacity: Animated.Value;
|
|
16
|
+
};
|
|
17
|
+
/** Launcher colors (from cobbai:launcher, with a default fallback) and its fade in/out. */
|
|
18
|
+
export declare function useLauncherPresentation({ prewarm, launcherVisible, visible, presented, }: LauncherPresentationInput): LauncherPresentation;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=useLauncherPresentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLauncherPresentation.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useLauncherPresentation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAU,MAAM,cAAc,CAAC;AAChD,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAErB,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,8BAA8B;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,8EAA8E;IAC9E,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,qBAAqB,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAChE,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,QAAQ,CAAC,KAAK,CAAC;CACjC,CAAC;AAEF,2FAA2F;AAC3F,wBAAgB,uBAAuB,CAAC,EACtC,OAAO,EACP,eAAe,EACf,OAAO,EACP,SAAS,GACV,EAAE,yBAAyB,GAAG,oBAAoB,CAwFlD"}
|