Plugin: Embed
EmbedPlugin (id 'embed') bridges a player running inside an <iframe> to the host page via postMessage: it forwards player events out (ready, play, pause, and more) and accepts a small transport command set in (play, pause, seek, volume, and more).
Options
| Option | Type | Default | Purpose |
|---|---|---|---|
allowedOrigins | string | string[] | none | Inbound origins accepted. Empty means no inbound commands are accepted at all, outbound events still forward. |
forwardEvents | ReadonlyArray<EmbedEventMessage['name']> | ['ready','play','pause','ended','time','volume','mute'] | Which player events forward to the host. |
applyIframeTweaks | boolean | result of an in-iframe check | Apply embed-specific layout/behavior tweaks automatically. |
Rules & restrictions
- Security default is closed, not open: with no
allowedOriginsconfigured, zero inbound origins are trusted. You opt in explicitly. - Outbound
postMessagetargeting: with exactly one origin inallowedOrigins, outbound messages are pinned to it. With multiple origins (or'*'), outbound falls back to'*', the plugin’s own docs recommend pinning to one origin in production rather than relying on the multi-origin fallback. - The host
<iframe>needsallow="autoplay; fullscreen; picture-in-picture; encrypted-media; accelerometer; gyroscope; web-share; clipboard-write",allowfullscreen, andloading="lazy"for full functionality. Theautoplaypermission specifically is load-bearing, without it the browser’s MediaSession integration never activates inside the frame. - Media Session already works correctly inside an iframe on its own, this plugin doesn’t need to bridge it.
How to extend it
TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player'; // nomercy-music-player's factory works identically
import { EmbedPlugin } from '@nomercy-entertainment/nomercy-player-core';
const player = nmplayer('player');
player.addPlugin(EmbedPlugin, {
allowedOrigins: 'https://host.example.com',
forwardEvents: ['ready', 'play', 'pause', 'time'],
});
await player.ready();
On the host page, listen for message events with event.data.type === 'nm:event' and post commands shaped like EmbedCommand ({ type: 'nm:command', action: 'play' }, { type: 'nm:command', action: 'seek', time: 30 }) to the iframe’s contentWindow.
Next steps
- Plugin: Key Handler: keyboard shortcuts, the other common “host page integration” surface.