Do not prefix private attributes
This commit is contained in:
parent
41a2aee38c
commit
ccf6ed16f1
15 changed files with 112 additions and 93 deletions
|
@ -53,14 +53,13 @@ export class AppComponent {
|
||||||
search_field: string = name;
|
search_field: string = name;
|
||||||
choices = [];
|
choices = [];
|
||||||
|
|
||||||
constructor(private _friendService: FriendService,
|
constructor(private friendService: FriendService,
|
||||||
private _authService: AuthService,
|
private authService: AuthService,
|
||||||
private _router: Router
|
private router: Router
|
||||||
|
|
||||||
) {
|
) {
|
||||||
this.isLoggedIn = this._authService.isLoggedIn();
|
this.isLoggedIn = this.authService.isLoggedIn();
|
||||||
|
|
||||||
this._authService.loginChanged$.subscribe(
|
this.authService.loginChangedSource.subscribe(
|
||||||
status => {
|
status => {
|
||||||
if (status === AuthStatus.LoggedIn) {
|
if (status === AuthStatus.LoggedIn) {
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
|
@ -75,9 +74,9 @@ export class AppComponent {
|
||||||
search: search.value,
|
search: search.value,
|
||||||
field: search.field
|
field: search.field
|
||||||
};
|
};
|
||||||
this._router.navigate(['VideosList', params]);
|
this.router.navigate(['VideosList', params]);
|
||||||
} else {
|
} else {
|
||||||
this._router.navigate(['VideosList']);
|
this.router.navigate(['VideosList']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +85,7 @@ export class AppComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
makeFriends() {
|
makeFriends() {
|
||||||
this._friendService.makeFriends().subscribe(
|
this.friendService.makeFriends().subscribe(
|
||||||
status => {
|
status => {
|
||||||
if (status === 409) {
|
if (status === 409) {
|
||||||
alert('Already made friends!');
|
alert('Already made friends!');
|
||||||
|
@ -99,7 +98,7 @@ export class AppComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
quitFriends() {
|
quitFriends() {
|
||||||
this._friendService.quitFriends().subscribe(
|
this.friendService.quitFriends().subscribe(
|
||||||
status => {
|
status => {
|
||||||
alert('Quit friends!');
|
alert('Quit friends!');
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,23 +4,23 @@ import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FriendService {
|
export class FriendService {
|
||||||
private _baseFriendsUrl = '/api/v1/pods/';
|
private static BASE_FRIEND_URL: string = '/api/v1/pods/';
|
||||||
|
|
||||||
constructor (private http: Http) {}
|
constructor (private http: Http) {}
|
||||||
|
|
||||||
makeFriends() {
|
makeFriends() {
|
||||||
return this.http.get(this._baseFriendsUrl + 'makefriends')
|
return this.http.get(FriendService.BASE_FRIEND_URL + 'makefriends')
|
||||||
.map(res => <number> res.status)
|
.map(res => res.status)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
quitFriends() {
|
quitFriends() {
|
||||||
return this.http.get(this._baseFriendsUrl + 'quitfriends')
|
return this.http.get(FriendService.BASE_FRIEND_URL + 'quitfriends')
|
||||||
.map(res => <number> res.status)
|
.map(res => res.status)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError (error: Response) {
|
private handleError (error: Response): Observable<number> {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return Observable.throw(error.json().error || 'Server error');
|
return Observable.throw(error.json().error || 'Server error');
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,13 @@ import { SearchField } from './search-field.type';
|
||||||
})
|
})
|
||||||
|
|
||||||
export class SearchComponent {
|
export class SearchComponent {
|
||||||
@Output() search: EventEmitter<Search> = new EventEmitter<Search>();
|
@Output() search = new EventEmitter<Search>();
|
||||||
|
|
||||||
searchCriterias: Search = {
|
searchCriterias: Search = {
|
||||||
field: 'name',
|
field: 'name',
|
||||||
value: ''
|
value: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
fieldChoices = {
|
fieldChoices = {
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
author: 'Author',
|
author: 'Author',
|
||||||
|
@ -29,7 +30,7 @@ export class SearchComponent {
|
||||||
return Object.keys(this.fieldChoices);
|
return Object.keys(this.fieldChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
getStringChoice(choiceKey: SearchField): string {
|
getStringChoice(choiceKey: SearchField) {
|
||||||
return this.fieldChoices[choiceKey];
|
return this.fieldChoices[choiceKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ export class SearchComponent {
|
||||||
this.searchCriterias.field = choice;
|
this.searchCriterias.field = choice;
|
||||||
}
|
}
|
||||||
|
|
||||||
doSearch(): void {
|
doSearch() {
|
||||||
this.search.emit(this.searchCriterias);
|
this.search.emit(this.searchCriterias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,17 @@ import { AuthService, AuthStatus, User } from '../shared/index';
|
||||||
})
|
})
|
||||||
|
|
||||||
export class UserLoginComponent {
|
export class UserLoginComponent {
|
||||||
constructor(private _authService: AuthService, private _router: Router) {}
|
constructor(private authService: AuthService, private router: Router) {}
|
||||||
|
|
||||||
login(username: string, password: string) {
|
login(username: string, password: string) {
|
||||||
this._authService.login(username, password).subscribe(
|
this.authService.login(username, password).subscribe(
|
||||||
result => {
|
result => {
|
||||||
const user = new User(username, result);
|
const user = new User(username, result);
|
||||||
user.save();
|
user.save();
|
||||||
|
|
||||||
this._authService.setStatus(AuthStatus.LoggedIn);
|
this.authService.setStatus(AuthStatus.LoggedIn);
|
||||||
|
|
||||||
this._router.navigate(['VideosList']);
|
this.router.navigate(['VideosList']);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
if (error.error === 'invalid_grant') {
|
if (error.error === 'invalid_grant') {
|
||||||
|
|
|
@ -7,27 +7,28 @@ import { User } from './user.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
loginChanged$;
|
private static BASE_LOGIN_URL = '/api/v1/users/token';
|
||||||
|
private static BASE_CLIENT_URL = '/api/v1/users/client';
|
||||||
|
|
||||||
private _loginChanged;
|
loginChangedSource: Observable<AuthStatus>;
|
||||||
private _baseLoginUrl = '/api/v1/users/token';
|
|
||||||
private _baseClientUrl = '/api/v1/users/client';
|
private loginChanged: Subject<AuthStatus>;
|
||||||
private _clientId = '';
|
private clientId: string;
|
||||||
private _clientSecret = '';
|
private clientSecret: string;
|
||||||
|
|
||||||
constructor(private http: Http) {
|
constructor(private http: Http) {
|
||||||
this._loginChanged = new Subject<AuthStatus>();
|
this.loginChanged = new Subject<AuthStatus>();
|
||||||
this.loginChanged$ = this._loginChanged.asObservable();
|
this.loginChangedSource = this.loginChanged.asObservable();
|
||||||
|
|
||||||
// Fetch the client_id/client_secret
|
// Fetch the client_id/client_secret
|
||||||
// FIXME: save in local storage?
|
// FIXME: save in local storage?
|
||||||
this.http.get(this._baseClientUrl)
|
this.http.get(AuthService.BASE_CLIENT_URL)
|
||||||
.map(res => res.json())
|
.map(res => res.json())
|
||||||
.catch(this.handleError)
|
.catch(this.handleError)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result => {
|
result => {
|
||||||
this._clientId = result.client_id;
|
this.clientId = result.client_id;
|
||||||
this._clientSecret = result.client_secret;
|
this.clientSecret = result.client_secret;
|
||||||
console.log('Client credentials loaded.');
|
console.log('Client credentials loaded.');
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
|
@ -38,8 +39,8 @@ export class AuthService {
|
||||||
|
|
||||||
login(username: string, password: string) {
|
login(username: string, password: string) {
|
||||||
let body = new URLSearchParams();
|
let body = new URLSearchParams();
|
||||||
body.set('client_id', this._clientId);
|
body.set('client_id', this.clientId);
|
||||||
body.set('client_secret', this._clientSecret);
|
body.set('client_secret', this.clientSecret);
|
||||||
body.set('response_type', 'code');
|
body.set('response_type', 'code');
|
||||||
body.set('grant_type', 'password');
|
body.set('grant_type', 'password');
|
||||||
body.set('scope', 'upload');
|
body.set('scope', 'upload');
|
||||||
|
@ -53,7 +54,7 @@ export class AuthService {
|
||||||
headers: headers
|
headers: headers
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.http.post(this._baseLoginUrl, body.toString(), options)
|
return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
|
||||||
.map(res => res.json())
|
.map(res => res.json())
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +63,7 @@ export class AuthService {
|
||||||
// TODO make HTTP request
|
// TODO make HTTP request
|
||||||
}
|
}
|
||||||
|
|
||||||
getRequestHeader(): Headers {
|
getRequestHeader() {
|
||||||
return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
|
return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,11 +71,11 @@ export class AuthService {
|
||||||
return new RequestOptions({ headers: this.getRequestHeader() });
|
return new RequestOptions({ headers: this.getRequestHeader() });
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken(): string {
|
getToken() {
|
||||||
return localStorage.getItem('access_token');
|
return localStorage.getItem('access_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
getTokenType(): string {
|
getTokenType() {
|
||||||
return localStorage.getItem('token_type');
|
return localStorage.getItem('token_type');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ export class AuthService {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn() {
|
||||||
if (this.getToken()) {
|
if (this.getToken()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +98,7 @@ export class AuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatus(status: AuthStatus) {
|
setStatus(status: AuthStatus) {
|
||||||
this._loginChanged.next(status);
|
this.loginChanged.next(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError (error: Response) {
|
private handleError (error: Response) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ export class Token {
|
||||||
refresh_token: string;
|
refresh_token: string;
|
||||||
token_type: string;
|
token_type: string;
|
||||||
|
|
||||||
static load(): Token {
|
static load() {
|
||||||
return new Token({
|
return new Token({
|
||||||
access_token: localStorage.getItem('access_token'),
|
access_token: localStorage.getItem('access_token'),
|
||||||
refresh_token: localStorage.getItem('refresh_token'),
|
refresh_token: localStorage.getItem('refresh_token'),
|
||||||
|
@ -15,6 +15,7 @@ export class Token {
|
||||||
if (hash) {
|
if (hash) {
|
||||||
this.access_token = hash.access_token;
|
this.access_token = hash.access_token;
|
||||||
this.refresh_token = hash.refresh_token;
|
this.refresh_token = hash.refresh_token;
|
||||||
|
|
||||||
if (hash.token_type === 'bearer') {
|
if (hash.token_type === 'bearer') {
|
||||||
this.token_type = 'Bearer';
|
this.token_type = 'Bearer';
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +24,7 @@ export class Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save():void {
|
save() {
|
||||||
localStorage.setItem('access_token', this.access_token);
|
localStorage.setItem('access_token', this.access_token);
|
||||||
localStorage.setItem('refresh_token', this.refresh_token);
|
localStorage.setItem('refresh_token', this.refresh_token);
|
||||||
localStorage.setItem('token_type', this.token_type);
|
localStorage.setItem('token_type', this.token_type);
|
||||||
|
|
|
@ -4,7 +4,7 @@ export class User {
|
||||||
username: string;
|
username: string;
|
||||||
token: Token;
|
token: Token;
|
||||||
|
|
||||||
static load(): User {
|
static load() {
|
||||||
return new User(localStorage.getItem('username'), Token.load());
|
return new User(localStorage.getItem('username'), Token.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export class User {
|
||||||
this.token = new Token(hash_token);
|
this.token = new Token(hash_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
save(): void {
|
save() {
|
||||||
localStorage.setItem('username', this.username);
|
localStorage.setItem('username', this.username);
|
||||||
this.token.save();
|
this.token.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ export class Video {
|
||||||
by: string;
|
by: string;
|
||||||
duration: string;
|
duration: string;
|
||||||
|
|
||||||
private static createDurationString(duration: number): string {
|
private static createDurationString(duration: number) {
|
||||||
const minutes = Math.floor(duration / 60);
|
const minutes = Math.floor(duration / 60);
|
||||||
const seconds = duration % 60;
|
const seconds = duration % 60;
|
||||||
const minutes_padding = minutes >= 10 ? '' : '0';
|
const minutes_padding = minutes >= 10 ? '' : '0';
|
||||||
|
@ -20,7 +20,7 @@ export class Video {
|
||||||
return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
|
return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createByString(author: string, podUrl: string): string {
|
private static createByString(author: string, podUrl: string) {
|
||||||
let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
|
let [ host, port ] = podUrl.replace(/^https?:\/\//, '').split(':');
|
||||||
|
|
||||||
if (port === '80' || port === '443') {
|
if (port === '80' || port === '443') {
|
||||||
|
@ -57,7 +57,7 @@ export class Video {
|
||||||
this.by = Video.createByString(hash.author, hash.podUrl);
|
this.by = Video.createByString(hash.author, hash.podUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
isRemovableBy(user): boolean {
|
isRemovableBy(user) {
|
||||||
return this.isLocal === true && user && this.author === user.username;
|
return this.isLocal === true && user && this.author === user.username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,30 +10,30 @@ import { Video } from './video.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VideoService {
|
export class VideoService {
|
||||||
private _baseVideoUrl = '/api/v1/videos/';
|
private static BASE_VIDEO_URL = '/api/v1/videos/';
|
||||||
|
|
||||||
constructor (private http: Http, private _authService: AuthService) {}
|
constructor(private http: Http, private authService: AuthService) {}
|
||||||
|
|
||||||
getVideos(pagination: Pagination, sort: SortField) {
|
getVideos(pagination: Pagination, sort: SortField) {
|
||||||
const params = this.createPaginationParams(pagination);
|
const params = this.createPaginationParams(pagination);
|
||||||
|
|
||||||
if (sort) params.set('sort', sort);
|
if (sort) params.set('sort', sort);
|
||||||
|
|
||||||
return this.http.get(this._baseVideoUrl, { search: params })
|
return this.http.get(VideoService.BASE_VIDEO_URL, { search: params })
|
||||||
.map(res => res.json())
|
.map(res => res.json())
|
||||||
.map(this.extractVideos)
|
.map(this.extractVideos)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getVideo(id: string) {
|
getVideo(id: string) {
|
||||||
return this.http.get(this._baseVideoUrl + id)
|
return this.http.get(VideoService.BASE_VIDEO_URL + id)
|
||||||
.map(res => <Video> res.json())
|
.map(res => <Video> res.json())
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeVideo(id: string) {
|
removeVideo(id: string) {
|
||||||
const options = this._authService.getAuthRequestOptions();
|
const options = this.authService.getAuthRequestOptions();
|
||||||
return this.http.delete(this._baseVideoUrl + id, options)
|
return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
|
||||||
.map(res => <number> res.status)
|
.map(res => <number> res.status)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ export class VideoService {
|
||||||
if (search.field) params.set('field', search.field);
|
if (search.field) params.set('field', search.field);
|
||||||
if (sort) params.set('sort', sort);
|
if (sort) params.set('sort', sort);
|
||||||
|
|
||||||
return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params })
|
return this.http.get(VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value), { search: params })
|
||||||
.map(res => res.json())
|
.map(res => res.json())
|
||||||
.map(this.extractVideos)
|
.map(this.extractVideos)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
|
|
|
@ -31,26 +31,26 @@ export class VideoListComponent implements OnInit {
|
||||||
total: 0
|
total: 0
|
||||||
};
|
};
|
||||||
sort: SortField;
|
sort: SortField;
|
||||||
loading: boolean = false;
|
loading = false;
|
||||||
|
|
||||||
private search: Search;
|
private search: Search;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _authService: AuthService,
|
private authService: AuthService,
|
||||||
private _videoService: VideoService,
|
private videoService: VideoService,
|
||||||
private _routeParams: RouteParams,
|
private routeParams: RouteParams,
|
||||||
private _router: Router
|
private router: Router
|
||||||
) {
|
) {
|
||||||
this.search = {
|
this.search = {
|
||||||
value: this._routeParams.get('search'),
|
value: this.routeParams.get('search'),
|
||||||
field: <SearchField>this._routeParams.get('field')
|
field: <SearchField>this.routeParams.get('field')
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sort = <SortField>this._routeParams.get('sort') || '-createdDate';
|
this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this._authService.isLoggedIn()) {
|
if (this.authService.isLoggedIn()) {
|
||||||
this.user = User.load();
|
this.user = User.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ export class VideoListComponent implements OnInit {
|
||||||
let observable = null;
|
let observable = null;
|
||||||
|
|
||||||
if (this.search.value !== null) {
|
if (this.search.value !== null) {
|
||||||
observable = this._videoService.searchVideos(this.search, this.pagination, this.sort);
|
observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
|
||||||
} else {
|
} else {
|
||||||
observable = this._videoService.getVideos(this.pagination, this.sort);
|
observable = this.videoService.getVideos(this.pagination, this.sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
observable.subscribe(
|
observable.subscribe(
|
||||||
|
@ -79,7 +79,7 @@ export class VideoListComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemoved(video: Video): void {
|
onRemoved(video: Video) {
|
||||||
this.videos.splice(this.videos.indexOf(video), 1);
|
this.videos.splice(this.videos.indexOf(video), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ export class VideoListComponent implements OnInit {
|
||||||
params.field = this.search.field;
|
params.field = this.search.field;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._router.navigate(['VideosList', params]);
|
this.router.navigate(['VideosList', params]);
|
||||||
this.getVideos();
|
this.getVideos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ export class VideoMiniatureComponent {
|
||||||
@Input() video: Video;
|
@Input() video: Video;
|
||||||
@Input() user: User;
|
@Input() user: User;
|
||||||
|
|
||||||
hovering: boolean = false;
|
hovering = false;
|
||||||
|
|
||||||
constructor(private _videoService: VideoService) {}
|
constructor(private videoService: VideoService) {}
|
||||||
|
|
||||||
onHover() {
|
onHover() {
|
||||||
this.hovering = true;
|
this.hovering = true;
|
||||||
|
@ -31,13 +31,13 @@ export class VideoMiniatureComponent {
|
||||||
this.hovering = false;
|
this.hovering = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayRemoveIcon(): boolean {
|
displayRemoveIcon() {
|
||||||
return this.hovering && this.video.isRemovableBy(this.user);
|
return this.hovering && this.video.isRemovableBy(this.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeVideo(id: string) {
|
removeVideo(id: string) {
|
||||||
if (confirm('Do you really want to remove this video?')) {
|
if (confirm('Do you really want to remove this video?')) {
|
||||||
this._videoService.removeVideo(id).subscribe(
|
this.videoService.removeVideo(id).subscribe(
|
||||||
status => this.removed.emit(true),
|
status => this.removed.emit(true),
|
||||||
error => alert(error)
|
error => alert(error)
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class VideoSortComponent {
|
||||||
return Object.keys(this.sortChoices);
|
return Object.keys(this.sortChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
getStringChoice(choiceKey: SortField): string {
|
getStringChoice(choiceKey: SortField) {
|
||||||
return this.sortChoices[choiceKey];
|
return this.sortChoices[choiceKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,21 +23,21 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
|
||||||
numPeers: number;
|
numPeers: number;
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
|
|
||||||
private _interval: NodeJS.Timer;
|
private interval: NodeJS.Timer;
|
||||||
private client: any;
|
private client: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _videoService: VideoService,
|
private videoService: VideoService,
|
||||||
private _routeParams: RouteParams,
|
private routeParams: RouteParams,
|
||||||
private _elementRef: ElementRef
|
private elementRef: ElementRef
|
||||||
) {
|
) {
|
||||||
// TODO: use a service
|
// TODO: use a service
|
||||||
this.client = new WebTorrent({ dht: false });
|
this.client = new WebTorrent({ dht: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
let id = this._routeParams.get('id');
|
let id = this.routeParams.get('id');
|
||||||
this._videoService.getVideo(id).subscribe(
|
this.videoService.getVideo(id).subscribe(
|
||||||
video => this.loadVideo(video),
|
video => this.loadVideo(video),
|
||||||
error => alert(error)
|
error => alert(error)
|
||||||
);
|
);
|
||||||
|
@ -50,7 +50,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
|
||||||
this.client.add(this.video.magnetUri, (torrent) => {
|
this.client.add(this.video.magnetUri, (torrent) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
console.log('Added ' + this.video.magnetUri + '.');
|
console.log('Added ' + this.video.magnetUri + '.');
|
||||||
torrent.files[0].appendTo(this._elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
|
torrent.files[0].appendTo(this.elementRef.nativeElement.querySelector('.embed-responsive'), (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
alert('Cannot append the file.');
|
alert('Cannot append the file.');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -58,7 +58,7 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Refresh each second
|
// Refresh each second
|
||||||
this._interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
this.downloadSpeed = torrent.downloadSpeed;
|
this.downloadSpeed = torrent.downloadSpeed;
|
||||||
this.uploadSpeed = torrent.uploadSpeed;
|
this.uploadSpeed = torrent.uploadSpeed;
|
||||||
this.numPeers = torrent.numPeers;
|
this.numPeers = torrent.numPeers;
|
||||||
|
@ -66,9 +66,9 @@ export class VideoWatchComponent implements OnInit, CanDeactivate {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
console.log('Removing video from webtorrent.');
|
console.log('Removing video from webtorrent.');
|
||||||
clearInterval(this._interval);
|
clearInterval(this.interval);
|
||||||
this.client.remove(this.video.magnetUri);
|
this.client.remove(this.video.magnetUri);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,23 @@
|
||||||
"use-pipe-transform-interface": true,
|
"use-pipe-transform-interface": true,
|
||||||
"pipe-naming": [true, "camelCase", "my"],
|
"pipe-naming": [true, "camelCase", "my"],
|
||||||
"component-class-suffix": true,
|
"component-class-suffix": true,
|
||||||
"directive-class-suffix": true
|
"directive-class-suffix": true,
|
||||||
|
|
||||||
|
"typedef-whitespace": [ true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"whitespace": [ true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue