-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from THEOplayer/release/v8.9.1
Release/v8.9.1
- Loading branch information
Showing
10 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export function browserCanPlayHLSAndHasNoMSE() { | ||
const videoElement = document.createElement('video'); | ||
const canPlayHls = videoElement && videoElement.canPlayType && videoElement.canPlayType('application/vnd.apple.mpegURL') !== ''; | ||
// @ts-ignore | ||
const canPlayMse = Boolean(window.MediaSource || window.WebKitMediaSource || window.ManagedMediaSource); | ||
return canPlayHls && !canPlayMse; | ||
} | ||
|
||
export async function registerServiceWorker(libraryLocation?: string): Promise<void> { | ||
if ('serviceWorker' in navigator) { | ||
try { | ||
const serviceWorkerName = 'theoplayer.sw.js'; | ||
const serviceWorkerPath = libraryLocation | ||
? (libraryLocation.endsWith('/') ? libraryLocation : `${libraryLocation}/`) + serviceWorkerName | ||
: serviceWorkerName; | ||
const serviceWorkerScope = libraryLocation ? (libraryLocation.endsWith('/') ? libraryLocation : `${libraryLocation}/`) : '/'; | ||
|
||
// unregister beforehand to solve an issue when doing a hard reload of the page causing the service worker to not intercept the manifests. | ||
await maybeUnregisterServiceWorker(serviceWorkerPath); | ||
await navigator.serviceWorker.register(serviceWorkerPath, { | ||
scope: serviceWorkerScope, | ||
}); | ||
//console.log('Successfully registered server worker'); | ||
} catch (error) { | ||
console.error(`Service worker registration failed: ${error}`); | ||
} | ||
} | ||
} | ||
|
||
export async function maybeUnregisterServiceWorker(serviceWorkerPath?: string): Promise<void> { | ||
if ('serviceWorker' in navigator) { | ||
try { | ||
const registration = await navigator.serviceWorker.getRegistration(serviceWorkerPath); | ||
await registration?.unregister(); | ||
} catch (error) { | ||
console.error(`Service worker unregistration failed: ${error}`); | ||
} | ||
} | ||
} |