Plugins ******* Built-in plugins for PRESTOplay for Web Apps, plus how to write a custom one. Plugins implement "PlayerPlugin" (https://players.castlabs.com/web/latest/docs/api/clpp.PlayerPlugin.md); a "PlayerPluginFactory" (https://players.castlabs.com/web/latest/docs/api/clpp.PlayerPluginFactory.md) registers them with "Player" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md). Code samples: * Custom plugin (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/plugins/stats_overlay.js): a stats overlay plugin that implements every callback and shows when each one runs. * SIMID interactive ads (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/advertising/simid.js): interactive overlay ads that shrink the video into a corner while a banner fills the rest of the player. * 360° video (https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/vr/vr.js): renders a 360° stream on a WebGL sphere, with drag and button controls. Built-in plugins ================ Each plugin ships as a separate module and must be imported before creating the player to register it. +----------------------------------------------------------------------------------------+----------------------------------------------------+ | Plugin | Use | |========================================================================================|====================================================| | "Adobe Analytics" | Reports playback metrics to Adobe Analytics via | | (https://players.castlabs.com/web/latest/docs/api/clpp.adobe.AdobeAnalyticsPlugin.md) | the "s.Media" API. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "AirPlay" | Casts to AirPlay receivers. See AirPlay. | | (https://players.castlabs.com/web/latest/docs/api/clpp.airplay.AirPlayPlugin.md) | | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Broadpeak" | Broadpeak server-side ad insertion and analytics. | | (https://players.castlabs.com/web/latest/docs/api/clpp.broadpeak.BroadpeakPlugin.md) | See Broadpeak. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Conviva" | Reports playback metrics to Conviva Experience | | (https://players.castlabs.com/web/latest/docs/api/clpp.conviva.ConvivaPlugin.md) | Insights. See Conviva. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "FreeWheel" | FreeWheel ad insertion. See FreeWheel. | | (https://players.castlabs.com/web/latest/docs/api/clpp.freewheel.FreeWheelPlugin.md) | | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "HLS SMPTE-TT" | Processes SMPTE-TT image cues in HLS streams. See | | (https://players.castlabs.com/web/latest/docs/api/clpp.HlsSmpteConfiguration.md) | SMPTE-TT over HLS. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "IMA" | Google Interactive Media Ads (IMA) SDK | | (https://players.castlabs.com/web/latest/docs/api/clpp.ima.ImaPlugin.md) | integration. See Google IMA. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Mux Data" | Reports playback metrics to Mux Data. See Mux | | (https://players.castlabs.com/web/latest/docs/api/clpp.muxdata.MuxDataPlugin.md) | Data. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | MediaTailor | AWS Elemental MediaTailor server-side ad | | | insertion. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "NPAW / Youbora" | Reports playback metrics to NPAW (Youbora). See | | (https://players.castlabs.com/web/latest/docs/api/clpp.npaw.YouboraPlugin.md) | NPAW. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Playlist" | Sequential playback of multiple media items. See | | (https://players.castlabs.com/web/latest/docs/api/clpp.Playlist.md) | Playlist. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | SIMID | Secure Interactive Media Interface Definition | | | (SIMID) support for interactive ad creatives. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Thumbnails" | Loads and parses thumbnail previews. See | | (https://players.castlabs.com/web/latest/docs/api/clpp.thumbnails.ThumbnailsPlugin.md) | Thumbnails. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Vimond" | Vimond integration. Deprecated — will be removed | | (https://players.castlabs.com/web/latest/docs/api/clpp.vimond.VimondPlugin.md) | in a future major version. | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "VR" | Adds 360-degree video playback support. | | (https://players.castlabs.com/web/latest/docs/api/clpp.vr.VrPlugin.md) | | +----------------------------------------------------------------------------------------+----------------------------------------------------+ | "Yospace" | Yospace server-side ad insertion. See Yospace. | | (https://players.castlabs.com/web/latest/docs/api/clpp.yospace.YospacePlugin.md) | | +----------------------------------------------------------------------------------------+----------------------------------------------------+ Writing a custom plugin ======================= PRESTOplay plugins are class-based components that implement the "PlayerPlugin" (https://players.castlabs.com/web/latest/docs/api/clpp.PlayerPlugin.md) interface. The interface defines a set of callbacks and hooks that the player calls at different points during its lifecycle. The player calls these callbacks on each plugin instance: +----------------------------------------------------+-------------------------------------------------------------------------------+ | Callback | Called | |====================================================|===============================================================================| | "onPlayerCreated(player)" | When the "Player" | | | (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md) | | | instance is created. Set up anything that lives as | | | long as the player, such as UI. | +----------------------------------------------------+-------------------------------------------------------------------------------+ | "onContentWillLoad(player, source)" | Before content loads. Register event listeners | | | here. Return a URL, or a promise that resolves | | | with one, to replace the stream URL. If a promise | | | is returned, loading waits for it. | +----------------------------------------------------+-------------------------------------------------------------------------------+ | "onContentLoaded(player)" | After content loads. Content information such as | | | "Player.isLive" | | | (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#isLive) | | | and "Player.getDuration" | | | (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#getDuration) | | | is available from this point. | +----------------------------------------------------+-------------------------------------------------------------------------------+ | "onPlayerWillRelease(player)" | Before the current content is released, including | | | before each new "Player.open" | | | (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#open) | | | call. Remove the listeners registered in | | | "onContentWillLoad". | +----------------------------------------------------+-------------------------------------------------------------------------------+ | "onPlayerWillDestroy(player)" | Before the player is destroyed. Clean up | | | everything else. | +----------------------------------------------------+-------------------------------------------------------------------------------+ | "id()" | Returns the plugin ID. The plugin instance is then | | | available through "Player.getPlugin" | | | (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#getPlugin). | +----------------------------------------------------+-------------------------------------------------------------------------------+ Registering a plugin ==================== Register the plugin with the SDK before using it. The SDK exposes a plugin factory "PlayerPluginFactory" (https://players.castlabs.com/web/latest/docs/api/clpp.PlayerPluginFactory.md) interface that you implement and provide. A generic plugin factory that creates instances of a "MyPlugin" class looks like this: /** * @implements {clpp.PlayerPluginFactory} */ class MyPluginFactory { /** * @override */ create (playerConfig) { return new MyPlugin(); } }; Register the factory with the player using "Player.registerPlugin" (https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#registerPlugin): // *Before* the player instance is created clpp.Player.registerPlugin(new MyPluginFactory()); // ... // Now the plugin will be used with each new instance of the player. const player = new clpp.Player(...);