]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/root-helpers/video.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / root-helpers / video.ts
CommitLineData
3545e72c 1import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models'
57d65032 2
de615445
C
3function buildVideoOrPlaylistEmbed (options: {
4 embedUrl: string
5 embedTitle: string
cadc1a1b 6 responsive?: boolean
de615445 7}) {
cadc1a1b 8 const { embedUrl, embedTitle, responsive = false } = options
de615445 9
57d65032
C
10 const iframe = document.createElement('iframe')
11
12 iframe.title = embedTitle
cadc1a1b
W
13 iframe.width = responsive ? '100%' : '560'
14 iframe.height = responsive ? '100%' : '315'
57d65032
C
15 iframe.src = embedUrl
16 iframe.frameBorder = '0'
17 iframe.allowFullscreen = true
18 iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups')
19
cadc1a1b
W
20 if (responsive) {
21 const wrapper = document.createElement('div')
22
23 wrapper.style.position = 'relative'
24 wrapper.style['padding-top'] = '56.25%'
25
26 iframe.style.position = 'absolute'
27 iframe.style.inset = '0'
28
29 wrapper.appendChild(iframe)
30
31 return wrapper.outerHTML
32 }
33
57d65032
C
34 return iframe.outerHTML
35}
36
37function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: boolean) {
38 if (video.isLocal && config.tracker.enabled === false) return false
39 if (isWebRTCDisabled()) return false
40
41 return userP2PEnabled
42}
43
3545e72c
C
44function videoRequiresAuth (video: Video) {
45 return new Set([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]).has(video.privacy.id)
46}
47
57d65032
C
48export {
49 buildVideoOrPlaylistEmbed,
3545e72c
C
50 isP2PEnabled,
51 videoRequiresAuth
57d65032
C
52}
53
54// ---------------------------------------------------------------------------
55
56function isWebRTCDisabled () {
57 return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false
58}