Skip to content

Adapter: Platform

IPlatform bundles every primitive the kit would otherwise hardcode against a browser API, so a native-shell consumer (Capacitor, Tauri, Electron) injects native equivalents in one swap instead of patching five call sites.

The interface

FieldInterfacePurpose
wakeLockIWakeLockKeep the display awake during playback. acquire() / release() / isHeld().
networkINetworkMonitorOnline/offline + connection type. isOnline() / type() / downlinkMbps() / subscribe().
visibilityIVisibilityMonitorTab visibility. isVisible() / subscribe().
capabilitiesICapabilitiesProbeHardware decode capability, feeds ABR. canDecode(profile).
fullscreenIFullscreenController (optional)Video only.
pipIPipController (optional)Video only.

Rules & restrictions

  • fullscreen and pip are video-only fields. The audio player never touches them; the video player throws a descriptive BrowserPolicyError if either is invoked when the field wasn’t supplied.
  • IWakeLock.acquire() throws BrowserPolicyError('core:policy/wakeLockUnsupported') when the Screen Wake Lock API is unavailable, check isSupported() first if you need to gate the feature instead of catching.
  • downlinkMbps() and rttMs() return undefined on browsers without the Network Information API (Firefox, Safari as of this writing), not a fabricated number.

How to extend it

Partial overrides compose cleanly, spread the default and replace only the controller you need:

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

const player = nmplayer('player');

player.setup({
platform: { ...browserPlatform, wakeLock: myCapacitorWakeLock },
});

Full native-shell adapters (@nomercy/platform-capacitor, @nomercy/platform-tauri, @nomercy/platform-electron) live outside the kit and replace the whole IPlatform object.

Next steps