From 57d6503286b114fee61b5e4725825e2490dcac29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Mar 2022 14:28:20 +0100 Subject: Reorganize player files --- client/src/root-helpers/index.ts | 3 ++- client/src/root-helpers/video.ts | 33 +++++++++++++++++++++++++++++++++ client/src/root-helpers/web-browser.ts | 24 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 client/src/root-helpers/video.ts create mode 100644 client/src/root-helpers/web-browser.ts (limited to 'client/src/root-helpers') diff --git a/client/src/root-helpers/index.ts b/client/src/root-helpers/index.ts index aa3b442dd..3b95b4b99 100644 --- a/client/src/root-helpers/index.ts +++ b/client/src/root-helpers/index.ts @@ -3,5 +3,6 @@ export * from './bytes' export * from './images' export * from './local-storage-utils' export * from './peertube-web-storage' -export * from './utils' export * from './plugins-manager' +export * from './utils' +export * from './video' diff --git a/client/src/root-helpers/video.ts b/client/src/root-helpers/video.ts new file mode 100644 index 000000000..4290992aa --- /dev/null +++ b/client/src/root-helpers/video.ts @@ -0,0 +1,33 @@ +import { HTMLServerConfig, Video } from '@shared/models' + +function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) { + const iframe = document.createElement('iframe') + + iframe.title = embedTitle + iframe.width = '560' + iframe.height = '315' + iframe.src = embedUrl + iframe.frameBorder = '0' + iframe.allowFullscreen = true + iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups') + + return iframe.outerHTML +} + +function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: boolean) { + if (video.isLocal && config.tracker.enabled === false) return false + if (isWebRTCDisabled()) return false + + return userP2PEnabled +} + +export { + buildVideoOrPlaylistEmbed, + isP2PEnabled +} + +// --------------------------------------------------------------------------- + +function isWebRTCDisabled () { + return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false +} diff --git a/client/src/root-helpers/web-browser.ts b/client/src/root-helpers/web-browser.ts new file mode 100644 index 000000000..9dade20e8 --- /dev/null +++ b/client/src/root-helpers/web-browser.ts @@ -0,0 +1,24 @@ +function isIOS () { + if (/iPad|iPhone|iPod/.test(navigator.platform)) { + return true + } + + // Detect iPad Desktop mode + return !!(navigator.maxTouchPoints && + navigator.maxTouchPoints > 2 && + navigator.platform.includes('MacIntel')) +} + +function isSafari () { + return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) +} + +function isMobile () { + return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) +} + +export { + isIOS, + isSafari, + isMobile +} -- cgit v1.2.3