@dolby-optiview/ads-sdk-core
Player-agnostic core of the OptiView Ads SDK for the web: break manifest
polling and verification, break scheduling, ad playback and event reporting.
It never imports player code; content and ad players are driven through the
PlayerAdapter interface.
Most applications do not install this package directly:
@dolby-optiview/ads-sdk depends on it and adds a default ad player. Use the
core on its own when you supply both the content adapter and the ad player
adapter yourself, for example with a custom PlayerAdapter.
Installation
npm install @dolby-optiview/ads-sdk-core @dolby-optiview/ads-sdk-adapter-hlsjs hls.js
Replace the adapter with @dolby-optiview/ads-sdk-adapter-shaka or
@dolby-optiview/ads-sdk-adapter-theoplayer for those players.
Quick start
With the bare core, createAdAdapter is required:
import Hls from 'hls.js';
import { OptiViewAds } from '@dolby-optiview/ads-sdk-core';
import { HlsJsAdapter } from '@dolby-optiview/ads-sdk-adapter-hlsjs';
const video = document.getElementById('video') as HTMLVideoElement;
const hls = new Hls();
hls.attachMedia(video);
const sdk = new OptiViewAds({
player: new HlsJsAdapter(hls, video),
container: document.getElementById('container')!,
createAdAdapter: (adContainer) => {
const adVideo = document.createElement('video');
adContainer.appendChild(adVideo);
const adHls = new Hls();
adHls.attachMedia(adVideo);
return new HlsJsAdapter(adHls, adVideo);
},
});
await sdk.startSession({
manifestUrl: 'https://manifest.example.com/v1/your-org/channels/your-channel',
});
hls.loadSource('https://example.com/content.m3u8');
video.play();
Custom adapters
Implement PlayerAdapter (exported as a type from this package) to connect a
player that has no ready-made adapter. The adapter reports playback state,
program date time and in-stream metadata to the core and receives load, play,
pause and seek commands.
Documentation
- OptiView Ads SDK documentation
- Entry package:
@dolby-optiview/ads-sdk