en:outskirts:mages-peaks:detach-windows
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:outskirts:mages-peaks:detach-windows [2024/04/09 16:41] – [Using the Intercoms to communicate] Philippe M | en:outskirts:mages-peaks:detach-windows [2024/10/28 08:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Detachable Windows and Intercom ====== | ||
| + | |||
| + | |||
| ===== Goals ===== | ===== Goals ===== | ||
| As demonstrated in the laelith-adventure project, for the Editor, the goal is to enable a (Svelte) component sitting in a page to be // | As demonstrated in the laelith-adventure project, for the Editor, the goal is to enable a (Svelte) component sitting in a page to be // | ||
| Line 95: | Line 98: | ||
| When the view is mounted, it listens to // | When the view is mounted, it listens to // | ||
| + | The " | ||
| ===== Using the Intercoms to communicate ===== | ===== Using the Intercoms to communicate ===== | ||
| === Readiness signals === | === Readiness signals === | ||
| Line 100: | Line 104: | ||
| The // | The // | ||
| - | This is signalled using the '' | + | This is signalled using the '' |
| + | When in the embedded view, the returned Promise will immediately resolved.\\ | ||
| + | When in the detached view, it will resolve when the handshake with the parent window is complete, and, most importantly, | ||
| + | Typically, this is where you will have the code to fetch the data of the component, using // | ||
| + | < | ||
| + | intercom.whenReady().then(() => { | ||
| + | intercom.sendMessage(" | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | === Communication between components === | ||
| + | The // | ||
| + | |||
| + | The key property of this communication system is that a message addressed to a '' | ||
| + | |||
| + | Sending a message to the view identified by **target-view-id** is done using: | ||
| + | < | ||
| + | intercom.sendMessage(" | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | |||
| + | For message reception, attach a Listener to the '' | ||
| + | < | ||
| + | intercom.on(Intercom.RX_MESSAGE, | ||
| + | (msg: IntercomMessage) => { | ||
| + | switch (msg.msgType) { | ||
| + | case ' | ||
| + | [...] | ||
| + | } | ||
| + | }," | ||
| + | ); | ||
| + | | ||
| + | intercom.whenReady().then(() => { | ||
| + | intercom.sendMessage(' | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | The code above illustrates a common pattern: the View registers a message listener on the '' | ||
| + | |||
| + | === The Network Prefix === | ||
| + | All the '' | ||
| + | The special value **prefix-all** broadcasts a message to all Views with the same Prefix.\\ | ||
| + | |||
| + | //Intercom messages// can only be exchanged between Views of the same '' | ||
| + | * This disposition allows to define several independent " | ||
| + | * It allows to scope the Broadcasts to the Views of the same // | ||
| + | * Other unrelated applications communicate using also postMessage between windows and // | ||
| + | |||
| + | ===== Ensuring consistency between definitions ===== | ||
| + | |||
| + | To prevent misspelling bugs and provide a central place for the common definitions of communicating entities, it is suggested to create a specific '' | ||
| + | |||
| + | * All the ViewIDs (same network prefix) in an //Enum//. | ||
| + | * The '' | ||
| + | * The type definition of the Payloads. | ||
| + | |||
| + | Create one such file for each " | ||
| + | |||
| + | < | ||
| + | /** | ||
| + | * Participants to the Adventure Editor group. Used as Source and Target of messages, with the NetworkPrefix. | ||
| + | */ | ||
| + | export enum AdvEditViews { | ||
| + | /** For broadcasting messages, to all except the emitter. */ | ||
| + | All = " | ||
| + | |||
| + | /** The Adventure Editor Store. */ | ||
| + | EditStore = " | ||
| + | |||
| + | /** The Main Editor View */ | ||
| + | MainEditor = " | ||
| + | [...] | ||
| + | } | ||
| + | |||
| + | /** Messages of these msgTypes are requests adressed to a View. */ | ||
| + | export enum AdvEditRequests { | ||
| + | /** | ||
| + | * The message requests the Adventure currently being edited. | ||
| + | * The Owner of the Adventure Edit Store should respond with a CurrentAdventure indication to the requester. | ||
| + | * Target: AdvEditViews.EditStore | ||
| + | * No Payload. | ||
| + | */ | ||
| + | RequestCurrentAdventure = " | ||
| + | [...] | ||
| + | } | ||
| + | |||
| + | /** Messages of these msgTypes are event-like messages that can interest different Views. */ | ||
| + | export enum AdvEditIndications { | ||
| + | |||
| + | /** The message payload contains the Adventure newly selected. */ | ||
| + | CurrentAdventure = " | ||
| + | [...] | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Payload of AdventureAssetCount and UpdateAssetCount | ||
| + | */ | ||
| + | export interface AdventureAssetCountUpdate { | ||
| + | assetId: string, | ||
| + | value: number | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | </ | ||
en/outskirts/mages-peaks/detach-windows.1712680893.txt.gz · Last modified: 2024/10/28 08:00 (external edit)
