aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/e2e/src/po/player.po.ts2
-rw-r--r--client/src/app/core/notification/peertube-socket.service.ts23
-rw-r--r--client/src/app/helpers/index.ts1
-rw-r--r--client/src/app/helpers/rxjs.ts13
-rw-r--r--client/src/app/helpers/zone.ts40
-rw-r--r--client/src/app/shared/shared-search/find-in-bulk.service.ts6
-rw-r--r--client/src/app/shared/shared-user-subscription/user-subscription.service.ts6
-rw-r--r--client/src/app/shared/shared-video-playlist/video-playlist.service.ts6
8 files changed, 19 insertions, 78 deletions
diff --git a/client/e2e/src/po/player.po.ts b/client/e2e/src/po/player.po.ts
index fca3bcdba..a20e683bc 100644
--- a/client/e2e/src/po/player.po.ts
+++ b/client/e2e/src/po/player.po.ts
@@ -35,7 +35,7 @@ export class PlayerPage {
35 35
36 // Autoplay is disabled on iOS and Safari 36 // Autoplay is disabled on iOS and Safari
37 if (isIOS() || isSafari() || isMobileDevice()) { 37 if (isIOS() || isSafari() || isMobileDevice()) {
38 // We can't play the video using protractor if it is not muted 38 // We can't play the video if it is not muted
39 await browser.execute(`document.querySelector('video').muted = true`) 39 await browser.execute(`document.querySelector('video').muted = true`)
40 await this.clickOnPlayButton() 40 await this.clickOnPlayButton()
41 } else if (isAutoplay === false) { 41 } else if (isAutoplay === false) {
diff --git a/client/src/app/core/notification/peertube-socket.service.ts b/client/src/app/core/notification/peertube-socket.service.ts
index 50d5df68f..0db86d8e7 100644
--- a/client/src/app/core/notification/peertube-socket.service.ts
+++ b/client/src/app/core/notification/peertube-socket.service.ts
@@ -1,9 +1,9 @@
1import { Subject } from 'rxjs' 1import { Subject } from 'rxjs'
2import { Injectable, NgZone } from '@angular/core' 2import { io, Socket } from 'socket.io-client'
3import { Injectable } from '@angular/core'
3import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' 4import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models'
4import { environment } from '../../../environments/environment' 5import { environment } from '../../../environments/environment'
5import { AuthService } from '../auth' 6import { AuthService } from '../auth'
6import { io, Socket } from 'socket.io-client'
7 7
8export type NotificationEvent = 'new' | 'read' | 'read-all' 8export type NotificationEvent = 'new' | 'read' | 'read-all'
9 9
@@ -18,8 +18,7 @@ export class PeerTubeSocket {
18 private liveVideosSocket: Socket 18 private liveVideosSocket: Socket
19 19
20 constructor ( 20 constructor (
21 private auth: AuthService, 21 private auth: AuthService
22 private ngZone: NgZone
23 ) {} 22 ) {}
24 23
25 async getMyNotificationsSocket () { 24 async getMyNotificationsSocket () {
@@ -53,15 +52,12 @@ export class PeerTubeSocket {
53 52
54 await this.importIOIfNeeded() 53 await this.importIOIfNeeded()
55 54
56 // Prevent protractor issues https://github.com/angular/angular/issues/11853 55 this.notificationSocket = this.io(environment.apiUrl + '/user-notifications', {
57 this.ngZone.runOutsideAngular(() => { 56 query: { accessToken: this.auth.getAccessToken() }
58 this.notificationSocket = this.io(environment.apiUrl + '/user-notifications', {
59 query: { accessToken: this.auth.getAccessToken() }
60 })
61 }) 57 })
62 58
63 this.notificationSocket.on('new-notification', (n: UserNotificationServer) => { 59 this.notificationSocket.on('new-notification', (n: UserNotificationServer) => {
64 this.ngZone.run(() => this.dispatchNotificationEvent('new', n)) 60 this.dispatchNotificationEvent('new', n)
65 }) 61 })
66 } 62 }
67 63
@@ -70,16 +66,13 @@ export class PeerTubeSocket {
70 66
71 await this.importIOIfNeeded() 67 await this.importIOIfNeeded()
72 68
73 // Prevent protractor issues https://github.com/angular/angular/issues/11853 69 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos')
74 this.ngZone.runOutsideAngular(() => {
75 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos')
76 })
77 70
78 const types: LiveVideoEventType[] = [ 'views-change', 'state-change' ] 71 const types: LiveVideoEventType[] = [ 'views-change', 'state-change' ]
79 72
80 for (const type of types) { 73 for (const type of types) {
81 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => { 74 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => {
82 this.ngZone.run(() => this.dispatchLiveVideoEvent(type, payload)) 75 this.dispatchLiveVideoEvent(type, payload)
83 }) 76 })
84 } 77 }
85 } 78 }
diff --git a/client/src/app/helpers/index.ts b/client/src/app/helpers/index.ts
index beff749ec..8cdda83f3 100644
--- a/client/src/app/helpers/index.ts
+++ b/client/src/app/helpers/index.ts
@@ -3,4 +3,3 @@ export * from './constants'
3export * from './i18n-utils' 3export * from './i18n-utils'
4export * from './rxjs' 4export * from './rxjs'
5export * from './utils' 5export * from './utils'
6export * from './zone'
diff --git a/client/src/app/helpers/rxjs.ts b/client/src/app/helpers/rxjs.ts
index eb051f868..625bca0f7 100644
--- a/client/src/app/helpers/rxjs.ts
+++ b/client/src/app/helpers/rxjs.ts
@@ -1,24 +1,19 @@
1import { uniq } from 'lodash-es' 1import { uniq } from 'lodash-es'
2import { asyncScheduler, Observable } from 'rxjs' 2import { Observable } from 'rxjs'
3import { bufferTime, distinctUntilChanged, filter, map, observeOn, share, switchMap } from 'rxjs/operators' 3import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
4import { NgZone } from '@angular/core'
5import { enterZone, leaveZone } from './zone'
6 4
7function buildBulkObservable <T extends number | string, R> (options: { 5function buildBulkObservable <T extends number | string, R> (options: {
8 ngZone: NgZone
9 notifierObservable: Observable<T> 6 notifierObservable: Observable<T>
10 time: number 7 time: number
11 bulkGet: (params: T[]) => Observable<R> 8 bulkGet: (params: T[]) => Observable<R>
12}) { 9}) {
13 const { ngZone, notifierObservable, time, bulkGet } = options 10 const { notifierObservable, time, bulkGet } = options
14 11
15 return notifierObservable.pipe( 12 return notifierObservable.pipe(
16 distinctUntilChanged(), 13 distinctUntilChanged(),
17 // We leave Angular zone so Protractor does not get stuck 14 bufferTime(time),
18 bufferTime(time, leaveZone(ngZone, asyncScheduler)),
19 filter(params => params.length !== 0), 15 filter(params => params.length !== 0),
20 map(params => uniq(params)), 16 map(params => uniq(params)),
21 observeOn(enterZone(ngZone, asyncScheduler)),
22 switchMap(params => bulkGet(params)), 17 switchMap(params => bulkGet(params)),
23 share() 18 share()
24 ) 19 )
diff --git a/client/src/app/helpers/zone.ts b/client/src/app/helpers/zone.ts
deleted file mode 100644
index 74eed7032..000000000
--- a/client/src/app/helpers/zone.ts
+++ /dev/null
@@ -1,40 +0,0 @@
1import { SchedulerLike, Subscription } from 'rxjs'
2import { NgZone } from '@angular/core'
3
4class LeaveZoneScheduler implements SchedulerLike {
5 constructor (private zone: NgZone, private scheduler: SchedulerLike) {
6 }
7
8 schedule (...args: any[]): Subscription {
9 return this.zone.runOutsideAngular(() =>
10 this.scheduler.schedule.apply(this.scheduler, args)
11 )
12 }
13
14 now (): number {
15 return this.scheduler.now()
16 }
17}
18
19class EnterZoneScheduler implements SchedulerLike {
20 constructor (private zone: NgZone, private scheduler: SchedulerLike) {
21 }
22
23 schedule (...args: any[]): Subscription {
24 return this.zone.run(() =>
25 this.scheduler.schedule.apply(this.scheduler, args)
26 )
27 }
28
29 now (): number {
30 return this.scheduler.now()
31 }
32}
33
34export function leaveZone (zone: NgZone, scheduler: SchedulerLike): SchedulerLike {
35 return new LeaveZoneScheduler(zone, scheduler)
36}
37
38export function enterZone (zone: NgZone, scheduler: SchedulerLike): SchedulerLike {
39 return new EnterZoneScheduler(zone, scheduler)
40}
diff --git a/client/src/app/shared/shared-search/find-in-bulk.service.ts b/client/src/app/shared/shared-search/find-in-bulk.service.ts
index 962e374a5..6d77941d3 100644
--- a/client/src/app/shared/shared-search/find-in-bulk.service.ts
+++ b/client/src/app/shared/shared-search/find-in-bulk.service.ts
@@ -1,7 +1,7 @@
1import * as debug from 'debug' 1import * as debug from 'debug'
2import { Observable, Subject } from 'rxjs' 2import { Observable, Subject } from 'rxjs'
3import { first, map } from 'rxjs/operators' 3import { first, map } from 'rxjs/operators'
4import { Injectable, NgZone } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { buildBulkObservable } from '@app/helpers' 5import { buildBulkObservable } from '@app/helpers'
6import { ResultList } from '@shared/models/common' 6import { ResultList } from '@shared/models/common'
7import { Video, VideoChannel } from '../shared-main' 7import { Video, VideoChannel } from '../shared-main'
@@ -23,8 +23,7 @@ export class FindInBulkService {
23 private getPlaylistInBulk: BulkObservables<string, ResultList<VideoPlaylist>> 23 private getPlaylistInBulk: BulkObservables<string, ResultList<VideoPlaylist>>
24 24
25 constructor ( 25 constructor (
26 private searchService: SearchService, 26 private searchService: SearchService
27 private ngZone: NgZone
28 ) { 27 ) {
29 this.getVideoInBulk = this.buildBulkObservableObject(this.getVideosInBulk.bind(this)) 28 this.getVideoInBulk = this.buildBulkObservableObject(this.getVideosInBulk.bind(this))
30 this.getChannelInBulk = this.buildBulkObservableObject(this.getChannelsInBulk.bind(this)) 29 this.getChannelInBulk = this.buildBulkObservableObject(this.getChannelsInBulk.bind(this))
@@ -115,7 +114,6 @@ export class FindInBulkService {
115 result: buildBulkObservable({ 114 result: buildBulkObservable({
116 time: 500, 115 time: 500,
117 bulkGet, 116 bulkGet,
118 ngZone: this.ngZone,
119 notifierObservable: notifier.asObservable() 117 notifierObservable: notifier.asObservable()
120 }) 118 })
121 } 119 }
diff --git a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts b/client/src/app/shared/shared-user-subscription/user-subscription.service.ts
index e4fc09b36..8d2de8173 100644
--- a/client/src/app/shared/shared-user-subscription/user-subscription.service.ts
+++ b/client/src/app/shared/shared-user-subscription/user-subscription.service.ts
@@ -2,7 +2,7 @@ import * as debug from 'debug'
2import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' 2import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs'
3import { catchError, filter, map, switchMap, tap } from 'rxjs/operators' 3import { catchError, filter, map, switchMap, tap } from 'rxjs/operators'
4import { HttpClient, HttpParams } from '@angular/common/http' 4import { HttpClient, HttpParams } from '@angular/common/http'
5import { Injectable, NgZone } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' 6import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core'
7import { buildBulkObservable } from '@app/helpers' 7import { buildBulkObservable } from '@app/helpers'
8import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' 8import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
@@ -30,13 +30,11 @@ export class UserSubscriptionService {
30 private authHttp: HttpClient, 30 private authHttp: HttpClient,
31 private restExtractor: RestExtractor, 31 private restExtractor: RestExtractor,
32 private videoService: VideoService, 32 private videoService: VideoService,
33 private restService: RestService, 33 private restService: RestService
34 private ngZone: NgZone
35 ) { 34 ) {
36 this.existsObservable = merge( 35 this.existsObservable = merge(
37 buildBulkObservable({ 36 buildBulkObservable({
38 time: 500, 37 time: 500,
39 ngZone: this.ngZone,
40 notifierObservable: this.existsSubject, 38 notifierObservable: this.existsSubject,
41 bulkGet: this.doSubscriptionsExist.bind(this) 39 bulkGet: this.doSubscriptionsExist.bind(this)
42 }), 40 }),
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
index 76835b9fc..02632c9eb 100644
--- a/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
+++ b/client/src/app/shared/shared-video-playlist/video-playlist.service.ts
@@ -2,7 +2,7 @@ import * as debug from 'debug'
2import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' 2import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs'
3import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' 3import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators'
4import { HttpClient, HttpParams } from '@angular/common/http' 4import { HttpClient, HttpParams } from '@angular/common/http'
5import { Injectable, NgZone } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core' 6import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core'
7import { buildBulkObservable, objectToFormData } from '@app/helpers' 7import { buildBulkObservable, objectToFormData } from '@app/helpers'
8import { Account, AccountService, VideoChannel, VideoChannelService } from '@app/shared/shared-main' 8import { Account, AccountService, VideoChannel, VideoChannelService } from '@app/shared/shared-main'
@@ -47,13 +47,11 @@ export class VideoPlaylistService {
47 private authHttp: HttpClient, 47 private authHttp: HttpClient,
48 private serverService: ServerService, 48 private serverService: ServerService,
49 private restExtractor: RestExtractor, 49 private restExtractor: RestExtractor,
50 private restService: RestService, 50 private restService: RestService
51 private ngZone: NgZone
52 ) { 51 ) {
53 this.videoExistsInPlaylistObservable = merge( 52 this.videoExistsInPlaylistObservable = merge(
54 buildBulkObservable({ 53 buildBulkObservable({
55 time: 500, 54 time: 500,
56 ngZone: this.ngZone,
57 bulkGet: this.doVideosExistInPlaylist.bind(this), 55 bulkGet: this.doVideosExistInPlaylist.bind(this),
58 notifierObservable: this.videoExistsInPlaylistNotifier 56 notifierObservable: this.videoExistsInPlaylistNotifier
59 }), 57 }),