]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/root-helpers/video.ts
Update copyright to 2023
[github/Chocobozzz/PeerTube.git] / client / src / root-helpers / video.ts
1 import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models'
2
3 function buildVideoOrPlaylistEmbed (options: {
4 embedUrl: string
5 embedTitle: string
6 }) {
7 const { embedUrl, embedTitle } = options
8
9 const iframe = document.createElement('iframe')
10
11 iframe.title = embedTitle
12 iframe.width = '560'
13 iframe.height = '315'
14 iframe.src = embedUrl
15 iframe.frameBorder = '0'
16 iframe.allowFullscreen = true
17 iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups')
18
19 return iframe.outerHTML
20 }
21
22 function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: boolean) {
23 if (video.isLocal && config.tracker.enabled === false) return false
24 if (isWebRTCDisabled()) return false
25
26 return userP2PEnabled
27 }
28
29 function videoRequiresAuth (video: Video) {
30 return new Set([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]).has(video.privacy.id)
31 }
32
33 export {
34 buildVideoOrPlaylistEmbed,
35 isP2PEnabled,
36 videoRequiresAuth
37 }
38
39 // ---------------------------------------------------------------------------
40
41 function isWebRTCDisabled () {
42 return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false
43 }