From 33c4972d5b54155540267f4c9c9ee55c539b8385 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jul 2017 10:09:18 +0200 Subject: Type webtorrent --- client/src/app/core/auth/auth-user.model.ts | 2 ++ client/src/app/core/auth/auth.service.ts | 34 +++++++++++++++++----- .../app/videos/video-list/video-list.component.ts | 15 +++++----- .../videos/video-watch/video-watch.component.ts | 12 ++++---- .../app/videos/video-watch/webtorrent.service.ts | 12 +++----- 5 files changed, 46 insertions(+), 29 deletions(-) (limited to 'client/src') diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 9cb201907..4155aea19 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -96,6 +96,7 @@ export class AuthUser extends User { localStorage.removeItem(this.KEYS.ID) localStorage.removeItem(this.KEYS.ROLE) localStorage.removeItem(this.KEYS.DISPLAY_NSFW) + localStorage.removeItem(this.KEYS.EMAIL) Tokens.flush() } @@ -130,6 +131,7 @@ export class AuthUser extends User { save () { localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()) localStorage.setItem(AuthUser.KEYS.USERNAME, this.username) + localStorage.setItem(AuthUser.KEYS.EMAIL, this.email) localStorage.setItem(AuthUser.KEYS.ROLE, this.role) localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW)) this.tokens.save() diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index d5aa80512..de9e14b2d 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,7 +11,7 @@ import { NotificationsService } from 'angular2-notifications' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' -import { OAuthClientLocal } from '../../../../../shared' +import { OAuthClientLocal, UserRole } from '../../../../../shared' // Do not use the barrel (dependency loop) import { RestExtractor } from '../../shared/rest' @@ -181,7 +181,10 @@ export class AuthService { refreshUserInformations () { const obj = { - access_token: this.user.getAccessToken() + access_token: this.user.getAccessToken(), + refresh_token: null, + token_type: this.user.getTokenType(), + username: this.user.username } this.mergeUserInformations (obj) @@ -195,7 +198,12 @@ export class AuthService { ) } - private mergeUserInformations (obj: { access_token: string }) { + private mergeUserInformations (obj: { + access_token: string, + refresh_token: string, + token_type: string, + username: string + }) { // Do not call authHttp here to avoid circular dependencies headaches const headers = new Headers() @@ -205,9 +213,10 @@ export class AuthService { .map(res => res.json()) .map(res => { const newProperties = { - id: res.id, - role: res.role, - displayNSFW: res.displayNSFW + id: res.id as number, + role: res.role as UserRole, + displayNSFW: res.displayNSFW as boolean, + email: res.email as string } return Object.assign(obj, newProperties) @@ -215,7 +224,16 @@ export class AuthService { ) } - private handleLogin (obj: any) { + private handleLogin (obj: { + access_token: string, + refresh_token: string, + token_type: string, + id: number, + username: string, + email: string, + role: UserRole, + displayNSFW: boolean + }) { const id = obj.id const username = obj.username const role = obj.role @@ -233,7 +251,7 @@ export class AuthService { this.setStatus(AuthStatus.LoggedIn) } - private handleRefreshToken (obj: any) { + private handleRefreshToken (obj: { access_token: string, refresh_token: string }) { this.user.refreshTokens(obj.access_token, obj.refresh_token) this.user.save() } diff --git a/client/src/app/videos/video-list/video-list.component.ts b/client/src/app/videos/video-list/video-list.component.ts index 0c36e5b08..4ac539960 100644 --- a/client/src/app/videos/video-list/video-list.component.ts +++ b/client/src/app/videos/video-list/video-list.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' +import { Subscription } from 'rxjs/Subscription' import { BehaviorSubject } from 'rxjs/BehaviorSubject' import { NotificationsService } from 'angular2-notifications' @@ -30,8 +31,8 @@ export class VideoListComponent implements OnInit, OnDestroy { videos: Video[] = [] private search: Search - private subActivatedRoute: any - private subSearch: any + private subActivatedRoute: Subscription + private subSearch: Subscription constructor ( private notificationsService: NotificationsService, @@ -98,7 +99,7 @@ export class VideoListComponent implements OnInit, OnDestroy { return !this.loading.getValue() && this.videos.length === 0 } - onPageChanged (event: any) { + onPageChanged (event: { page: number }) { // Be sure the current page is set this.pagination.currentPage = event.page @@ -113,21 +114,21 @@ export class VideoListComponent implements OnInit, OnDestroy { private buildRouteParams () { // There is always a sort and a current page - const params: any = { + const params = { sort: this.sort, page: this.pagination.currentPage } // Maybe there is a search if (this.search.value) { - params.field = this.search.field - params.search = this.search.value + params['field'] = this.search.field + params['search'] = this.search.value } return params } - private loadRouteParams (routeParams) { + private loadRouteParams (routeParams: { [ key: string ]: any }) { if (routeParams['search'] !== undefined) { this.search = { value: routeParams['search'], 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 12ddf3eef..6bd6c1f7e 100644 --- a/client/src/app/videos/video-watch/video-watch.component.ts +++ b/client/src/app/videos/video-watch/video-watch.component.ts @@ -32,7 +32,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { loading = false numPeers: number player: videojs.Player - playerElement: Element + playerElement: HTMLMediaElement uploadSpeed: number userRating: UserVideoRateType = null video: Video = null @@ -41,7 +41,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private errorTimer: number private paramsSub: Subscription private errorsSub: Subscription - private warningsSub: Subscription private torrentInfosInterval: number constructor ( @@ -82,8 +81,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy { self.player = this }) - this.errorsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.error('Error', err.message)) - this.warningsSub = this.webTorrentService.errors.subscribe(err => this.notificationsService.alert('Warning', err.message)) + this.errorsSub = this.webTorrentService.errors.subscribe(err => { + const message = typeof err === 'string' ? err : err.message + this.notificationsService.error('Error', message) + }) } ngOnDestroy () { @@ -102,7 +103,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy { // Unsubscribe subscriptions this.paramsSub.unsubscribe() this.errorsSub.unsubscribe() - this.warningsSub.unsubscribe() } loadVideo () { @@ -117,7 +117,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { // So we create a timer to inform the user the load is abnormally long this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG) - this.webTorrentService.add(this.video.magnetUri, (torrent) => { + this.webTorrentService.add(this.video.magnetUri, torrent => { // Clear the error timer window.clearTimeout(this.errorTimer) // Maybe the error was fired by the timer, so reset it diff --git a/client/src/app/videos/video-watch/webtorrent.service.ts b/client/src/app/videos/video-watch/webtorrent.service.ts index 211894bfd..8819e17d4 100644 --- a/client/src/app/videos/video-watch/webtorrent.service.ts +++ b/client/src/app/videos/video-watch/webtorrent.service.ts @@ -5,21 +5,17 @@ import * as WebTorrent from 'webtorrent' @Injectable() export class WebTorrentService { - errors = new Subject() - warnings = new Subject() + errors = new Subject() - // TODO: use WebTorrent @type - // private client: WebTorrent.Client - private client: any + private client: WebTorrent.Instance constructor () { this.client = new WebTorrent({ dht: false }) - this.client.on('error', (err) => this.errors.next(err)) - this.client.on('warning', (err) => this.warnings.next(err)) + this.client.on('error', err => this.errors.next(err)) } - add (magnetUri: string, callback: Function) { + add (magnetUri: string, callback: (torrent: WebTorrent.Torrent) => any) { return this.client.add(magnetUri, callback) } -- cgit v1.2.3