Passing authentication headers to video HTTP requests

WebViewer Video utilizes service workers to allow for custom headers to be passed onto HTTP requests that retrieve the video. This gives you the ability to authenticate videos on the server side and access them securely using WebViewer Video. See below example on how to utilize the service worker and pass custom headers.

JavaScript (v8.0+)

1import WebViewer from '@pdftron/webviewer';
2import { initializeVideoViewer, renderControlsToDOM } from '@pdftron/webviewer-video';
3
4WebViewer({
5 path: '/webviewer/lib',
6 },
7 viewer.current,
8).then(async instance => {
9 // Extends WebViewer to allow loading HTML5 videos (.mp4, ogg, webm).
10 const {
11 getVideo,
12 loadVideo,
13 } = await initializeVideoViewer(
14 instance,
15 {
16 license: '---- Insert commercial license key here after purchase ----',
17 `---- Other settings ----`,
18 }
19 );
20 // Load a video at a specific url. Can be a local or public link
21 // If local it needs to be relative to lib/ui/index.html.
22 // Or at the root. (eg '/video.mp4')
23 const videoUrl = 'https://pdftron.s3.amazonaws.com/downloads/pl/video/video.mp4';
24 loadVideo(videoUrl, {
25 headers: {
26 Authorization: 'Bearer testToken',
27 TestHeader: 'Test',
28 },
29 });
30});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales