What is Jetstream player API?
Short description
Jetstream player API is a library that allows you to control an embedded video player from outside an iframe and subscribe to that player's events. Videos are embedded in a website through an iframe tag. As a user, you can play and pause the video by clicking a button within the iframe itself. But how about playing or pausing the video programmatically and receiving events directly from the player?
Since our embedded video player is a separate service that uses video.js under the hood, we cannot do this directly. Modern browsers don't allow this due to CORS policy and MessageEvent API restrictions. Therefore, this library uses postMessage() to send commands directly to the player, where they are processed. On its side, the embedded player sends events that can be captured where it is used.
Thus, we can interact with the player and subscribe to events for the required video or playlist.
Cross-origin and redirects — handled for you
The library identifies the embedded player by the iframe's window, not by an origin guessed from its URL. So if the embed follows a redirect to a different origin (for example jstre.am → embed.jetstream.studio, a regional host, or http → https), commands and events keep flowing — the real origin is learned from the player's own messages. You can also set the origin option to point the iframe at the destination host directly and skip the redirect.