]>
Commit | Line | Data |
---|---|---|
1 | import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models' | |
2 | ||
3 | function buildVideoOrPlaylistEmbed (options: { | |
4 | embedUrl: string | |
5 | embedTitle: string | |
6 | responsive?: boolean | |
7 | }) { | |
8 | const { embedUrl, embedTitle, responsive = false } = options | |
9 | ||
10 | const iframe = document.createElement('iframe') | |
11 | ||
12 | iframe.title = embedTitle | |
13 | iframe.width = responsive ? '100%' : '560' | |
14 | iframe.height = responsive ? '100%' : '315' | |
15 | iframe.src = embedUrl | |
16 | iframe.frameBorder = '0' | |
17 | iframe.allowFullscreen = true | |
18 | iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups') | |
19 | ||
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 | ||
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 | ||
44 | function videoRequiresAuth (video: Video) { | |
45 | return new Set([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]).has(video.privacy.id) | |
46 | } | |
47 | ||
48 | export { | |
49 | buildVideoOrPlaylistEmbed, | |
50 | isP2PEnabled, | |
51 | videoRequiresAuth | |
52 | } | |
53 | ||
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | function isWebRTCDisabled () { | |
57 | return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false | |
58 | } |