1 import { forkJoin } from 'rxjs'
2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { Video, VideoChannel } from '@app/shared/shared-main'
5 import { SearchService } from '@app/shared/shared-search'
8 selector: 'my-remote-interaction',
9 templateUrl: './remote-interaction.component.html'
11 export class RemoteInteractionComponent implements OnInit {
15 private route: ActivatedRoute,
16 private router: Router,
17 private search: SearchService
21 const uri = this.route.snapshot.queryParams['uri']
24 this.error = $localize`URL parameter is missing in URL parameters`
31 private loadUrl (uri: string) {
33 this.search.searchVideos({ search: uri }),
34 this.search.searchVideoChannels({ search: uri })
35 ]).subscribe(([ videoResult, channelResult ]) => {
36 let redirectUrl: string
38 if (videoResult.data.length !== 0) {
39 const video = videoResult.data[0]
41 redirectUrl = Video.buildWatchUrl(video)
42 } else if (channelResult.data.length !== 0) {
43 const channel = new VideoChannel(channelResult.data[0])
45 redirectUrl = '/c/' + channel.nameWithHost
47 this.error = $localize`Cannot access to the remote resource`
51 this.router.navigateByUrl(redirectUrl)