]>
Commit | Line | Data |
---|---|---|
3545e72c | 1 | import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models' |
57d65032 | 2 | |
de615445 C |
3 | function 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' | |
54909304 | 24 | wrapper.style.paddingTop = '56.25%' |
cadc1a1b W |
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 | ||
37 | function 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 |
44 | function videoRequiresAuth (video: Video) { |
45 | return new Set([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]).has(video.privacy.id) | |
46 | } | |
47 | ||
57d65032 C |
48 | export { |
49 | buildVideoOrPlaylistEmbed, | |
3545e72c C |
50 | isP2PEnabled, |
51 | videoRequiresAuth | |
57d65032 C |
52 | } |
53 | ||
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | function isWebRTCDisabled () { | |
57 | return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false | |
58 | } |