Skip to content

Plugin: Cast Sender

CastSenderPlugin (id 'cast-sender') bridges player transport state to and from an active Chromecast session via the Cast Web Sender SDK. It’s written as a shared base class: nomercy-video-player and nomercy-music-player each subclass it, overriding the two methods that differ per medium.

Options

OptionTypeDefaultPurpose
chromecastAppIdstringYour registered Cast receiver app id.
enableAirPlaybooleanAlso surface an AirPlay control path.
customReceiverNamespacestringCustom message namespace for a non-default receiver.
resumeLocalOnDisconnectbooleantrueResume local playback when the Cast session ends.
defaultContentTypestringsubclass’s defaultContentType()MIME type hint sent to the receiver.
livebooleanfalseMarks the content as a live stream for the receiver UI.

Events

cast:connected ({ deviceName }), cast:disconnected, cast:error ({ error }), cast:remote-state ({ time, state }), cast:media-changed ({ contentId }), unsupported ({ reason }).

Rules & restrictions

  • Chrome/Chromium Web Sender SDK only. In Firefox, Safari, or a non-Chromium browser, connect() emits unsupported and throws a BrowserPolicyError (core:policy/castUnavailable), everything else stays a harmless no-op rather than crashing.
  • Requires the global cast.framework / chrome.cast.media SDK to already be loaded on the page, the plugin doesn’t load the script for you.
  • Volume arrives on the kit’s own 0-100 volume() scale and is divided to 0-1 at the boundary, which is the 0-1 float range the receiver’s SDK expects.

How to extend it

Subclass it and override the two per-medium methods. This is exactly what nomercy-video-player and nomercy-music-player do, neither reimplements the session/connection handling.

TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player'; // nomercy-music-player's factory works identically
import { CastSenderPlugin } from '@nomercy-entertainment/nomercy-player-core';

const player = nmplayer('player');

class MyCastSenderPlugin extends CastSenderPlugin {
protected override defaultContentType(): string {
return 'application/x-mpegURL';
}
// override buildMetadata(item, ctors) for your own item shape
}

player.addPlugin(MyCastSenderPlugin, { chromecastAppId: 'ABCD1234' });
await player.ready();

await player.getPlugin(MyCastSenderPlugin)?.connect();

Next steps

  • Plugin: Embed: the cross-origin postMessage bridge for a player running in an iframe.