forked from chaabni/echoes-ng2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
98 lines (87 loc) · 2.94 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Angular 2 decorators and services
*/
import {Component} from '@angular/core';
import {RouteConfig, Router, ROUTER_DIRECTIVES} from '@angular/router-deprecated';
import {FORM_PROVIDERS} from '@angular/common';
// import { InfiniteScroll } from 'angular2-infinite-scroll';
// DIRECTIVES/COMPONENTS
import { InfiniteScroll } from './core/directives/infinite-scroll/infinite-scroll';
import { YoutubeVideos } from './youtube-videos/youtube-videos';
import { UserArea } from './user-area/user-area';
import { YoutubePlayer } from './youtube-player/youtube-player';
import { NowPlaylist } from './now-playlist/now-playlist';
import { NowPlaylistFilter } from './now-playlist-filter/now-playlist-filter';
// SERVICES
import { UserManager } from './core/services/user-manager.service';
import { YoutubeSearch } from './core/services/youtube.search';
import { YoutubePlayerService } from './core/services/youtube-player.service';
import { NowPlaylistService } from './core/services/now-playlist.service';
import { YoutubeVideosInfo } from './core/services/youtube-videos-info.service';
import { YoutubePlayerState } from './core/store/youtube-player.ts';
import { Observable } from "rxjs/Observable";
import { YoutubeMediaPlaylist } from './core/store/now-playlist';
/*
* App Component
* Top Level Component
*/
@Component({
selector: 'app',
providers: [...FORM_PROVIDERS, YoutubeSearch,
YoutubePlayerService, NowPlaylistService, UserManager,
NowPlaylistService,
YoutubeVideosInfo
],
directives: [...ROUTER_DIRECTIVES,
InfiniteScroll,
YoutubePlayer,
NowPlaylist,
NowPlaylistFilter
],
pipes: [],
styles: [],
template: require('./app.html')
})
@RouteConfig([
{ path: '/', component: YoutubeVideos, name: 'Index' },
{ path: '/user', component: UserArea, name: 'UserArea' },
// { path: '/home', component: Home, name: 'Home' },
{ path: '/**', redirectTo: ['Index'] }
])
export class App {
public start = true;
public player: Observable<YoutubePlayerState>;
public nowPlaylist: Observable<YoutubeMediaPlaylist>;
constructor(public youtubeSearch: YoutubeSearch,
public playerService: YoutubePlayerService,
public nowPlaylistService: NowPlaylistService
) {
this.player = this.playerService.player$;
this.nowPlaylist = nowPlaylistService.playlist$;
}
onScroll () {
if (this.start) {
this.start = false;
return;
}
this.youtubeSearch.searchMore();
}
selectVideo (media: GoogleApiYouTubeSearchResource) {
this.playerService.playVideo(media);
this.nowPlaylistService.updateIndexByMedia(media);
}
handleVideoEnded (state) {
if (!this.isLastIndex()) {
this.playNextVideo(state);
}
}
playNextVideo (player) {
this.nowPlaylistService.selectNextIndex();
this.selectVideo(this.nowPlaylistService.getCurrent());
}
sortVideo (media: GoogleApiYouTubeSearchResource) {
}
isLastIndex () {
// return this.nowPlaylist.index + 1 === this.nowPlaylist.length;
}
}