diff options
Diffstat (limited to 'client/src/app')
7 files changed, 18 insertions, 77 deletions
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 @@ | |||
1 | import { Subject } from 'rxjs' | 1 | import { Subject } from 'rxjs' |
2 | import { Injectable, NgZone } from '@angular/core' | 2 | import { io, Socket } from 'socket.io-client' |
3 | import { Injectable } from '@angular/core' | ||
3 | import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' | 4 | import { LiveVideoEventPayload, LiveVideoEventType, UserNotification as UserNotificationServer } from '@shared/models' |
4 | import { environment } from '../../../environments/environment' | 5 | import { environment } from '../../../environments/environment' |
5 | import { AuthService } from '../auth' | 6 | import { AuthService } from '../auth' |
6 | import { io, Socket } from 'socket.io-client' | ||
7 | 7 | ||
8 | export type NotificationEvent = 'new' | 'read' | 'read-all' | 8 | export 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' | |||
3 | export * from './i18n-utils' | 3 | export * from './i18n-utils' |
4 | export * from './rxjs' | 4 | export * from './rxjs' |
5 | export * from './utils' | 5 | export * from './utils' |
6 | export * 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 @@ | |||
1 | import { uniq } from 'lodash-es' | 1 | import { uniq } from 'lodash-es' |
2 | import { asyncScheduler, Observable } from 'rxjs' | 2 | import { Observable } from 'rxjs' |
3 | import { bufferTime, distinctUntilChanged, filter, map, observeOn, share, switchMap } from 'rxjs/operators' | 3 | import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators' |
4 | import { NgZone } from '@angular/core' | ||
5 | import { enterZone, leaveZone } from './zone' | ||
6 | 4 | ||
7 | function buildBulkObservable <T extends number | string, R> (options: { | 5 | function 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 @@ | |||
1 | import { SchedulerLike, Subscription } from 'rxjs' | ||
2 | import { NgZone } from '@angular/core' | ||
3 | |||
4 | class 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 | |||
19 | class 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 | |||
34 | export function leaveZone (zone: NgZone, scheduler: SchedulerLike): SchedulerLike { | ||
35 | return new LeaveZoneScheduler(zone, scheduler) | ||
36 | } | ||
37 | |||
38 | export 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 @@ | |||
1 | import * as debug from 'debug' | 1 | import * as debug from 'debug' |
2 | import { Observable, Subject } from 'rxjs' | 2 | import { Observable, Subject } from 'rxjs' |
3 | import { first, map } from 'rxjs/operators' | 3 | import { first, map } from 'rxjs/operators' |
4 | import { Injectable, NgZone } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { buildBulkObservable } from '@app/helpers' | 5 | import { buildBulkObservable } from '@app/helpers' |
6 | import { ResultList } from '@shared/models/common' | 6 | import { ResultList } from '@shared/models/common' |
7 | import { Video, VideoChannel } from '../shared-main' | 7 | import { 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' | |||
2 | import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' | 2 | import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' |
3 | import { catchError, filter, map, switchMap, tap } from 'rxjs/operators' | 3 | import { catchError, filter, map, switchMap, tap } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams } from '@angular/common/http' | 4 | import { HttpClient, HttpParams } from '@angular/common/http' |
5 | import { Injectable, NgZone } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' | 6 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' |
7 | import { buildBulkObservable } from '@app/helpers' | 7 | import { buildBulkObservable } from '@app/helpers' |
8 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | 8 | import { 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' | |||
2 | import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' | 2 | import { merge, Observable, of, ReplaySubject, Subject } from 'rxjs' |
3 | import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' | 3 | import { catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' |
4 | import { HttpClient, HttpParams } from '@angular/common/http' | 4 | import { HttpClient, HttpParams } from '@angular/common/http' |
5 | import { Injectable, NgZone } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core' | 6 | import { AuthUser, ComponentPaginationLight, RestExtractor, RestService, ServerService } from '@app/core' |
7 | import { buildBulkObservable, objectToFormData } from '@app/helpers' | 7 | import { buildBulkObservable, objectToFormData } from '@app/helpers' |
8 | import { Account, AccountService, VideoChannel, VideoChannelService } from '@app/shared/shared-main' | 8 | import { 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 | }), |