@wovvmap/ui-headless 0.0.0-stage → 1.2.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/README.md +24 -2
- package/dist/HeaderInfoController.d.ts +44 -0
- package/dist/HeaderInfoController.d.ts.map +1 -0
- package/dist/HeaderInfoController.js +112 -0
- package/dist/appearance.d.ts +26 -0
- package/dist/appearance.d.ts.map +1 -0
- package/dist/appearance.js +117 -0
- package/dist/classic/ClassicController.d.ts +124 -0
- package/dist/classic/ClassicController.d.ts.map +1 -0
- package/dist/classic/ClassicController.js +1131 -0
- package/dist/classic/classic.types.d.ts +111 -0
- package/dist/classic/classic.types.d.ts.map +1 -0
- package/dist/classic/classic.types.js +1 -0
- package/dist/classic/index.d.ts +3 -0
- package/dist/classic/index.d.ts.map +1 -0
- package/dist/classic/index.js +2 -0
- package/dist/components.d.ts +253 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +30 -0
- package/dist/directions/DirectionController.d.ts +76 -0
- package/dist/directions/DirectionController.d.ts.map +1 -0
- package/dist/directions/DirectionController.js +467 -0
- package/dist/directions/direction.types.d.ts +81 -0
- package/dist/directions/direction.types.d.ts.map +1 -0
- package/dist/directions/direction.types.js +1 -0
- package/dist/directions/directionPresentation.d.ts +17 -0
- package/dist/directions/directionPresentation.d.ts.map +1 -0
- package/dist/directions/directionPresentation.js +34 -0
- package/dist/flow/DiscoveryFlowController.d.ts +36 -0
- package/dist/flow/DiscoveryFlowController.d.ts.map +1 -0
- package/dist/flow/DiscoveryFlowController.js +162 -0
- package/dist/flow/FlowHistoryController.d.ts +14 -0
- package/dist/flow/FlowHistoryController.d.ts.map +1 -0
- package/dist/flow/FlowHistoryController.js +31 -0
- package/dist/flow/index.d.ts +3 -0
- package/dist/flow/index.d.ts.map +1 -0
- package/dist/flow/index.js +2 -0
- package/dist/gallery/PromotionGalleryController.d.ts +32 -0
- package/dist/gallery/PromotionGalleryController.d.ts.map +1 -0
- package/dist/gallery/PromotionGalleryController.js +80 -0
- package/dist/gallery/index.d.ts +2 -0
- package/dist/gallery/index.d.ts.map +1 -0
- package/dist/gallery/index.js +1 -0
- package/dist/headerInfo.d.ts +27 -0
- package/dist/headerInfo.d.ts.map +1 -0
- package/dist/headerInfo.js +70 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/presentation.d.ts +49 -0
- package/dist/presentation.d.ts.map +1 -0
- package/dist/presentation.js +116 -0
- package/dist/routes/RoutePreviewController.d.ts +61 -0
- package/dist/routes/RoutePreviewController.d.ts.map +1 -0
- package/dist/routes/RoutePreviewController.js +321 -0
- package/dist/routes/playback/RoutePlaybackController.d.ts +26 -0
- package/dist/routes/playback/RoutePlaybackController.d.ts.map +1 -0
- package/dist/routes/playback/RoutePlaybackController.js +115 -0
- package/dist/routes/routePlayback.types.d.ts +38 -0
- package/dist/routes/routePlayback.types.d.ts.map +1 -0
- package/dist/routes/routePlayback.types.js +1 -0
- package/dist/routes/routePreview.types.d.ts +71 -0
- package/dist/routes/routePreview.types.d.ts.map +1 -0
- package/dist/routes/routePreview.types.js +1 -0
- package/dist/routes/routePreviewPresentation.d.ts +8 -0
- package/dist/routes/routePreviewPresentation.d.ts.map +1 -0
- package/dist/routes/routePreviewPresentation.js +26 -0
- package/dist/routes/routeStepIcons.d.ts +15 -0
- package/dist/routes/routeStepIcons.d.ts.map +1 -0
- package/dist/routes/routeStepIcons.js +102 -0
- package/dist/routes/routeStepPresentation.d.ts +5 -0
- package/dist/routes/routeStepPresentation.d.ts.map +1 -0
- package/dist/routes/routeStepPresentation.js +15 -0
- package/dist/routes/routeSteps.types.d.ts +51 -0
- package/dist/routes/routeSteps.types.d.ts.map +1 -0
- package/dist/routes/routeSteps.types.js +1 -0
- package/dist/routes/steps/RouteStepsController.d.ts +49 -0
- package/dist/routes/steps/RouteStepsController.d.ts.map +1 -0
- package/dist/routes/steps/RouteStepsController.js +312 -0
- package/dist/saved-routes/SavedRoutesController.d.ts +76 -0
- package/dist/saved-routes/SavedRoutesController.d.ts.map +1 -0
- package/dist/saved-routes/SavedRoutesController.js +366 -0
- package/dist/storeHours.d.ts +19 -0
- package/dist/storeHours.d.ts.map +1 -0
- package/dist/storeHours.js +155 -0
- package/dist/storeList.d.ts +19 -0
- package/dist/storeList.d.ts.map +1 -0
- package/dist/storeList.js +21 -0
- package/dist/theme.d.ts +42 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +56 -0
- package/package.json +32 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** Use canonical indices, never FloorNumber aliases. Zero is a real index.
|
|
2
|
+
* Hinglish: Floor ka asli index hi command ko jayega; floor zero bhi valid hai. */
|
|
3
|
+
export function createFloorOptions(floors) {
|
|
4
|
+
return floors.map((floor, index) => ({
|
|
5
|
+
index: floor.index ?? index,
|
|
6
|
+
label: floor.FloorName,
|
|
7
|
+
shortLabel: floor.ShortName || floor.FloorName,
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
/** Resolve the small public floor list without looking up map nodes or requesting more data.
|
|
11
|
+
* Hinglish: Chhoti floor metadata se naam milega; NodePoint scan ya nayi API nahi chalegi. */
|
|
12
|
+
export function getFloorLabels(indices, floors = []) {
|
|
13
|
+
return indices
|
|
14
|
+
.map((index) => floors.find((floor) => floor.index === index)?.label ?? `Floor ${index}`)
|
|
15
|
+
.join(', ');
|
|
16
|
+
}
|
|
17
|
+
/** Stable row identity preserves group/node distinctions even when their IDs match.
|
|
18
|
+
* Hinglish: Group aur single store ki same ID ho tab bhi row identity alag rahegi. */
|
|
19
|
+
export function getStoreRowId(row) {
|
|
20
|
+
return row.kind === 'store' ? `store:${row.node.key}` : `group:${row.group.groupId}`;
|
|
21
|
+
}
|
|
22
|
+
/** Read only compact row fields; never expand every member to format one result.
|
|
23
|
+
* Hinglish: Row dikhane ke liye group ke saare nodes par loop nahi chalta. */
|
|
24
|
+
export function getStoreRowPresentation(row, locationsLabel = 'locations') {
|
|
25
|
+
const node = row.kind === 'store' ? row.node : row.group.representative;
|
|
26
|
+
return {
|
|
27
|
+
id: getStoreRowId(row),
|
|
28
|
+
title: row.kind === 'group' ? row.group.name : node.assets.locationName?.text || node.key,
|
|
29
|
+
subtitle: row.kind === 'group' ? `${row.group.memberCount} ${locationsLabel}` : node.floorName,
|
|
30
|
+
imageUrl: node.assets.logo || node.assets.brandLogo || undefined,
|
|
31
|
+
memberCount: row.kind === 'group' ? row.group.memberCount : 1,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Format only public details and at most seven days; never infer closed hours from absent data.
|
|
35
|
+
* Hinglish: Shared public metadata dikhate hain; missing timing ko closed assume nahi karte. */
|
|
36
|
+
export function getStoreDetailsFields(node) {
|
|
37
|
+
const fields = [];
|
|
38
|
+
const category = node.categoryName || node.categoryCode;
|
|
39
|
+
const subcategory = node.subCategoryName || node.subCategoryCode;
|
|
40
|
+
if (category !== undefined && category !== '')
|
|
41
|
+
fields.push({ label: 'Category', value: String(category) });
|
|
42
|
+
if (subcategory !== undefined && subcategory !== '')
|
|
43
|
+
fields.push({ label: 'Subcategory', value: String(subcategory) });
|
|
44
|
+
const days = {
|
|
45
|
+
mon: 'Monday',
|
|
46
|
+
tue: 'Tuesday',
|
|
47
|
+
wed: 'Wednesday',
|
|
48
|
+
thu: 'Thursday',
|
|
49
|
+
fri: 'Friday',
|
|
50
|
+
sat: 'Saturday',
|
|
51
|
+
sun: 'Sunday',
|
|
52
|
+
};
|
|
53
|
+
for (const day of Object.keys(days)) {
|
|
54
|
+
const hours = node.weeklyHours?.[day];
|
|
55
|
+
if (!hours?.open && !hours?.close)
|
|
56
|
+
continue;
|
|
57
|
+
fields.push({
|
|
58
|
+
label: days[day],
|
|
59
|
+
value: hours.open?.trim().toLowerCase() === 'closed' ||
|
|
60
|
+
hours.close?.trim().toLowerCase() === 'closed'
|
|
61
|
+
? 'Closed'
|
|
62
|
+
: hours.open && hours.close
|
|
63
|
+
? `${hours.open} – ${hours.close}`
|
|
64
|
+
: hours.open
|
|
65
|
+
? `Opens ${hours.open}`
|
|
66
|
+
: `Closes ${hours.close}`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return fields;
|
|
70
|
+
}
|
|
71
|
+
/** A constant-size visible slice; pagination remains the SDK's responsibility.
|
|
72
|
+
* Hinglish: Sirf screen ke aas-paas rows render hongi; search/pagination yahan nahi hota. */
|
|
73
|
+
export function getListWindow(count, offset, height = 288, rowHeight = 72, overscan = 3) {
|
|
74
|
+
const size = Math.max(1, Number.isFinite(rowHeight) ? rowHeight : 72);
|
|
75
|
+
const viewport = Math.max(1, Number.isFinite(height) ? height : 288);
|
|
76
|
+
const top = Math.min(Math.max(0, count * size - viewport), Math.max(0, Number.isFinite(offset) ? offset : 0));
|
|
77
|
+
const start = Math.max(0, Math.floor(top / size) - overscan);
|
|
78
|
+
const end = Math.min(count, start + Math.ceil(viewport / size) + 2 * overscan);
|
|
79
|
+
return { start: Math.max(0, start), end, top: Math.max(0, start) * size, total: count * size };
|
|
80
|
+
}
|
|
81
|
+
/** Public links are text unless they use an explicitly supported scheme.
|
|
82
|
+
* Hinglish: API ke javascript/data links ko clickable nahi banayenge. */
|
|
83
|
+
export function safeContactUrl(value, kind = 'website') {
|
|
84
|
+
if (kind === 'phone')
|
|
85
|
+
return /^\+?[\d ()-]+$/.test(value) ? `tel:${value}` : undefined;
|
|
86
|
+
if (kind === 'email')
|
|
87
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? `mailto:${value}` : undefined;
|
|
88
|
+
return /^https?:\/\//i.test(value) ? value : undefined;
|
|
89
|
+
}
|
|
90
|
+
/** Resolve public CDN paths without coupling a UI package to company/environment configuration.
|
|
91
|
+
* Hinglish: Relative logo ko host ke public CDN base se jodo; absolute URL same rahega. */
|
|
92
|
+
export function resolveUIAssetUrl(source, imageBaseUrl) {
|
|
93
|
+
if (!source)
|
|
94
|
+
return undefined;
|
|
95
|
+
if (/^https?:\/\//i.test(source))
|
|
96
|
+
return source;
|
|
97
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(source) || source.startsWith('//'))
|
|
98
|
+
return undefined;
|
|
99
|
+
if (!imageBaseUrl)
|
|
100
|
+
return source;
|
|
101
|
+
if (!/^https?:\/\//i.test(imageBaseUrl))
|
|
102
|
+
return undefined;
|
|
103
|
+
return `${imageBaseUrl.replace(/\/+$/, '')}/${source.replace(/^\/+/, '')}`;
|
|
104
|
+
}
|
|
105
|
+
/** Bounded display-only preview; SDK has already resolved eligibility and no UI clock filters it again.
|
|
106
|
+
* Hinglish: SDK ke ready active offers mein se sirf teen display hon; UI date policy dobara na likhe. */
|
|
107
|
+
export function getStoreOfferPreview(node) {
|
|
108
|
+
return (node.offers ?? []).slice(0, 3).map((offer, index) => ({
|
|
109
|
+
key: JSON.stringify([node.key, offer['offer_mst.id'] ?? null, index]),
|
|
110
|
+
title: offer['offer_mst.offer_name'] || 'Offer',
|
|
111
|
+
description: offer.offer_short_desc || offer.offer_remark || '',
|
|
112
|
+
until: offer['offer_mst.valid_to'] === undefined
|
|
113
|
+
? ''
|
|
114
|
+
: new Date(Number(offer['offer_mst.valid_to'])).toLocaleDateString('en-GB'),
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type MapLoadedData, type RouteSelection, type RoutePreferences, type RouteState } from '@wovvmap/contracts';
|
|
2
|
+
import type { RoutePreviewActions, RoutePreviewBindings, RoutePreviewSnapshot } from './routePreview.types.js';
|
|
3
|
+
import { RoutePlaybackController } from './playback/RoutePlaybackController.js';
|
|
4
|
+
import { RouteStepsController } from './steps/RouteStepsController.js';
|
|
5
|
+
/** Presentation commands only; the shared SDK owns validation, cancellation, selection and Start.
|
|
6
|
+
* Hinglish: UI request feedback sambhale; routing aur state transition existing SDK mein hi rahein. */
|
|
7
|
+
export declare class RoutePreviewController implements RoutePreviewActions {
|
|
8
|
+
private readonly viewer;
|
|
9
|
+
private readonly reviewSingleRoute;
|
|
10
|
+
readonly playback: RoutePlaybackController;
|
|
11
|
+
readonly steps: RouteStepsController;
|
|
12
|
+
private preferences;
|
|
13
|
+
private visible;
|
|
14
|
+
private previewMapId;
|
|
15
|
+
private map;
|
|
16
|
+
private ready;
|
|
17
|
+
private route;
|
|
18
|
+
private pending;
|
|
19
|
+
private error;
|
|
20
|
+
private request;
|
|
21
|
+
private event;
|
|
22
|
+
private connection;
|
|
23
|
+
private connected;
|
|
24
|
+
private readonly listeners;
|
|
25
|
+
private snapshot;
|
|
26
|
+
constructor(viewer: RoutePreviewBindings, reviewSingleRoute?: boolean);
|
|
27
|
+
setVisible(visible: boolean): void;
|
|
28
|
+
getSnapshot: () => RoutePreviewSnapshot;
|
|
29
|
+
/** Local screen intent only; route buffers, camera activation and simulation remain SDK-owned.
|
|
30
|
+
* Hinglish: Input/list se map preview khule; Generate, Start ya Play dobara nahi chale. */
|
|
31
|
+
viewRoute: () => void;
|
|
32
|
+
reviewRoute: () => void;
|
|
33
|
+
/** Separate manual inspection from the simulation clock, at the user intent only.
|
|
34
|
+
* Hinglish: Render/effect se nahi; Show steps click par hi running simulation pause ho. */
|
|
35
|
+
toggleSteps: () => void;
|
|
36
|
+
subscribe: (listener: () => void) => (() => void);
|
|
37
|
+
connect: () => (() => void);
|
|
38
|
+
/** Hydrate a committed binding once; map/ready delivery may follow its route event.
|
|
39
|
+
* Hinglish: Nayi binding ka accepted route padhein; har render/floor par read ya Generate nahi. */
|
|
40
|
+
private hydrate;
|
|
41
|
+
syncMap(map: MapLoadedData | null, ready: boolean): void;
|
|
42
|
+
handleEndpointsChanged: () => void;
|
|
43
|
+
handleChanged: (state: RouteState) => void;
|
|
44
|
+
private acceptRoute;
|
|
45
|
+
/** Explicit preference intent retires an old path; render/watchers never regenerate it.
|
|
46
|
+
* Hinglish: Choice badle to old route clear ho, endpoints bachein; Generate user hi kare. */
|
|
47
|
+
setPreferences: (preferences: RoutePreferences) => void;
|
|
48
|
+
generate: () => void;
|
|
49
|
+
select: (selection: RouteSelection) => void;
|
|
50
|
+
start: (selection: RouteSelection) => void;
|
|
51
|
+
stop: () => void;
|
|
52
|
+
clear: () => void;
|
|
53
|
+
/** Supersede only queued UI feedback before the explicit Back owner clears the SDK route.
|
|
54
|
+
* Hinglish: Back par unsent Generate ruk jaye; actual Clear SDK command se hi ho, unmount se nahi. */
|
|
55
|
+
dismissFeedback(): void;
|
|
56
|
+
private validChoice;
|
|
57
|
+
private run;
|
|
58
|
+
private readSnapshot;
|
|
59
|
+
private publish;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=RoutePreviewController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutePreviewController.d.ts","sourceRoot":"","sources":["../../src/routes/RoutePreviewController.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAEnE;uGACuG;AACvG,qBAAa,sBAAuB,YAAW,mBAAmB;IAkB9D,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAlBpC,SAAgB,QAAQ,EAAE,uBAAuB,CAAA;IACjD,SAAgB,KAAK,EAAE,oBAAoB,CAAA;IAC3C,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,GAAG,CAA6B;IACxC,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,OAAO,CAAI;IACnB,OAAO,CAAC,KAAK,CAAI;IACjB,OAAO,CAAC,UAAU,CAAI;IACtB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,OAAO,CAAC,QAAQ,CAAsB;gBAEnB,MAAM,EAAE,oBAAoB,EAC5B,iBAAiB,UAAQ;IA0B5C,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMlC,WAAW,QAAO,oBAAoB,CAAiB;IACvD;+FAC2F;IAC3F,SAAS,QAAO,IAAI,CAKnB;IACD,WAAW,QAAO,IAAI,CAYrB;IACD;+FAC2F;IAC3F,WAAW,QAAO,IAAI,CAuBrB;IACD,SAAS,GAAI,UAAU,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CAG/C;IACD,OAAO,QAAO,CAAC,MAAM,IAAI,CAAC,CAoBzB;IACD;uGACmG;IACnG,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAgBxD,sBAAsB,QAAO,IAAI,CAKhC;IACD,aAAa,GAAI,OAAO,UAAU,KAAG,IAAI,CAUxC;IACD,OAAO,CAAC,WAAW;IAYnB;iGAC6F;IAC7F,cAAc,GAAI,aAAa,gBAAgB,KAAG,IAAI,CAUrD;IACD,QAAQ,QAAO,IAAI,CAUlB;IACD,MAAM,GAAI,WAAW,cAAc,KAAG,IAAI,CAKzC;IACD,KAAK,GAAI,WAAW,cAAc,KAAG,IAAI,CAUxC;IACD,IAAI,QAAO,IAAI,CASd;IACD,KAAK,QAAO,IAAI,CAGf;IACD;0GACsG;IACtG,eAAe,IAAI,IAAI;IAOvB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,GAAG;IAiCX,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,OAAO;CAqBhB"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { toViewerCommandError, } from '@wovvmap/contracts';
|
|
2
|
+
import { RoutePlaybackController } from './playback/RoutePlaybackController.js';
|
|
3
|
+
import { RouteStepsController } from './steps/RouteStepsController.js';
|
|
4
|
+
/** Presentation commands only; the shared SDK owns validation, cancellation, selection and Start.
|
|
5
|
+
* Hinglish: UI request feedback sambhale; routing aur state transition existing SDK mein hi rahein. */
|
|
6
|
+
export class RoutePreviewController {
|
|
7
|
+
viewer;
|
|
8
|
+
reviewSingleRoute;
|
|
9
|
+
playback;
|
|
10
|
+
steps;
|
|
11
|
+
preferences;
|
|
12
|
+
visible = false;
|
|
13
|
+
previewMapId = null;
|
|
14
|
+
map = null;
|
|
15
|
+
ready = false;
|
|
16
|
+
route = null;
|
|
17
|
+
pending = null;
|
|
18
|
+
error = null;
|
|
19
|
+
request = 0;
|
|
20
|
+
event = 0;
|
|
21
|
+
connection = 0;
|
|
22
|
+
connected = false;
|
|
23
|
+
listeners = new Set();
|
|
24
|
+
snapshot;
|
|
25
|
+
constructor(viewer, reviewSingleRoute = false) {
|
|
26
|
+
this.viewer = viewer;
|
|
27
|
+
this.reviewSingleRoute = reviewSingleRoute;
|
|
28
|
+
this.playback = new RoutePlaybackController(viewer, () => {
|
|
29
|
+
const endpoints = viewer.getEndpoints();
|
|
30
|
+
return endpoints
|
|
31
|
+
? { mallId: endpoints.mallId, expectedRevision: endpoints.revision }
|
|
32
|
+
: undefined;
|
|
33
|
+
}, () => this.publish());
|
|
34
|
+
this.steps = new RouteStepsController(viewer.getRouteSteps, () => {
|
|
35
|
+
const endpoints = viewer.getEndpoints();
|
|
36
|
+
return endpoints
|
|
37
|
+
? { mallId: endpoints.mallId, expectedRevision: endpoints.revision }
|
|
38
|
+
: undefined;
|
|
39
|
+
}, viewer.selectRouteStep, viewer, () => viewer.getProgress?.()?.activeStep?.stepIndex ?? null);
|
|
40
|
+
this.snapshot = this.readSnapshot();
|
|
41
|
+
}
|
|
42
|
+
setVisible(visible) {
|
|
43
|
+
if (visible === this.visible)
|
|
44
|
+
return;
|
|
45
|
+
this.visible = visible;
|
|
46
|
+
this.steps.sync(this.route, visible && this.ready);
|
|
47
|
+
this.publish();
|
|
48
|
+
}
|
|
49
|
+
getSnapshot = () => this.snapshot;
|
|
50
|
+
/** Local screen intent only; route buffers, camera activation and simulation remain SDK-owned.
|
|
51
|
+
* Hinglish: Input/list se map preview khule; Generate, Start ya Play dobara nahi chale. */
|
|
52
|
+
viewRoute = () => {
|
|
53
|
+
if (!this.snapshot.reviewing || !this.ready || this.pending)
|
|
54
|
+
return;
|
|
55
|
+
this.previewMapId = this.route.routeSet.routeSetId;
|
|
56
|
+
this.steps.setExpanded(false);
|
|
57
|
+
this.publish();
|
|
58
|
+
};
|
|
59
|
+
reviewRoute = () => {
|
|
60
|
+
if (!this.reviewSingleRoute ||
|
|
61
|
+
this.route?.stage !== 'preview' ||
|
|
62
|
+
this.route.routeSet?.options.length !== 1 ||
|
|
63
|
+
!this.steps.getSnapshot().enabled ||
|
|
64
|
+
!this.ready ||
|
|
65
|
+
this.pending)
|
|
66
|
+
return;
|
|
67
|
+
this.previewMapId = null;
|
|
68
|
+
this.publish();
|
|
69
|
+
};
|
|
70
|
+
/** Separate manual inspection from the simulation clock, at the user intent only.
|
|
71
|
+
* Hinglish: Render/effect se nahi; Show steps click par hi running simulation pause ho. */
|
|
72
|
+
toggleSteps = () => {
|
|
73
|
+
const route = this.route;
|
|
74
|
+
if (!this.steps.getSnapshot().enabled || !this.ready || route?.stage !== 'guiding')
|
|
75
|
+
return;
|
|
76
|
+
if (!this.steps.getSnapshot().expanded) {
|
|
77
|
+
const status = this.playback.getSnapshot().state?.status;
|
|
78
|
+
if (status === 'running' ||
|
|
79
|
+
status === 'starting' ||
|
|
80
|
+
status === 'transitioning' ||
|
|
81
|
+
status === 'countdown')
|
|
82
|
+
this.playback.pause();
|
|
83
|
+
// Pause can synchronously notify a newer Stop/route choice; that intent owns the panel.
|
|
84
|
+
// Hinglish: Pause ke event mein Stop ya route change aaye to purana Show steps retire ho.
|
|
85
|
+
if (!this.ready ||
|
|
86
|
+
this.route?.stage !== 'guiding' ||
|
|
87
|
+
this.route.routeSet?.routeSetId !== route.routeSet?.routeSetId ||
|
|
88
|
+
this.route.selectedRouteId !== route.selectedRouteId)
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.steps.toggle();
|
|
92
|
+
};
|
|
93
|
+
subscribe = (listener) => {
|
|
94
|
+
this.listeners.add(listener);
|
|
95
|
+
return () => this.listeners.delete(listener);
|
|
96
|
+
};
|
|
97
|
+
connect = () => {
|
|
98
|
+
const connection = ++this.connection;
|
|
99
|
+
this.connected = true;
|
|
100
|
+
const off = this.viewer.subscribe(this.handleChanged);
|
|
101
|
+
const offSteps = this.steps.subscribe(() => this.publish());
|
|
102
|
+
this.hydrate();
|
|
103
|
+
return () => {
|
|
104
|
+
off();
|
|
105
|
+
offSteps();
|
|
106
|
+
queueMicrotask(() => {
|
|
107
|
+
if (connection !== this.connection)
|
|
108
|
+
return;
|
|
109
|
+
++this.connection;
|
|
110
|
+
this.connected = false;
|
|
111
|
+
++this.request;
|
|
112
|
+
this.ready = false;
|
|
113
|
+
this.steps.sync(this.route, false);
|
|
114
|
+
this.pending = null;
|
|
115
|
+
this.publish();
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/** Hydrate a committed binding once; map/ready delivery may follow its route event.
|
|
120
|
+
* Hinglish: Nayi binding ka accepted route padhein; har render/floor par read ya Generate nahi. */
|
|
121
|
+
hydrate() {
|
|
122
|
+
if (!this.connected || !this.ready)
|
|
123
|
+
return;
|
|
124
|
+
const connection = this.connection, event = this.event, map = this.map, request = this.request;
|
|
125
|
+
void Promise.resolve()
|
|
126
|
+
.then(() => this.viewer.getRoute())
|
|
127
|
+
.then((state) => {
|
|
128
|
+
if (connection === this.connection &&
|
|
129
|
+
event === this.event &&
|
|
130
|
+
map === this.map &&
|
|
131
|
+
request === this.request &&
|
|
132
|
+
this.ready &&
|
|
133
|
+
this.acceptRoute(state))
|
|
134
|
+
this.publish();
|
|
135
|
+
})
|
|
136
|
+
.catch(() => { });
|
|
137
|
+
}
|
|
138
|
+
syncMap(map, ready) {
|
|
139
|
+
const changed = map !== this.map || ready !== this.ready;
|
|
140
|
+
if (map !== this.map || !ready) {
|
|
141
|
+
++this.request;
|
|
142
|
+
this.pending = null;
|
|
143
|
+
this.error = null;
|
|
144
|
+
if (map !== this.map) {
|
|
145
|
+
this.route = null;
|
|
146
|
+
this.preferences = undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this.map = map;
|
|
150
|
+
this.ready = ready && map !== null;
|
|
151
|
+
if (changed)
|
|
152
|
+
this.hydrate();
|
|
153
|
+
this.publish();
|
|
154
|
+
}
|
|
155
|
+
handleEndpointsChanged = () => {
|
|
156
|
+
++this.request;
|
|
157
|
+
this.pending = null;
|
|
158
|
+
this.error = null;
|
|
159
|
+
this.publish();
|
|
160
|
+
};
|
|
161
|
+
handleChanged = (state) => {
|
|
162
|
+
++this.event;
|
|
163
|
+
if (!this.acceptRoute(state))
|
|
164
|
+
return;
|
|
165
|
+
// Terminal domain events retire local command feedback too; old ACKs cannot revive an error/spinner.
|
|
166
|
+
// Hinglish: SDK ne route clear/fail kar diya ho to purana ACK nayi UI ko busy/error na banaye.
|
|
167
|
+
if (this.pending && (state.stage === 'idle' || state.stage === 'failed')) {
|
|
168
|
+
++this.request;
|
|
169
|
+
this.pending = null;
|
|
170
|
+
}
|
|
171
|
+
this.publish();
|
|
172
|
+
};
|
|
173
|
+
acceptRoute(state) {
|
|
174
|
+
const endpoints = this.viewer.getEndpoints();
|
|
175
|
+
if (state.map &&
|
|
176
|
+
(state.map.mallId !== this.map?.mallId || state.map.revision !== endpoints?.revision))
|
|
177
|
+
return false;
|
|
178
|
+
if (state.routeSet?.routeSetId !== this.route?.routeSet?.routeSetId)
|
|
179
|
+
this.previewMapId = null;
|
|
180
|
+
this.route = state;
|
|
181
|
+
this.error = null;
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
/** Explicit preference intent retires an old path; render/watchers never regenerate it.
|
|
185
|
+
* Hinglish: Choice badle to old route clear ho, endpoints bachein; Generate user hi kare. */
|
|
186
|
+
setPreferences = (preferences) => {
|
|
187
|
+
if (!this.ready)
|
|
188
|
+
return;
|
|
189
|
+
const next = Object.freeze({
|
|
190
|
+
...preferences,
|
|
191
|
+
...(preferences.allow ? { allow: Object.freeze({ ...preferences.allow }) } : {}),
|
|
192
|
+
});
|
|
193
|
+
if (JSON.stringify(this.preferences ?? {}) === JSON.stringify(next))
|
|
194
|
+
return;
|
|
195
|
+
this.preferences = next;
|
|
196
|
+
if (this.route?.routeSet || this.pending || this.route?.stage === 'generating')
|
|
197
|
+
this.clear();
|
|
198
|
+
else
|
|
199
|
+
this.publish();
|
|
200
|
+
};
|
|
201
|
+
generate = () => {
|
|
202
|
+
if (!this.snapshot.canGenerate ||
|
|
203
|
+
this.pending ||
|
|
204
|
+
this.route?.stage === 'generating' ||
|
|
205
|
+
this.route?.stage === 'starting')
|
|
206
|
+
return;
|
|
207
|
+
const preferences = this.preferences;
|
|
208
|
+
this.run('generate', (context) => this.viewer.generateRoute(preferences, context));
|
|
209
|
+
};
|
|
210
|
+
select = (selection) => {
|
|
211
|
+
if (!this.validChoice(selection) || this.pending || this.route?.stage !== 'preview')
|
|
212
|
+
return;
|
|
213
|
+
if (selection.routeId === this.route.selectedRouteId)
|
|
214
|
+
return;
|
|
215
|
+
const choice = { routeSetId: selection.routeSetId, routeId: selection.routeId };
|
|
216
|
+
this.run('select', (context) => this.viewer.selectRoute(choice, context));
|
|
217
|
+
};
|
|
218
|
+
start = (selection) => {
|
|
219
|
+
if (!this.validChoice(selection) ||
|
|
220
|
+
this.pending ||
|
|
221
|
+
this.route?.stage !== 'preview' ||
|
|
222
|
+
selection.routeId !== this.route.selectedRouteId)
|
|
223
|
+
return;
|
|
224
|
+
const choice = { routeSetId: selection.routeSetId, routeId: selection.routeId };
|
|
225
|
+
this.run('start', (context) => this.viewer.startRoute(choice, context));
|
|
226
|
+
};
|
|
227
|
+
stop = () => {
|
|
228
|
+
if (!this.ready ||
|
|
229
|
+
this.pending === 'stop' ||
|
|
230
|
+
this.pending === 'clear' ||
|
|
231
|
+
(this.route?.stage !== 'guiding' && this.route?.stage !== 'starting'))
|
|
232
|
+
return;
|
|
233
|
+
this.run('stop', (context) => this.viewer.stopRoute(context));
|
|
234
|
+
};
|
|
235
|
+
clear = () => {
|
|
236
|
+
if (!this.ready || this.pending === 'clear')
|
|
237
|
+
return;
|
|
238
|
+
this.run('clear', (context) => this.viewer.clearRoute(context));
|
|
239
|
+
};
|
|
240
|
+
/** Supersede only queued UI feedback before the explicit Back owner clears the SDK route.
|
|
241
|
+
* Hinglish: Back par unsent Generate ruk jaye; actual Clear SDK command se hi ho, unmount se nahi. */
|
|
242
|
+
dismissFeedback() {
|
|
243
|
+
++this.request;
|
|
244
|
+
this.pending = null;
|
|
245
|
+
this.error = null;
|
|
246
|
+
this.steps.dismissFeedback();
|
|
247
|
+
this.publish();
|
|
248
|
+
}
|
|
249
|
+
validChoice(choice) {
|
|
250
|
+
return (this.snapshot.canGenerate &&
|
|
251
|
+
!!this.route?.routeSet &&
|
|
252
|
+
this.route.routeSet.routeSetId === choice.routeSetId &&
|
|
253
|
+
this.route.routeSet.options.some((option) => option.routeId === choice.routeId));
|
|
254
|
+
}
|
|
255
|
+
run(pending, action) {
|
|
256
|
+
const endpoints = this.viewer.getEndpoints();
|
|
257
|
+
if (!this.ready || !endpoints || endpoints.mallId !== this.map?.mallId)
|
|
258
|
+
return;
|
|
259
|
+
const request = ++this.request;
|
|
260
|
+
const map = this.map;
|
|
261
|
+
this.pending = pending;
|
|
262
|
+
this.error = null;
|
|
263
|
+
this.publish();
|
|
264
|
+
void Promise.resolve()
|
|
265
|
+
.then(() => {
|
|
266
|
+
if (request !== this.request || map !== this.map || !this.ready)
|
|
267
|
+
return;
|
|
268
|
+
return action({ mallId: endpoints.mallId, expectedRevision: endpoints.revision });
|
|
269
|
+
})
|
|
270
|
+
.catch((error) => {
|
|
271
|
+
if (request === this.request && map === this.map && this.ready) {
|
|
272
|
+
const failure = toViewerCommandError(error);
|
|
273
|
+
// Stop/teardown cancellations and already reported errors have no second UI error owner.
|
|
274
|
+
// Hinglish: Normal cancel ya pehle reported failure ka duplicate error card nahi dikhana hai.
|
|
275
|
+
this.error = failure?.code === 'CANCELLED' ? null : (failure?.message ?? null);
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
.finally(() => {
|
|
279
|
+
// ACKs only settle local feedback; accepted route data always comes from routeChanged.
|
|
280
|
+
// Hinglish: Late ACK route state nahi likhe; nayi action ka pending/error bhi na hataye.
|
|
281
|
+
if (request === this.request) {
|
|
282
|
+
this.pending = null;
|
|
283
|
+
this.publish();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
readSnapshot() {
|
|
288
|
+
const endpoints = this.viewer.getEndpoints();
|
|
289
|
+
return {
|
|
290
|
+
preferences: this.preferences,
|
|
291
|
+
reviewing: this.reviewSingleRoute &&
|
|
292
|
+
this.route?.stage === 'preview' &&
|
|
293
|
+
this.route.routeSet?.options.length === 1 &&
|
|
294
|
+
this.steps.getSnapshot().enabled &&
|
|
295
|
+
this.previewMapId !== this.route.routeSet.routeSetId,
|
|
296
|
+
playback: this.playback.getSnapshot(),
|
|
297
|
+
steps: this.steps.getSnapshot(),
|
|
298
|
+
route: this.route,
|
|
299
|
+
ready: this.ready,
|
|
300
|
+
canGenerate: this.ready &&
|
|
301
|
+
endpoints?.mallId === this.map?.mallId &&
|
|
302
|
+
!!endpoints?.origin &&
|
|
303
|
+
!!endpoints.destination &&
|
|
304
|
+
!endpoints.conflict,
|
|
305
|
+
pending: this.pending,
|
|
306
|
+
error: this.error,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
publish() {
|
|
310
|
+
this.playback.sync(this.route, this.visible && this.ready && this.pending !== 'stop' && this.pending !== 'clear');
|
|
311
|
+
this.steps.sync(this.route, this.visible && this.ready && this.pending !== 'stop' && this.pending !== 'clear');
|
|
312
|
+
if (this.readSnapshot().reviewing && this.visible && this.ready && !this.pending)
|
|
313
|
+
this.steps.setExpanded(true);
|
|
314
|
+
const next = this.readSnapshot();
|
|
315
|
+
if (Object.entries(next).every(([key, value]) => Object.is(this.snapshot[key], value)))
|
|
316
|
+
return;
|
|
317
|
+
this.snapshot = next;
|
|
318
|
+
for (const listener of this.listeners)
|
|
319
|
+
listener();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type EndpointContext, type RouteState, type RoutePlaybackOptions } from '@wovvmap/contracts';
|
|
2
|
+
import type { RoutePlaybackActions, RoutePlaybackBindings, RoutePlaybackSnapshot, RoutePlaybackProgressSource } from '../routePlayback.types.js';
|
|
3
|
+
/** Shared command feedback only; the existing route subscription supplies authoritative playback.
|
|
4
|
+
* Hinglish: Na naya store/subscription, na timer; ACK sirf pending hata sakta hai, state nahi likhta. */
|
|
5
|
+
export declare class RoutePlaybackController implements RoutePlaybackActions {
|
|
6
|
+
private readonly viewer;
|
|
7
|
+
private readonly context;
|
|
8
|
+
private readonly changed;
|
|
9
|
+
private route;
|
|
10
|
+
private ready;
|
|
11
|
+
private request;
|
|
12
|
+
private snapshot;
|
|
13
|
+
constructor(viewer: RoutePlaybackBindings & RoutePlaybackProgressSource, context: () => EndpointContext | undefined, changed: () => void);
|
|
14
|
+
getProgress: () => import("@wovvmap/contracts").RoutePlaybackProgress | null;
|
|
15
|
+
subscribeProgress: (listener: () => void) => () => void;
|
|
16
|
+
getSnapshot: () => RoutePlaybackSnapshot;
|
|
17
|
+
sync(route: RouteState | null, ready: boolean): void;
|
|
18
|
+
play: () => void;
|
|
19
|
+
pause: () => void;
|
|
20
|
+
resume: () => void;
|
|
21
|
+
stop: () => void;
|
|
22
|
+
replay: () => void;
|
|
23
|
+
updateOptions: (options: RoutePlaybackOptions) => void;
|
|
24
|
+
private run;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=RoutePlaybackController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutePlaybackController.d.ts","sourceRoot":"","sources":["../../../src/routes/playback/RoutePlaybackController.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,UAAU,EAEf,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EAErB,2BAA2B,EAC5B,MAAM,wBAAwB,CAAA;AAE/B;yGACyG;AACzG,qBAAa,uBAAwB,YAAW,oBAAoB;IAWhE,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ1B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,OAAO,CAAI;IACnB,OAAO,CAAC,QAAQ,CAKf;gBAEkB,MAAM,EAAE,qBAAqB,GAAG,2BAA2B,EAC3D,OAAO,EAAE,MAAM,eAAe,GAAG,SAAS,EAC1C,OAAO,EAAE,MAAM,IAAI;IAEtC,WAAW,kEAA4C;IACvD,iBAAiB,GAAI,UAAU,MAAM,IAAI,gBACgB;IACzD,WAAW,QAAO,qBAAqB,CAAiB;IACxD,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAgDpD,IAAI,QAAO,IAAI,CAGZ;IACH,KAAK,QAAO,IAAI,CAGb;IACH,MAAM,QAAO,IAAI,CAGd;IACH,IAAI,QAAO,IAAI,CAGZ;IACH,MAAM,QAAO,IAAI,CAGd;IACH,aAAa,GAAI,SAAS,oBAAoB,KAAG,IAAI,CAGpD;IACD,OAAO,CAAC,GAAG;CA0CZ"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { toViewerCommandError, } from '@wovvmap/contracts';
|
|
2
|
+
/** Shared command feedback only; the existing route subscription supplies authoritative playback.
|
|
3
|
+
* Hinglish: Na naya store/subscription, na timer; ACK sirf pending hata sakta hai, state nahi likhta. */
|
|
4
|
+
export class RoutePlaybackController {
|
|
5
|
+
viewer;
|
|
6
|
+
context;
|
|
7
|
+
changed;
|
|
8
|
+
route = null;
|
|
9
|
+
ready = false;
|
|
10
|
+
request = 0;
|
|
11
|
+
snapshot = {
|
|
12
|
+
enabled: false,
|
|
13
|
+
state: null,
|
|
14
|
+
pending: null,
|
|
15
|
+
error: null,
|
|
16
|
+
};
|
|
17
|
+
constructor(viewer, context, changed) {
|
|
18
|
+
this.viewer = viewer;
|
|
19
|
+
this.context = context;
|
|
20
|
+
this.changed = changed;
|
|
21
|
+
}
|
|
22
|
+
getProgress = () => this.viewer.getProgress?.() ?? null;
|
|
23
|
+
subscribeProgress = (listener) => this.viewer.subscribeProgress?.(listener) ?? (() => { });
|
|
24
|
+
getSnapshot = () => this.snapshot;
|
|
25
|
+
sync(route, ready) {
|
|
26
|
+
const before = this.route?.playback, next = route?.playback;
|
|
27
|
+
const playbackChanged = before?.status !== next?.status ||
|
|
28
|
+
before?.mode !== next?.mode ||
|
|
29
|
+
before?.speed !== next?.speed ||
|
|
30
|
+
before?.cameraFollow !== next?.cameraFollow ||
|
|
31
|
+
before?.stepSync !== next?.stepSync ||
|
|
32
|
+
before?.startDelayMs !== next?.startDelayMs ||
|
|
33
|
+
before?.finishView !== next?.finishView ||
|
|
34
|
+
before?.finishDelayMs !== next?.finishDelayMs ||
|
|
35
|
+
before?.countdownSeconds !== next?.countdownSeconds ||
|
|
36
|
+
before?.transition !== next?.transition ||
|
|
37
|
+
before?.unavailableReason !== next?.unavailableReason;
|
|
38
|
+
const retired = route?.routeSet?.routeSetId !== this.route?.routeSet?.routeSetId ||
|
|
39
|
+
route?.selectedRouteId !== this.route?.selectedRouteId ||
|
|
40
|
+
route?.stage !== 'guiding' ||
|
|
41
|
+
route.config.simulation === 'off' ||
|
|
42
|
+
!ready;
|
|
43
|
+
this.route = route;
|
|
44
|
+
this.ready = ready;
|
|
45
|
+
// Accepted lifecycle/preferences settle button feedback even if the Native ACK arrives later.
|
|
46
|
+
// Hinglish: External Stop/Replay ke baad old ACK ka spinner/error nayi state ko block na kare.
|
|
47
|
+
const settled = retired || (playbackChanged && next?.status !== 'starting');
|
|
48
|
+
if (settled && this.snapshot.pending)
|
|
49
|
+
this.request++;
|
|
50
|
+
const enabled = ready &&
|
|
51
|
+
route?.stage === 'guiding' &&
|
|
52
|
+
route.config.simulation !== 'off' &&
|
|
53
|
+
!!this.viewer.startRoutePlayback &&
|
|
54
|
+
!!this.viewer.pauseRoutePlayback &&
|
|
55
|
+
!!this.viewer.resumeRoutePlayback &&
|
|
56
|
+
!!this.viewer.stopRoutePlayback &&
|
|
57
|
+
!!this.viewer.replayRoutePlayback &&
|
|
58
|
+
!!this.viewer.updateRoutePlaybackOptions;
|
|
59
|
+
const state = route?.playback ?? null, pending = settled ? null : this.snapshot.pending, error = retired || playbackChanged ? null : this.snapshot.error;
|
|
60
|
+
if (this.snapshot.enabled !== enabled ||
|
|
61
|
+
this.snapshot.state !== state ||
|
|
62
|
+
this.snapshot.pending !== pending ||
|
|
63
|
+
this.snapshot.error !== error)
|
|
64
|
+
this.snapshot = { enabled, state, pending, error };
|
|
65
|
+
}
|
|
66
|
+
play = () => this.run('startRoutePlayback', (selection, context) => this.viewer.startRoutePlayback?.(selection, context));
|
|
67
|
+
pause = () => this.run('pauseRoutePlayback', (selection, context) => this.viewer.pauseRoutePlayback?.(selection, context));
|
|
68
|
+
resume = () => this.run('resumeRoutePlayback', (selection, context) => this.viewer.resumeRoutePlayback?.(selection, context));
|
|
69
|
+
stop = () => this.run('stopRoutePlayback', (selection, context) => this.viewer.stopRoutePlayback?.(selection, context));
|
|
70
|
+
replay = () => this.run('replayRoutePlayback', (selection, context) => this.viewer.replayRoutePlayback?.(selection, context));
|
|
71
|
+
updateOptions = (options) => {
|
|
72
|
+
const owned = { ...options };
|
|
73
|
+
this.run('updateRoutePlaybackOptions', () => this.viewer.updateRoutePlaybackOptions?.(owned));
|
|
74
|
+
};
|
|
75
|
+
run(command, action) {
|
|
76
|
+
if (!this.snapshot.enabled || !this.route?.routeSet || !this.route.selectedRouteId)
|
|
77
|
+
return;
|
|
78
|
+
const selection = {
|
|
79
|
+
routeSetId: this.route.routeSet.routeSetId,
|
|
80
|
+
routeId: this.route.selectedRouteId,
|
|
81
|
+
}, context = this.context(), request = ++this.request;
|
|
82
|
+
this.snapshot = { ...this.snapshot, pending: command, error: null };
|
|
83
|
+
this.changed();
|
|
84
|
+
// Dispatch cheap intents at the user event, not a later microtask that could overtake an SDK Stop.
|
|
85
|
+
// Hinglish: Play phir SDK Stop ka same-tick order sahi rahe; clock/mesh work common owner kare.
|
|
86
|
+
let work;
|
|
87
|
+
try {
|
|
88
|
+
if (request === this.request && this.ready)
|
|
89
|
+
work = action(selection, context);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
work = Promise.reject(error);
|
|
93
|
+
}
|
|
94
|
+
void Promise.resolve(work)
|
|
95
|
+
.catch((error) => {
|
|
96
|
+
if (request !== this.request)
|
|
97
|
+
return;
|
|
98
|
+
const failure = toViewerCommandError(error);
|
|
99
|
+
this.snapshot = {
|
|
100
|
+
...this.snapshot,
|
|
101
|
+
error: !failure || failure.code === 'CANCELLED'
|
|
102
|
+
? null
|
|
103
|
+
: failure?.code === 'UNAVAILABLE'
|
|
104
|
+
? 'Playback is unavailable for this mode or floor. Choose a compatible mode or floor.'
|
|
105
|
+
: 'Playback could not be updated.',
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
.finally(() => {
|
|
109
|
+
if (request === this.request) {
|
|
110
|
+
this.snapshot = { ...this.snapshot, pending: null };
|
|
111
|
+
this.changed();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|