Skip to content

Commit

Permalink
Describe how to register the THEOlive service worker (#172)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher <[email protected]>
  • Loading branch information
cTopher and Christopher authored Dec 5, 2024
1 parent 57323aa commit e06ee10
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion theoplayer/how-to-guides/web/theolive/00-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,34 @@ import Intro from '../../shared/theolive/_getting-started-intro.mdx';

1. Follow [our Getting Started guide](../../../getting-started/01-sdks/01-web/00-getting-started.mdx)
to set up THEOplayer in your web app or website.
2. Add a THEOlive source to your player's source.
2. Register the service worker if necessary.
3. Add a THEOlive source to your player's source.

### Register the service worker

On Apple devices running an iOS version lower than 17.1, a service worker needs to be registered to support low
latency play-out of THEOlive streams.

```javascript
function needsServiceWorkerForTHEOlive() {
const canPlayMSE = !!(window.MediaSource || window.WebKitMediaSource || window.ManagedMediaSource);
const videoElement = document.createElement('video');
const canPlayHLS = videoElement.canPlayType && videoElement.canPlayType('application/vnd.apple.mpegURL') !== '';
return canPlayHLS && !canPlayMSE;
}
if (needsServiceWorkerForTHEOlive()) {
await navigator.serviceWorker.register('theoplayer.sw.js');
}
```

The service worker `theoplayer.sw.js` is part of the THEOplayer SDK and needs to be on the same domain and path as the
page initiating the player.

### Add a THEOlive source

After setting up your THEOplayer on your web page, set its source to a `SourceDescription` containing a `THEOliveSource`.
Take into account that the source must be set after awaiting the registration of the service worker for streams to work
on iOS versions lower than 17.1.
You'll need a THEOlive channel ID:

```javascript
Expand Down

0 comments on commit e06ee10

Please sign in to comment.