From 31b6ddf86652502e0c96d77fa10861ce4af11aa4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 10 Apr 2019 09:23:18 +0200 Subject: Add ability to disable tracker --- client/src/app/core/server/server.service.ts | 3 +++ .../instance/instance-features-table.component.ts | 5 ++++- .../videos/+video-watch/video-watch.component.scss | 1 + .../videos/+video-watch/video-watch.component.ts | 18 ++++++++++----- client/src/assets/player/utils.ts | 5 +++++ client/src/sass/player/peertube-skin.scss | 6 ++--- client/src/standalone/videos/embed.ts | 26 +++++++++++++++------- 7 files changed, 46 insertions(+), 18 deletions(-) (limited to 'client/src') diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index b0c5d1130..3a8a535fd 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -105,6 +105,9 @@ export class ServerService { enabled: false } } + }, + tracker: { + enabled: true } } private videoCategories: Array> = [] diff --git a/client/src/app/shared/instance/instance-features-table.component.ts b/client/src/app/shared/instance/instance-features-table.component.ts index c0257fd59..72e7c2730 100644 --- a/client/src/app/shared/instance/instance-features-table.component.ts +++ b/client/src/app/shared/instance/instance-features-table.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from '@angular/core' import { ServerService } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' -import { ServerConfig } from '../../../../../shared' @Component({ selector: 'my-instance-features-table', @@ -65,6 +64,10 @@ export class InstanceFeaturesTableComponent implements OnInit { { label: this.i18n('Torrent import'), value: config.import.videos.torrent.enabled + }, + { + label: this.i18n('P2P enabled'), + value: config.tracker.enabled } ] } diff --git a/client/src/app/videos/+video-watch/video-watch.component.scss b/client/src/app/videos/+video-watch/video-watch.component.scss index d61a0bc3e..84b9aed39 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.scss +++ b/client/src/app/videos/+video-watch/video-watch.component.scss @@ -427,6 +427,7 @@ my-video-comments { // If the view is not expanded, take into account the menu .privacy-concerns { width: calc(100% - #{$menu-width}); + margin-left: -15px; } @media screen and (max-width: $small-view) { diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index edc546b28..bce652210 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -29,6 +29,7 @@ import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' import { ComponentPagination } from '@app/shared/rest/component-pagination.model' import { Video } from '@app/shared/video/video.model' +import { isWebRTCDisabled } from '../../../assets/player/utils' @Component({ selector: 'my-video-watch', @@ -71,6 +72,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private currentTime: number private paramsSub: Subscription private queryParamsSub: Subscription + private configSub: Subscription constructor ( private elementRef: ElementRef, @@ -100,12 +102,16 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } ngOnInit () { - if ( - !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false || - peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true' - ) { - this.hasAlreadyAcceptedPrivacyConcern = true - } + this.configSub = this.serverService.configLoaded + .subscribe(() => { + if ( + isWebRTCDisabled() || + this.serverService.getConfig().tracker.enabled === false || + peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true' + ) { + this.hasAlreadyAcceptedPrivacyConcern = true + } + }) this.paramsSub = this.route.params.subscribe(routeParams => { const videoId = routeParams[ 'videoId' ] diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 0966027ac..366689962 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -4,6 +4,10 @@ function toTitleCase (str: string) { return str.charAt(0).toUpperCase() + str.slice(1) } +function isWebRTCDisabled () { + return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false +} + // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts // Don't import all Angular stuff, just copy the code with shame const dictionaryBytes: Array<{max: number, type: string}> = [ @@ -141,6 +145,7 @@ export { toTitleCase, timeToInt, secondsToTime, + isWebRTCDisabled, buildVideoLink, buildVideoEmbed, videoFileMaxByResolution, diff --git a/client/src/sass/player/peertube-skin.scss b/client/src/sass/player/peertube-skin.scss index a6942001a..e63a2875c 100644 --- a/client/src/sass/player/peertube-skin.scss +++ b/client/src/sass/player/peertube-skin.scss @@ -21,16 +21,16 @@ .vjs-dock-description { font-size: 11px; - &::before, &::after { + .text::before, .text::after { display: inline-block; content: '\1F308'; } - &::before { + .text::before { margin-right: 4px; } - &::after { + .text::after { margin-left: 4px; transform: scale(-1, 1); } diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 626d55a7c..707f04253 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -2,7 +2,7 @@ import './embed.scss' import * as Channel from 'jschannel' -import { peertubeTranslate, ResultList, VideoDetails } from '../../../../shared' +import { peertubeTranslate, ResultList, ServerConfig, VideoDetails } from '../../../../shared' import { PeerTubeResolution } from '../player/definitions' import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' @@ -177,6 +177,10 @@ class PeerTubeEmbed { return fetch(this.getVideoUrl(videoId) + '/captions') } + loadConfig (): Promise { + return fetch('/api/v1/config') + } + removeElement (element: HTMLElement) { element.parentElement.removeChild(element) } @@ -237,10 +241,10 @@ class PeerTubeEmbed { try { const params = new URL(window.location.toString()).searchParams - this.autoplay = this.getParamToggle(params, 'autoplay') - this.controls = this.getParamToggle(params, 'controls') - this.muted = this.getParamToggle(params, 'muted') - this.loop = this.getParamToggle(params, 'loop') + this.autoplay = this.getParamToggle(params, 'autoplay', false) + this.controls = this.getParamToggle(params, 'controls', true) + this.muted = this.getParamToggle(params, 'muted', false) + this.loop = this.getParamToggle(params, 'loop', false) this.enableApi = this.getParamToggle(params, 'api', this.enableApi) this.scope = this.getParamString(params, 'scope', this.scope) @@ -258,10 +262,11 @@ class PeerTubeEmbed { const urlParts = window.location.pathname.split('/') const videoId = urlParts[ urlParts.length - 1 ] - const [ serverTranslations, videoResponse, captionsResponse ] = await Promise.all([ + const [ serverTranslations, videoResponse, captionsResponse, configResponse ] = await Promise.all([ PeertubePlayerManager.getServerTranslations(window.location.origin, navigator.language), this.loadVideoInfo(videoId), - this.loadVideoCaptions(videoId) + this.loadVideoCaptions(videoId), + this.loadConfig() ]) if (!videoResponse.ok) { @@ -338,9 +343,14 @@ class PeerTubeEmbed { window[ 'videojsPlayer' ] = this.player if (this.controls) { + const config: ServerConfig = await configResponse.json() + const description = config.tracker.enabled + ? '' + this.player.localize('Uses P2P, others may know your IP is downloading this video.') + '' + : undefined + this.player.dock({ title: videoInfo.name, - description: this.player.localize('Uses P2P, others may know your IP is downloading this video.') + description }) } -- cgit v1.2.3