datakeen-session-react 1.1.200-rc.2 → 1.1.200-rc.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.
|
@@ -24,6 +24,7 @@ var NfcSuccessAnimation = require('./NfcSuccessAnimation.js');
|
|
|
24
24
|
// choisir l'environnement (même rôle que `intent://<host>/scan/<id>` sur Android).
|
|
25
25
|
var IOS_APP_SCHEME = "datakeenscannerswift";
|
|
26
26
|
var IOS_APP_STORE_URL = "https://apps.apple.com/app/id6762505375";
|
|
27
|
+
var INSTALL_REVEAL_DELAY_MS = 2500;
|
|
27
28
|
var NfcScanStep = function (_a) {
|
|
28
29
|
var sessionId = _a.sessionId, nodeId = _a.nodeId, stepObject = _a.stepObject, template = _a.template, pageTitle = _a.pageTitle, pageDescription = _a.pageDescription, onBack = _a.onBack, onContinueWithoutChip = _a.onContinueWithoutChip;
|
|
29
30
|
var t = useI18n.useI18n().t;
|
|
@@ -41,8 +42,11 @@ var NfcScanStep = function (_a) {
|
|
|
41
42
|
var apiBaseUrl = React.useMemo(function () { return api.getBaseURL(); }, []);
|
|
42
43
|
var iosAppLinks = React.useMemo(function () {
|
|
43
44
|
var host = new URL(apiBaseUrl, window.location.href).host;
|
|
45
|
+
// `return` : l'app rouvre exactement cette URL en fin de scan, ce qui ramène Safari sur cet
|
|
46
|
+
// onglet (et non un nouvel onglet) quand l'URL est identique.
|
|
47
|
+
var returnUrl = encodeURIComponent(window.location.href);
|
|
44
48
|
return {
|
|
45
|
-
open: "".concat(IOS_APP_SCHEME, "://").concat(host, "/scan/").concat(sessionId),
|
|
49
|
+
open: "".concat(IOS_APP_SCHEME, "://").concat(host, "/scan/").concat(sessionId, "?return=").concat(returnUrl),
|
|
46
50
|
// Lu par le bouton « Reprendre ma session » de l'app au premier lancement après installation.
|
|
47
51
|
resume: "https://".concat(host, "/scan/").concat(sessionId),
|
|
48
52
|
};
|
|
@@ -53,6 +57,20 @@ var NfcScanStep = function (_a) {
|
|
|
53
57
|
var _a;
|
|
54
58
|
(_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(iosAppLinks.resume).catch(function () { return undefined; });
|
|
55
59
|
};
|
|
60
|
+
// iOS ne permet pas de savoir si l'app est installée. Un seul bouton « Ouvrir » ; si la page est
|
|
61
|
+
// toujours visible après le délai (app absente : Safari affiche « adresse invalide »), on révèle
|
|
62
|
+
// « Installer ». Pas de redirection automatique vers l'App Store : pendant la confirmation iOS
|
|
63
|
+
// « Ouvrir dans ID Scan ? » la page reste visible, une redirection y enverrait à tort.
|
|
64
|
+
var _e = React.useState(false), showInstall = _e[0], setShowInstall = _e[1];
|
|
65
|
+
var installRevealTimerRef = React.useRef();
|
|
66
|
+
React.useEffect(function () { return function () { return clearTimeout(installRevealTimerRef.current); }; }, []);
|
|
67
|
+
var revealInstallIfAppDidNotOpen = function () {
|
|
68
|
+
clearTimeout(installRevealTimerRef.current);
|
|
69
|
+
installRevealTimerRef.current = setTimeout(function () {
|
|
70
|
+
if (document.visibilityState === "visible")
|
|
71
|
+
setShowInstall(true);
|
|
72
|
+
}, INSTALL_REVEAL_DELAY_MS);
|
|
73
|
+
};
|
|
56
74
|
var status = useNfcSseStatus.useNfcSseStatus({
|
|
57
75
|
sessionId: sessionId,
|
|
58
76
|
apiBaseUrl: apiBaseUrl,
|
|
@@ -164,7 +182,7 @@ var NfcScanStep = function (_a) {
|
|
|
164
182
|
return (jsxRuntime.jsx(MobilePageLayout.default, { footer: footer, children: jsxRuntime.jsx("div", { className: "px-4 py-6 pt-11 md:px-8 md:py-8", children: jsxRuntime.jsxs("div", { className: "w-full max-w-md mx-auto space-y-6", children: [jsxRuntime.jsxs("div", { className: "text-center space-y-4 mt-16 md:mt-20", children: [jsxRuntime.jsx(Title.default, { className: "text-xl md:text-2xl lg:text-3xl", children: title }), jsxRuntime.jsx(Subtitle.default, { className: "text-sm md:text-base text-gray-600 leading-relaxed whitespace-pre-line", children: subtitle })] }), jsxRuntime.jsx("div", { className: "flex-1 flex flex-col justify-center items-center gap-4", children: status === "success" ? (jsxRuntime.jsx(NfcSuccessAnimation.default, {})) : status === "completed" ? (jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4 p-8", children: [jsxRuntime.jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.verifying", "Vérification en cours…") })] })) : status === "failed" ? (jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center", children: [jsxRuntime.jsx("p", { className: "text-base font-semibold text-red-600", children: t("nfc_scan.failed_title", "Le scan n'a pas pu être vérifié") }), jsxRuntime.jsx("p", { className: "text-sm text-gray-600 leading-relaxed", children: t("nfc_scan.failed_description", "Après plusieurs tentatives, la lecture de votre document n'a pas pu être validée.") }), resetError && (jsxRuntime.jsx("p", { className: "text-sm text-red-600", role: "alert", children: resetError }))] })) : (
|
|
165
183
|
// Contenu principal QR/mobile — reste monté pour "pending" ET "opened", pour ne
|
|
166
184
|
// jamais démonter le canvas déjà généré.
|
|
167
|
-
jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [qrError ? (jsxRuntime.jsx("div", { className: "text-red-500 text-center p-4", children: qrError })) : isIOS ? (jsxRuntime.jsxs("div", { className: "flex w-full flex-col items-center gap-3 p-4 text-center", children: [jsxRuntime.jsx("a", { href: iosAppLinks.open, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] text-sm font-medium hover:brightness-110 active:brightness-90", style: { backgroundColor: "var(--dk-btn-bg)", color: "var(--dk-btn-text)" }, children: t("nfc_scan.open_app_link", "Ouvrir l'application") }), jsxRuntime.jsx("a", { href: IOS_APP_STORE_URL, onClick: copyResumeLink, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] border border-gray-300 text-sm font-medium text-gray-600 hover:bg-black/5", children: t("nfc_scan.install_app_link", "Installer l'application") }), jsxRuntime.jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.install_app_hint", "Après l'installation, revenez sur cette page et appuyez sur « Ouvrir l'application ».") })] })) : isMobile ? (jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4 p-8 text-center", children: [jsxRuntime.jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.opening_app", "Ouverture de l'application…") }), jsxRuntime.jsx("a", { href: nfcUrl, className: "text-sm font-medium text-blue-600 underline", children: t("nfc_scan.open_app_link", "Ouvrir l'application") })] })) : (jsxRuntime.jsx("div", { className: "bg-white p-4 rounded-lg shadow-lg border-2 border-gray-200", children: jsxRuntime.jsx("canvas", { ref: canvasRef }) })), status === "opened" && (jsxRuntime.jsxs("div", { className: "text-center space-y-1", children: [jsxRuntime.jsx("p", { className: "text-sm font-semibold", style: { color: "var(--uni-secondary-color, #0a9983)" }, children: t("nfc_scan.qr_opened_title", "QR code scanné") }), jsxRuntime.jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.qr_opened_description", "L'expérience NFC est ouverte sur votre smartphone. Continuez le scan sur votre téléphone.") }), jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-xs text-gray-500 pt-1", children: [jsxRuntime.jsx("span", { className: "h-2 w-2 rounded-full animate-pulse", style: { backgroundColor: "var(--uni-primary-color, #11e5c5)" } }), t("nfc_scan.waiting_completion", "En attente de la lecture NFC")] })] }))] })) })] }) }) }));
|
|
185
|
+
jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [qrError ? (jsxRuntime.jsx("div", { className: "text-red-500 text-center p-4", children: qrError })) : isIOS ? (jsxRuntime.jsxs("div", { className: "flex w-full flex-col items-center gap-3 p-4 text-center", children: [jsxRuntime.jsx("a", { href: iosAppLinks.open, onClick: revealInstallIfAppDidNotOpen, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] text-sm font-medium hover:brightness-110 active:brightness-90", style: { backgroundColor: "var(--dk-btn-bg)", color: "var(--dk-btn-text)" }, children: t("nfc_scan.open_app_link", "Ouvrir l'application") }), showInstall ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("a", { href: IOS_APP_STORE_URL, onClick: copyResumeLink, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] border border-gray-300 text-sm font-medium text-gray-600 hover:bg-black/5", children: t("nfc_scan.install_app_link", "Installer l'application") }), jsxRuntime.jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.install_app_hint", "Après l'installation, revenez sur cette page et appuyez sur « Ouvrir l'application ».") })] })) : null] })) : isMobile ? (jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4 p-8 text-center", children: [jsxRuntime.jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.opening_app", "Ouverture de l'application…") }), jsxRuntime.jsx("a", { href: nfcUrl, className: "text-sm font-medium text-blue-600 underline", children: t("nfc_scan.open_app_link", "Ouvrir l'application") })] })) : (jsxRuntime.jsx("div", { className: "bg-white p-4 rounded-lg shadow-lg border-2 border-gray-200", children: jsxRuntime.jsx("canvas", { ref: canvasRef }) })), status === "opened" && (jsxRuntime.jsxs("div", { className: "text-center space-y-1", children: [jsxRuntime.jsx("p", { className: "text-sm font-semibold", style: { color: "var(--uni-secondary-color, #0a9983)" }, children: t("nfc_scan.qr_opened_title", "QR code scanné") }), jsxRuntime.jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.qr_opened_description", "L'expérience NFC est ouverte sur votre smartphone. Continuez le scan sur votre téléphone.") }), jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2 text-xs text-gray-500 pt-1", children: [jsxRuntime.jsx("span", { className: "h-2 w-2 rounded-full animate-pulse", style: { backgroundColor: "var(--uni-primary-color, #11e5c5)" } }), t("nfc_scan.waiting_completion", "En attente de la lecture NFC")] })] }))] })) })] }) }) }));
|
|
168
186
|
};
|
|
169
187
|
|
|
170
188
|
exports.default = NfcScanStep;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
|
|
5
5
|
var SUCCESS_DISPLAY_DURATION_MS = 2500;
|
|
6
|
+
var RECONNECT_DELAY_MS = 2000;
|
|
6
7
|
function useNfcSseStatus(_a) {
|
|
7
8
|
var sessionId = _a.sessionId, apiBaseUrl = _a.apiBaseUrl, onCompleted = _a.onCompleted;
|
|
8
9
|
var _b = React.useState("pending"), status = _b[0], setStatus = _b[1];
|
|
@@ -12,42 +13,76 @@ function useNfcSseStatus(_a) {
|
|
|
12
13
|
if (!sessionId || !apiBaseUrl)
|
|
13
14
|
return;
|
|
14
15
|
var url = "".concat(apiBaseUrl, "/session/sdk/").concat(sessionId, "/nfc-status");
|
|
15
|
-
var source =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
var source = null;
|
|
17
|
+
// Statut terminal reçu : plus aucune (re)connexion, et `onCompleted` n'est appelé qu'une fois.
|
|
18
|
+
var finished = false;
|
|
19
|
+
var reconnectTimer;
|
|
20
|
+
var open = function () {
|
|
21
|
+
clearTimeout(reconnectTimer);
|
|
22
|
+
source === null || source === void 0 ? void 0 : source.close();
|
|
23
|
+
var current = new EventSource(url);
|
|
24
|
+
source = current;
|
|
25
|
+
current.onmessage = function (event) {
|
|
26
|
+
if (finished)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
var data = JSON.parse(event.data);
|
|
30
|
+
if (data.status === "completed") {
|
|
31
|
+
finished = true;
|
|
32
|
+
current.close();
|
|
33
|
+
setStatus("success");
|
|
34
|
+
setTimeout(function () {
|
|
35
|
+
setStatus("completed");
|
|
36
|
+
onCompletedRef.current();
|
|
37
|
+
}, SUCCESS_DISPLAY_DURATION_MS);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// `failed` est terminal : le serveur ferme le flux, inutile de le rouvrir en boucle.
|
|
41
|
+
if (data.status === "failed")
|
|
42
|
+
finished = true;
|
|
43
|
+
setStatus(data.status);
|
|
44
|
+
}
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
catch (_a) {
|
|
47
|
+
// message malformé, on ignore
|
|
29
48
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
};
|
|
50
|
+
// EventSource se reconnecte seul tant qu'il est CONNECTING. Mais iOS coupe le flux quand
|
|
51
|
+
// Safari passe en arrière-plan pendant le scan dans l'app, et une réponse non-200 à la
|
|
52
|
+
// reconnexion le ferme définitivement (CLOSED) : on le rouvre alors nous-mêmes.
|
|
53
|
+
current.onerror = function () {
|
|
54
|
+
if (!finished && current.readyState === EventSource.CLOSED) {
|
|
55
|
+
reconnectTimer = setTimeout(open, RECONNECT_DELAY_MS);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
34
58
|
};
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
// Retour sur la page (depuis l'app de scan, ou restauration bfcache) : le flux a pu mourir
|
|
60
|
+
// pendant la suspension et l'event `completed` être perdu. On rouvre : le serveur renvoie le
|
|
61
|
+
// statut courant dès la connexion, donc le parcours avance sans recharger la page.
|
|
62
|
+
var reopenIfVisible = function () {
|
|
63
|
+
if (!finished && document.visibilityState === "visible")
|
|
64
|
+
open();
|
|
37
65
|
};
|
|
38
66
|
// Fermer le flux uniquement quand la page se ferme réellement, sinon le SSE reste ouvert côté
|
|
39
67
|
// serveur (heartbeat + listener qui fuient). `pagehide` couvre la fermeture d'onglet/navigation
|
|
40
68
|
// (plus fiable que `beforeunload` sur mobile).
|
|
41
69
|
//
|
|
42
70
|
// NE PAS fermer sur `visibilitychange`/`hidden` : le passage en arrière-plan est le geste
|
|
43
|
-
// NORMAL de l'utilisateur qui bascule vers son téléphone pour scanner le QR.
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
// NORMAL de l'utilisateur qui bascule vers son téléphone pour scanner le QR. On se contente de
|
|
72
|
+
// ROUVRIR au retour (`visible`), ce qui ne coupe jamais un flux encore utile.
|
|
73
|
+
var closeSource = function () {
|
|
74
|
+
clearTimeout(reconnectTimer);
|
|
75
|
+
source === null || source === void 0 ? void 0 : source.close();
|
|
76
|
+
};
|
|
77
|
+
open();
|
|
47
78
|
window.addEventListener("pagehide", closeSource);
|
|
79
|
+
window.addEventListener("pageshow", reopenIfVisible);
|
|
80
|
+
document.addEventListener("visibilitychange", reopenIfVisible);
|
|
48
81
|
return function () {
|
|
49
82
|
window.removeEventListener("pagehide", closeSource);
|
|
50
|
-
|
|
83
|
+
window.removeEventListener("pageshow", reopenIfVisible);
|
|
84
|
+
document.removeEventListener("visibilitychange", reopenIfVisible);
|
|
85
|
+
closeSource();
|
|
51
86
|
};
|
|
52
87
|
}, [sessionId, apiBaseUrl]);
|
|
53
88
|
return { status: status };
|
|
@@ -20,6 +20,7 @@ import NfcSuccessAnimation from './NfcSuccessAnimation.js';
|
|
|
20
20
|
// choisir l'environnement (même rôle que `intent://<host>/scan/<id>` sur Android).
|
|
21
21
|
var IOS_APP_SCHEME = "datakeenscannerswift";
|
|
22
22
|
var IOS_APP_STORE_URL = "https://apps.apple.com/app/id6762505375";
|
|
23
|
+
var INSTALL_REVEAL_DELAY_MS = 2500;
|
|
23
24
|
var NfcScanStep = function (_a) {
|
|
24
25
|
var sessionId = _a.sessionId, nodeId = _a.nodeId, stepObject = _a.stepObject, template = _a.template, pageTitle = _a.pageTitle, pageDescription = _a.pageDescription, onBack = _a.onBack, onContinueWithoutChip = _a.onContinueWithoutChip;
|
|
25
26
|
var t = useI18n().t;
|
|
@@ -37,8 +38,11 @@ var NfcScanStep = function (_a) {
|
|
|
37
38
|
var apiBaseUrl = useMemo(function () { return getBaseURL(); }, []);
|
|
38
39
|
var iosAppLinks = useMemo(function () {
|
|
39
40
|
var host = new URL(apiBaseUrl, window.location.href).host;
|
|
41
|
+
// `return` : l'app rouvre exactement cette URL en fin de scan, ce qui ramène Safari sur cet
|
|
42
|
+
// onglet (et non un nouvel onglet) quand l'URL est identique.
|
|
43
|
+
var returnUrl = encodeURIComponent(window.location.href);
|
|
40
44
|
return {
|
|
41
|
-
open: "".concat(IOS_APP_SCHEME, "://").concat(host, "/scan/").concat(sessionId),
|
|
45
|
+
open: "".concat(IOS_APP_SCHEME, "://").concat(host, "/scan/").concat(sessionId, "?return=").concat(returnUrl),
|
|
42
46
|
// Lu par le bouton « Reprendre ma session » de l'app au premier lancement après installation.
|
|
43
47
|
resume: "https://".concat(host, "/scan/").concat(sessionId),
|
|
44
48
|
};
|
|
@@ -49,6 +53,20 @@ var NfcScanStep = function (_a) {
|
|
|
49
53
|
var _a;
|
|
50
54
|
(_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(iosAppLinks.resume).catch(function () { return undefined; });
|
|
51
55
|
};
|
|
56
|
+
// iOS ne permet pas de savoir si l'app est installée. Un seul bouton « Ouvrir » ; si la page est
|
|
57
|
+
// toujours visible après le délai (app absente : Safari affiche « adresse invalide »), on révèle
|
|
58
|
+
// « Installer ». Pas de redirection automatique vers l'App Store : pendant la confirmation iOS
|
|
59
|
+
// « Ouvrir dans ID Scan ? » la page reste visible, une redirection y enverrait à tort.
|
|
60
|
+
var _e = useState(false), showInstall = _e[0], setShowInstall = _e[1];
|
|
61
|
+
var installRevealTimerRef = useRef();
|
|
62
|
+
useEffect(function () { return function () { return clearTimeout(installRevealTimerRef.current); }; }, []);
|
|
63
|
+
var revealInstallIfAppDidNotOpen = function () {
|
|
64
|
+
clearTimeout(installRevealTimerRef.current);
|
|
65
|
+
installRevealTimerRef.current = setTimeout(function () {
|
|
66
|
+
if (document.visibilityState === "visible")
|
|
67
|
+
setShowInstall(true);
|
|
68
|
+
}, INSTALL_REVEAL_DELAY_MS);
|
|
69
|
+
};
|
|
52
70
|
var status = useNfcSseStatus({
|
|
53
71
|
sessionId: sessionId,
|
|
54
72
|
apiBaseUrl: apiBaseUrl,
|
|
@@ -160,7 +178,7 @@ var NfcScanStep = function (_a) {
|
|
|
160
178
|
return (jsx(MobilePageLayout, { footer: footer, children: jsx("div", { className: "px-4 py-6 pt-11 md:px-8 md:py-8", children: jsxs("div", { className: "w-full max-w-md mx-auto space-y-6", children: [jsxs("div", { className: "text-center space-y-4 mt-16 md:mt-20", children: [jsx(Title, { className: "text-xl md:text-2xl lg:text-3xl", children: title }), jsx(Subtitle, { className: "text-sm md:text-base text-gray-600 leading-relaxed whitespace-pre-line", children: subtitle })] }), jsx("div", { className: "flex-1 flex flex-col justify-center items-center gap-4", children: status === "success" ? (jsx(NfcSuccessAnimation, {})) : status === "completed" ? (jsxs("div", { className: "flex flex-col items-center gap-4 p-8", children: [jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.verifying", "Vérification en cours…") })] })) : status === "failed" ? (jsxs("div", { className: "flex flex-col items-center gap-2 p-8 text-center", children: [jsx("p", { className: "text-base font-semibold text-red-600", children: t("nfc_scan.failed_title", "Le scan n'a pas pu être vérifié") }), jsx("p", { className: "text-sm text-gray-600 leading-relaxed", children: t("nfc_scan.failed_description", "Après plusieurs tentatives, la lecture de votre document n'a pas pu être validée.") }), resetError && (jsx("p", { className: "text-sm text-red-600", role: "alert", children: resetError }))] })) : (
|
|
161
179
|
// Contenu principal QR/mobile — reste monté pour "pending" ET "opened", pour ne
|
|
162
180
|
// jamais démonter le canvas déjà généré.
|
|
163
|
-
jsxs(Fragment, { children: [qrError ? (jsx("div", { className: "text-red-500 text-center p-4", children: qrError })) : isIOS ? (jsxs("div", { className: "flex w-full flex-col items-center gap-3 p-4 text-center", children: [jsx("a", { href: iosAppLinks.open, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] text-sm font-medium hover:brightness-110 active:brightness-90", style: { backgroundColor: "var(--dk-btn-bg)", color: "var(--dk-btn-text)" }, children: t("nfc_scan.open_app_link", "Ouvrir l'application") }), jsx("a", { href: IOS_APP_STORE_URL, onClick: copyResumeLink, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] border border-gray-300 text-sm font-medium text-gray-600 hover:bg-black/5", children: t("nfc_scan.install_app_link", "Installer l'application") }), jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.install_app_hint", "Après l'installation, revenez sur cette page et appuyez sur « Ouvrir l'application ».") })] })) : isMobile ? (jsxs("div", { className: "flex flex-col items-center gap-4 p-8 text-center", children: [jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.opening_app", "Ouverture de l'application…") }), jsx("a", { href: nfcUrl, className: "text-sm font-medium text-blue-600 underline", children: t("nfc_scan.open_app_link", "Ouvrir l'application") })] })) : (jsx("div", { className: "bg-white p-4 rounded-lg shadow-lg border-2 border-gray-200", children: jsx("canvas", { ref: canvasRef }) })), status === "opened" && (jsxs("div", { className: "text-center space-y-1", children: [jsx("p", { className: "text-sm font-semibold", style: { color: "var(--uni-secondary-color, #0a9983)" }, children: t("nfc_scan.qr_opened_title", "QR code scanné") }), jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.qr_opened_description", "L'expérience NFC est ouverte sur votre smartphone. Continuez le scan sur votre téléphone.") }), jsxs("div", { className: "flex items-center justify-center gap-2 text-xs text-gray-500 pt-1", children: [jsx("span", { className: "h-2 w-2 rounded-full animate-pulse", style: { backgroundColor: "var(--uni-primary-color, #11e5c5)" } }), t("nfc_scan.waiting_completion", "En attente de la lecture NFC")] })] }))] })) })] }) }) }));
|
|
181
|
+
jsxs(Fragment, { children: [qrError ? (jsx("div", { className: "text-red-500 text-center p-4", children: qrError })) : isIOS ? (jsxs("div", { className: "flex w-full flex-col items-center gap-3 p-4 text-center", children: [jsx("a", { href: iosAppLinks.open, onClick: revealInstallIfAppDidNotOpen, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] text-sm font-medium hover:brightness-110 active:brightness-90", style: { backgroundColor: "var(--dk-btn-bg)", color: "var(--dk-btn-text)" }, children: t("nfc_scan.open_app_link", "Ouvrir l'application") }), showInstall ? (jsxs(Fragment, { children: [jsx("a", { href: IOS_APP_STORE_URL, onClick: copyResumeLink, className: "flex h-[48px] w-full items-center justify-center rounded-[12px] border border-gray-300 text-sm font-medium text-gray-600 hover:bg-black/5", children: t("nfc_scan.install_app_link", "Installer l'application") }), jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.install_app_hint", "Après l'installation, revenez sur cette page et appuyez sur « Ouvrir l'application ».") })] })) : null] })) : isMobile ? (jsxs("div", { className: "flex flex-col items-center gap-4 p-8 text-center", children: [jsx("div", { className: "animate-spin w-10 h-10 border-2 border-gray-300 border-t-blue-500 rounded-full" }), jsx("p", { className: "text-sm text-gray-600", children: t("nfc_scan.opening_app", "Ouverture de l'application…") }), jsx("a", { href: nfcUrl, className: "text-sm font-medium text-blue-600 underline", children: t("nfc_scan.open_app_link", "Ouvrir l'application") })] })) : (jsx("div", { className: "bg-white p-4 rounded-lg shadow-lg border-2 border-gray-200", children: jsx("canvas", { ref: canvasRef }) })), status === "opened" && (jsxs("div", { className: "text-center space-y-1", children: [jsx("p", { className: "text-sm font-semibold", style: { color: "var(--uni-secondary-color, #0a9983)" }, children: t("nfc_scan.qr_opened_title", "QR code scanné") }), jsx("p", { className: "text-xs text-gray-500 leading-relaxed", children: t("nfc_scan.qr_opened_description", "L'expérience NFC est ouverte sur votre smartphone. Continuez le scan sur votre téléphone.") }), jsxs("div", { className: "flex items-center justify-center gap-2 text-xs text-gray-500 pt-1", children: [jsx("span", { className: "h-2 w-2 rounded-full animate-pulse", style: { backgroundColor: "var(--uni-primary-color, #11e5c5)" } }), t("nfc_scan.waiting_completion", "En attente de la lecture NFC")] })] }))] })) })] }) }) }));
|
|
164
182
|
};
|
|
165
183
|
|
|
166
184
|
export { NfcScanStep as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState, useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
var SUCCESS_DISPLAY_DURATION_MS = 2500;
|
|
4
|
+
var RECONNECT_DELAY_MS = 2000;
|
|
4
5
|
function useNfcSseStatus(_a) {
|
|
5
6
|
var sessionId = _a.sessionId, apiBaseUrl = _a.apiBaseUrl, onCompleted = _a.onCompleted;
|
|
6
7
|
var _b = useState("pending"), status = _b[0], setStatus = _b[1];
|
|
@@ -10,42 +11,76 @@ function useNfcSseStatus(_a) {
|
|
|
10
11
|
if (!sessionId || !apiBaseUrl)
|
|
11
12
|
return;
|
|
12
13
|
var url = "".concat(apiBaseUrl, "/session/sdk/").concat(sessionId, "/nfc-status");
|
|
13
|
-
var source =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
var source = null;
|
|
15
|
+
// Statut terminal reçu : plus aucune (re)connexion, et `onCompleted` n'est appelé qu'une fois.
|
|
16
|
+
var finished = false;
|
|
17
|
+
var reconnectTimer;
|
|
18
|
+
var open = function () {
|
|
19
|
+
clearTimeout(reconnectTimer);
|
|
20
|
+
source === null || source === void 0 ? void 0 : source.close();
|
|
21
|
+
var current = new EventSource(url);
|
|
22
|
+
source = current;
|
|
23
|
+
current.onmessage = function (event) {
|
|
24
|
+
if (finished)
|
|
25
|
+
return;
|
|
26
|
+
try {
|
|
27
|
+
var data = JSON.parse(event.data);
|
|
28
|
+
if (data.status === "completed") {
|
|
29
|
+
finished = true;
|
|
30
|
+
current.close();
|
|
31
|
+
setStatus("success");
|
|
32
|
+
setTimeout(function () {
|
|
33
|
+
setStatus("completed");
|
|
34
|
+
onCompletedRef.current();
|
|
35
|
+
}, SUCCESS_DISPLAY_DURATION_MS);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// `failed` est terminal : le serveur ferme le flux, inutile de le rouvrir en boucle.
|
|
39
|
+
if (data.status === "failed")
|
|
40
|
+
finished = true;
|
|
41
|
+
setStatus(data.status);
|
|
42
|
+
}
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
catch (_a) {
|
|
45
|
+
// message malformé, on ignore
|
|
27
46
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
};
|
|
48
|
+
// EventSource se reconnecte seul tant qu'il est CONNECTING. Mais iOS coupe le flux quand
|
|
49
|
+
// Safari passe en arrière-plan pendant le scan dans l'app, et une réponse non-200 à la
|
|
50
|
+
// reconnexion le ferme définitivement (CLOSED) : on le rouvre alors nous-mêmes.
|
|
51
|
+
current.onerror = function () {
|
|
52
|
+
if (!finished && current.readyState === EventSource.CLOSED) {
|
|
53
|
+
reconnectTimer = setTimeout(open, RECONNECT_DELAY_MS);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
32
56
|
};
|
|
33
|
-
|
|
34
|
-
|
|
57
|
+
// Retour sur la page (depuis l'app de scan, ou restauration bfcache) : le flux a pu mourir
|
|
58
|
+
// pendant la suspension et l'event `completed` être perdu. On rouvre : le serveur renvoie le
|
|
59
|
+
// statut courant dès la connexion, donc le parcours avance sans recharger la page.
|
|
60
|
+
var reopenIfVisible = function () {
|
|
61
|
+
if (!finished && document.visibilityState === "visible")
|
|
62
|
+
open();
|
|
35
63
|
};
|
|
36
64
|
// Fermer le flux uniquement quand la page se ferme réellement, sinon le SSE reste ouvert côté
|
|
37
65
|
// serveur (heartbeat + listener qui fuient). `pagehide` couvre la fermeture d'onglet/navigation
|
|
38
66
|
// (plus fiable que `beforeunload` sur mobile).
|
|
39
67
|
//
|
|
40
68
|
// NE PAS fermer sur `visibilitychange`/`hidden` : le passage en arrière-plan est le geste
|
|
41
|
-
// NORMAL de l'utilisateur qui bascule vers son téléphone pour scanner le QR.
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
// NORMAL de l'utilisateur qui bascule vers son téléphone pour scanner le QR. On se contente de
|
|
70
|
+
// ROUVRIR au retour (`visible`), ce qui ne coupe jamais un flux encore utile.
|
|
71
|
+
var closeSource = function () {
|
|
72
|
+
clearTimeout(reconnectTimer);
|
|
73
|
+
source === null || source === void 0 ? void 0 : source.close();
|
|
74
|
+
};
|
|
75
|
+
open();
|
|
45
76
|
window.addEventListener("pagehide", closeSource);
|
|
77
|
+
window.addEventListener("pageshow", reopenIfVisible);
|
|
78
|
+
document.addEventListener("visibilitychange", reopenIfVisible);
|
|
46
79
|
return function () {
|
|
47
80
|
window.removeEventListener("pagehide", closeSource);
|
|
48
|
-
|
|
81
|
+
window.removeEventListener("pageshow", reopenIfVisible);
|
|
82
|
+
document.removeEventListener("visibilitychange", reopenIfVisible);
|
|
83
|
+
closeSource();
|
|
49
84
|
};
|
|
50
85
|
}, [sessionId, apiBaseUrl]);
|
|
51
86
|
return { status: status };
|