Skip to content

inter-frame-messenger

Audience: Agent

Purpose

Reusable InterFrameMessenger class: wraps window.postMessage with allowlisted origins, message type enums, and helpers for EliteEvent / Status payloads validated via @howfe/elite-dangerous-event-types.

Tech stack

  • TypeScript, built with tsupdist/ (package.json main / module / types).
  • Published as @howfe/inter-frame-messenger.

Layout

Path Role
src/index.ts MessageTypeEnum, InterFrameMessenger class
tsup.config.ts Build output

Integration points

  • Remote journal reader — constructs InterFrameMessenger with target = window.opener, sends game events, listens for remote control message types.
  • Surface map — constructs with target = popup from window.open, listens for elite-event / elite-status.
  • See IPC.md for envelope and parent/child setup.

Extension points

  • New message types: add to MessageTypeEnum, then update both send and listen allowlists in every consumer.
  • Stricter origin policy: replace '*' in EDJR buttons with explicit parent origins when embedders are known.
  • After changes: npm run build, publish, bump versions in Quasar apps.

Pitfalls / checks

  • Constructor ordering: sendMessageTypes / listenMessageTypes must include every type you send / on or the library throws or ignores.
  • send loops over allowedListenerOrigins — empty list means postMessage never fires.
  • Duplicate listeners: each on() registers a new window listener — avoid double-registering the same handler pattern.