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',
10 styleUrls: [ './remote-interaction.component.scss' ]
12 export class RemoteInteractionComponent implements OnInit {
16 private route: ActivatedRoute,
17 private router: Router,
18 private search: SearchService
22 const uri = this.route.snapshot.queryParams['uri']
25 this.error = $localize`URL parameter is missing in URL parameters`
32 private loadUrl (uri: string) {
34 this.search.searchVideos({ search: uri }),
35 this.search.searchVideoChannels({ search: uri })
36 ]).subscribe(([ videoResult, channelResult ]) => {
37 let redirectUrl: string
39 if (videoResult.data.length !== 0) {
40 const video = videoResult.data[0]
42 redirectUrl = Video.buildWatchUrl(video)
43 } else if (channelResult.data.length !== 0) {
44 const channel = new VideoChannel(channelResult.data[0])
46 redirectUrl = '/c/' + channel.nameWithHost
48 this.error = $localize`Cannot access to the remote resource`
52 this.router.navigateByUrl(redirectUrl)