JavaScript SDK
Download a runnable Node exampleAuthorize on the customer server
Implement requireViewer and requireFilmAccess with your own membership system. Derive the viewer, film and origin on the server. Cache the movie page independently of its launch response. For public access your server must explicitly allow a guest.
// Inside your authenticated movie route on the customer server
const viewer = await requireViewer(request);
await requireFilmAccess(viewer, film);
const result = await fetch(process.env.PARADYM_API_ORIGIN + '/partner/v1/playback-sessions', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + process.env.PARADYM_PLAYER_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
asset_id: film.externalId,
viewer_id: viewer.opaqueId,
origin: process.env.PUBLIC_SITE_ORIGIN
})
});
if (!result.ok) throw new Error('Playback authorization failed');
return Response.json(await result.json(), {headers:{'Cache-Control':'private, no-store'}});Mount the player
Load the versioned SDK once, then mount it inside the movie page. Your launch callback returns a fresh grant. Paradym delivers player updates on the next player load.
<div id="film"></div>
<script src="https://player.paradym.tv/sdk/v1/player.js"></script>
<script>
const player = ParadymPlayer.mount(document.querySelector('#film'), {
locale: 'en',
launch: async () => {
const response = await fetch('/movies/demo-film/launch', {
method: 'POST', credentials: 'same-origin', cache: 'no-store'
});
if (!response.ok) throw new Error('Cannot open this film');
return response.json();
}
});
// Call player.destroy() when removing the player.
</script>Player commands and browser events
Await player.ready before calling play(), pause() or seek(seconds). on(event, handler) returns an unsubscribe function. The supported events are ready, play, pause, ended, error and progress. When your app supports episodes, pass onNavigate(assetId) and authorize the selected film on your own page.
In SDK 1.1, the progress event and getProgress() deliver mountId, positionSeconds, durationSeconds and reason for media with a known duration. Seconds can be fractional. Updates come at most once per second during playback and immediately after a settled seek, pause or end. Use the latest snapshot for your own save interval and page exit. Read getProgress() before destroy(). It returns null before the first sample and after destruction. Your server applies your normal enrollment and completion rules.
const stop = player.on('progress', sample => updateLessonTimeline(sample));
await player.ready;
player.seek(savedPositionSeconds);
// Before removing the active lesson player:
const latest = player.getProgress();
if (latest) saveLessonPosition(latest);
stop();
player.destroy();