aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html5
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts4
-rw-r--r--client/src/app/core/auth/auth-user.model.ts4
-rw-r--r--client/src/app/shared/users/user.model.ts3
-rw-r--r--client/src/assets/player/peertube-player-local-storage.ts8
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts48
6 files changed, 56 insertions, 16 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
index 96629940f..8be8a66cc 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
+++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
@@ -16,6 +16,11 @@
16 </div> 16 </div>
17 17
18 <my-peertube-checkbox 18 <my-peertube-checkbox
19 inputName="webTorrentEnabled" formControlName="webTorrentEnabled"
20 i18n-labelText labelText="Use WebTorrent to exchange parts of the video with others"
21 ></my-peertube-checkbox>
22
23 <my-peertube-checkbox
19 inputName="autoPlayVideo" formControlName="autoPlayVideo" 24 inputName="autoPlayVideo" formControlName="autoPlayVideo"
20 i18n-labelText labelText="Automatically plays video" 25 i18n-labelText labelText="Automatically plays video"
21 ></my-peertube-checkbox> 26 ></my-peertube-checkbox>
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
index 7089b2057..6c9a7ce75 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
@@ -29,12 +29,14 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI
29 ngOnInit () { 29 ngOnInit () {
30 this.buildForm({ 30 this.buildForm({
31 nsfwPolicy: null, 31 nsfwPolicy: null,
32 webTorrentEnabled: null,
32 autoPlayVideo: null 33 autoPlayVideo: null
33 }) 34 })
34 35
35 this.userInformationLoaded.subscribe(() => { 36 this.userInformationLoaded.subscribe(() => {
36 this.form.patchValue({ 37 this.form.patchValue({
37 nsfwPolicy: this.user.nsfwPolicy, 38 nsfwPolicy: this.user.nsfwPolicy,
39 webTorrentEnabled: this.user.webTorrentEnabled,
38 autoPlayVideo: this.user.autoPlayVideo === true 40 autoPlayVideo: this.user.autoPlayVideo === true
39 }) 41 })
40 }) 42 })
@@ -42,9 +44,11 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI
42 44
43 updateDetails () { 45 updateDetails () {
44 const nsfwPolicy = this.form.value['nsfwPolicy'] 46 const nsfwPolicy = this.form.value['nsfwPolicy']
47 const webTorrentEnabled = this.form.value['webTorrentEnabled']
45 const autoPlayVideo = this.form.value['autoPlayVideo'] 48 const autoPlayVideo = this.form.value['autoPlayVideo']
46 const details: UserUpdateMe = { 49 const details: UserUpdateMe = {
47 nsfwPolicy, 50 nsfwPolicy,
51 webTorrentEnabled,
48 autoPlayVideo 52 autoPlayVideo
49 } 53 }
50 54
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 74ed1c580..acd13d9c5 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -72,6 +72,7 @@ export class AuthUser extends User {
72 EMAIL: 'email', 72 EMAIL: 'email',
73 USERNAME: 'username', 73 USERNAME: 'username',
74 NSFW_POLICY: 'nsfw_policy', 74 NSFW_POLICY: 'nsfw_policy',
75 WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
75 AUTO_PLAY_VIDEO: 'auto_play_video' 76 AUTO_PLAY_VIDEO: 'auto_play_video'
76 } 77 }
77 78
@@ -87,6 +88,7 @@ export class AuthUser extends User {
87 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL), 88 email: peertubeLocalStorage.getItem(this.KEYS.EMAIL),
88 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole, 89 role: parseInt(peertubeLocalStorage.getItem(this.KEYS.ROLE), 10) as UserRole,
89 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType, 90 nsfwPolicy: peertubeLocalStorage.getItem(this.KEYS.NSFW_POLICY) as NSFWPolicyType,
91 webTorrentEnabled: peertubeLocalStorage.getItem(this.KEYS.WEBTORRENT_ENABLED) === 'true',
90 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true' 92 autoPlayVideo: peertubeLocalStorage.getItem(this.KEYS.AUTO_PLAY_VIDEO) === 'true'
91 }, 93 },
92 Tokens.load() 94 Tokens.load()
@@ -101,6 +103,7 @@ export class AuthUser extends User {
101 peertubeLocalStorage.removeItem(this.KEYS.ID) 103 peertubeLocalStorage.removeItem(this.KEYS.ID)
102 peertubeLocalStorage.removeItem(this.KEYS.ROLE) 104 peertubeLocalStorage.removeItem(this.KEYS.ROLE)
103 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY) 105 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY)
106 peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_ENABLED)
104 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO) 107 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO)
105 peertubeLocalStorage.removeItem(this.KEYS.EMAIL) 108 peertubeLocalStorage.removeItem(this.KEYS.EMAIL)
106 Tokens.flush() 109 Tokens.flush()
@@ -138,6 +141,7 @@ export class AuthUser extends User {
138 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email) 141 peertubeLocalStorage.setItem(AuthUser.KEYS.EMAIL, this.email)
139 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString()) 142 peertubeLocalStorage.setItem(AuthUser.KEYS.ROLE, this.role.toString())
140 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString()) 143 peertubeLocalStorage.setItem(AuthUser.KEYS.NSFW_POLICY, this.nsfwPolicy.toString())
144 peertubeLocalStorage.setItem(AuthUser.KEYS.WEBTORRENT_ENABLED, JSON.stringify(this.webTorrentEnabled))
141 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) 145 peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo))
142 this.tokens.save() 146 this.tokens.save()
143 } 147 }
diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts
index 877f1bf3a..7c840ffa7 100644
--- a/client/src/app/shared/users/user.model.ts
+++ b/client/src/app/shared/users/user.model.ts
@@ -18,6 +18,7 @@ export type UserConstructorHash = {
18 videoQuota?: number, 18 videoQuota?: number,
19 videoQuotaDaily?: number, 19 videoQuotaDaily?: number,
20 nsfwPolicy?: NSFWPolicyType, 20 nsfwPolicy?: NSFWPolicyType,
21 webTorrentEnabled?: boolean,
21 autoPlayVideo?: boolean, 22 autoPlayVideo?: boolean,
22 createdAt?: Date, 23 createdAt?: Date,
23 account?: AccountServerModel, 24 account?: AccountServerModel,
@@ -32,6 +33,7 @@ export class User implements UserServerModel {
32 email: string 33 email: string
33 role: UserRole 34 role: UserRole
34 nsfwPolicy: NSFWPolicyType 35 nsfwPolicy: NSFWPolicyType
36 webTorrentEnabled: boolean
35 autoPlayVideo: boolean 37 autoPlayVideo: boolean
36 videoQuota: number 38 videoQuota: number
37 videoQuotaDaily: number 39 videoQuotaDaily: number
@@ -52,6 +54,7 @@ export class User implements UserServerModel {
52 this.videoQuota = hash.videoQuota 54 this.videoQuota = hash.videoQuota
53 this.videoQuotaDaily = hash.videoQuotaDaily 55 this.videoQuotaDaily = hash.videoQuotaDaily
54 this.nsfwPolicy = hash.nsfwPolicy 56 this.nsfwPolicy = hash.nsfwPolicy
57 this.webTorrentEnabled = hash.webTorrentEnabled
55 this.autoPlayVideo = hash.autoPlayVideo 58 this.autoPlayVideo = hash.autoPlayVideo
56 this.createdAt = hash.createdAt 59 this.createdAt = hash.createdAt
57 this.blocked = hash.blocked 60 this.blocked = hash.blocked
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts
index dac54c5a4..3ac5fe58a 100644
--- a/client/src/assets/player/peertube-player-local-storage.ts
+++ b/client/src/assets/player/peertube-player-local-storage.ts
@@ -10,6 +10,13 @@ function getStoredVolume () {
10 return undefined 10 return undefined
11} 11}
12 12
13function getStoredWebTorrentEnabled (): boolean {
14 const value = getLocalStorage('webtorrent_enabled')
15 if (value !== null && value !== undefined) return value === 'true'
16
17 return false
18}
19
13function getStoredMute () { 20function getStoredMute () {
14 const value = getLocalStorage('mute') 21 const value = getLocalStorage('mute')
15 if (value !== null && value !== undefined) return value === 'true' 22 if (value !== null && value !== undefined) return value === 'true'
@@ -56,6 +63,7 @@ function getAverageBandwidthInStore () {
56 63
57export { 64export {
58 getStoredVolume, 65 getStoredVolume,
66 getStoredWebTorrentEnabled,
59 getStoredMute, 67 getStoredMute,
60 getStoredTheater, 68 getStoredTheater,
61 saveVolumeInStore, 69 saveVolumeInStore,
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 2330f476f..5cebab6d9 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -11,11 +11,18 @@ import {
11 getAverageBandwidthInStore, 11 getAverageBandwidthInStore,
12 getStoredMute, 12 getStoredMute,
13 getStoredVolume, 13 getStoredVolume,
14 getStoredWebTorrentEnabled,
14 saveAverageBandwidth, 15 saveAverageBandwidth,
15 saveMuteInStore, 16 saveMuteInStore,
16 saveVolumeInStore 17 saveVolumeInStore
17} from './peertube-player-local-storage' 18} from './peertube-player-local-storage'
18 19
20type PlayOptions = {
21 forcePlay?: boolean,
22 seek?: number,
23 delay?: number
24}
25
19const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') 26const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
20class PeerTubePlugin extends Plugin { 27class PeerTubePlugin extends Plugin {
21 private readonly playerElement: HTMLVideoElement 28 private readonly playerElement: HTMLVideoElement
@@ -64,6 +71,7 @@ class PeerTubePlugin extends Plugin {
64 private autoResolution = true 71 private autoResolution = true
65 private forbidAutoResolution = false 72 private forbidAutoResolution = false
66 private isAutoResolutionObservation = false 73 private isAutoResolutionObservation = false
74 private playerRefusedP2P = false
67 75
68 private videoViewInterval 76 private videoViewInterval
69 private torrentInfoInterval 77 private torrentInfoInterval
@@ -80,6 +88,7 @@ class PeerTubePlugin extends Plugin {
80 88
81 // Disable auto play on iOS 89 // Disable auto play on iOS
82 this.autoplay = options.autoplay && this.isIOS() === false 90 this.autoplay = options.autoplay && this.isIOS() === false
91 this.playerRefusedP2P = !getStoredWebTorrentEnabled()
83 92
84 this.startTime = timeToInt(options.startTime) 93 this.startTime = timeToInt(options.startTime)
85 this.videoFiles = options.videoFiles 94 this.videoFiles = options.videoFiles
@@ -178,6 +187,15 @@ class PeerTubePlugin extends Plugin {
178 const previousVideoFile = this.currentVideoFile 187 const previousVideoFile = this.currentVideoFile
179 this.currentVideoFile = videoFile 188 this.currentVideoFile = videoFile
180 189
190 // Don't try on iOS that does not support MediaSource
191 // Or don't use P2P if webtorrent is disabled
192 if (this.isIOS() || this.playerRefusedP2P) {
193 return this.fallbackToHttp(options, () => {
194 this.player.playbackRate(oldPlaybackRate)
195 return done()
196 })
197 }
198
181 this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => { 199 this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => {
182 this.player.playbackRate(oldPlaybackRate) 200 this.player.playbackRate(oldPlaybackRate)
183 return done() 201 return done()
@@ -248,11 +266,7 @@ class PeerTubePlugin extends Plugin {
248 private addTorrent ( 266 private addTorrent (
249 magnetOrTorrentUrl: string, 267 magnetOrTorrentUrl: string,
250 previousVideoFile: VideoFile, 268 previousVideoFile: VideoFile,
251 options: { 269 options: PlayOptions,
252 forcePlay?: boolean,
253 seek?: number,
254 delay?: number
255 },
256 done: Function 270 done: Function
257 ) { 271 ) {
258 console.log('Adding ' + magnetOrTorrentUrl + '.') 272 console.log('Adding ' + magnetOrTorrentUrl + '.')
@@ -288,7 +302,7 @@ class PeerTubePlugin extends Plugin {
288 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => { 302 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
289 this.renderer = renderer 303 this.renderer = renderer
290 304
291 if (err) return this.fallbackToHttp(done) 305 if (err) return this.fallbackToHttp(options, done)
292 306
293 return this.tryToPlay(err => { 307 return this.tryToPlay(err => {
294 if (err) return done(err) 308 if (err) return done(err)
@@ -296,7 +310,7 @@ class PeerTubePlugin extends Plugin {
296 if (options.seek) this.seek(options.seek) 310 if (options.seek) this.seek(options.seek)
297 if (options.forcePlay === false && paused === true) this.player.pause() 311 if (options.forcePlay === false && paused === true) this.player.pause()
298 312
299 return done(err) 313 return done()
300 }) 314 })
301 }) 315 })
302 }, options.delay || 0) 316 }, options.delay || 0)
@@ -432,12 +446,6 @@ class PeerTubePlugin extends Plugin {
432 return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) 446 return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
433 } 447 }
434 448
435 // Don't try on iOS that does not support MediaSource
436 if (this.isIOS()) {
437 this.currentVideoFile = this.pickAverageVideoFile()
438 return this.fallbackToHttp(undefined, false)
439 }
440
441 // Proxy first play 449 // Proxy first play
442 const oldPlay = this.player.play.bind(this.player) 450 const oldPlay = this.player.play.bind(this.player)
443 this.player.play = () => { 451 this.player.play = () => {
@@ -567,7 +575,9 @@ class PeerTubePlugin extends Plugin {
567 return fetch(url, { method: 'PUT', body, headers }) 575 return fetch(url, { method: 'PUT', body, headers })
568 } 576 }
569 577
570 private fallbackToHttp (done?: Function, play = true) { 578 private fallbackToHttp (options: PlayOptions, done?: Function) {
579 const paused = this.player.paused()
580
571 this.disableAutoResolution(true) 581 this.disableAutoResolution(true)
572 582
573 this.flushVideoFile(this.currentVideoFile, true) 583 this.flushVideoFile(this.currentVideoFile, true)
@@ -579,9 +589,15 @@ class PeerTubePlugin extends Plugin {
579 const httpUrl = this.currentVideoFile.fileUrl 589 const httpUrl = this.currentVideoFile.fileUrl
580 this.player.src = this.savePlayerSrcFunction 590 this.player.src = this.savePlayerSrcFunction
581 this.player.src(httpUrl) 591 this.player.src(httpUrl)
582 if (play) this.tryToPlay()
583 592
584 if (done) return done() 593 return this.tryToPlay(err => {
594 if (err && done) return done(err)
595
596 if (options.seek) this.seek(options.seek)
597 if (options.forcePlay === false && paused === true) this.player.pause()
598
599 if (done) return done()
600 })
585 } 601 }
586 602
587 private handleError (err: Error | string) { 603 private handleError (err: Error | string) {