X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fstandalone%2Fvideos%2Fembed-api.ts;h=75174f2f8ef2a6eca1362ab52db7d3e7b8234001;hb=adb8809d43648ea0a64d6845bb39aa3bd0e005a6;hp=c5fbe07fa56c851cf60f01fdb9380ed66affe460;hpb=96aae68cc47b7ac9b9400d5b5cf95acdf9fe38da;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index c5fbe07fa..75174f2f8 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts @@ -1,7 +1,7 @@ import './embed.scss' import * as Channel from 'jschannel' -import { PeerTubeResolution } from '../player/definitions' +import { PeerTubeResolution, PeerTubeTextTrack } from '../player/definitions' import { PeerTubeEmbed } from './embed' /** @@ -26,7 +26,7 @@ export class PeerTubeEmbedApi { } private get element () { - return this.embed.videoElement + return this.embed.playerElement } private constructChannel () { @@ -44,9 +44,16 @@ export class PeerTubeEmbedApi { channel.bind('setResolution', (txn, resolutionId) => this.setResolution(resolutionId)) channel.bind('getResolutions', (txn, params) => this.resolutions) + channel.bind('getCaptions', (txn, params) => this.getCaptions()) + channel.bind('setCaption', (txn, id) => this.setCaption(id)), + channel.bind('setPlaybackRate', (txn, playbackRate) => this.embed.player.playbackRate(playbackRate)) channel.bind('getPlaybackRate', (txn, params) => this.embed.player.playbackRate()) channel.bind('getPlaybackRates', (txn, params) => this.embed.player.options_.playbackRates) + + channel.bind('playNextVideo', (txn, params) => this.embed.playNextVideo()) + channel.bind('playPreviousVideo', (txn, params) => this.embed.playPreviousVideo()) + channel.bind('getCurrentPosition', (txn, params) => this.embed.getCurrentPosition()) this.channel = channel } @@ -71,6 +78,26 @@ export class PeerTubeEmbedApi { this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId } + private getCaptions (): PeerTubeTextTrack[] { + return this.embed.player.textTracks().tracks_.map(t => { + return { + id: t.id, + src: t.src, + label: t.label, + mode: t.mode as any + } + }) + } + + private setCaption (id: string) { + const tracks = this.embed.player.textTracks().tracks_ + + for (const track of tracks) { + if (track.id === id) track.mode = 'showing' + else track.mode = 'disabled' + } + } + /** * Let the host know that we're ready to go! */ @@ -91,6 +118,7 @@ export class PeerTubeEmbedApi { params: { position, volume, + duration: this.embed.player.duration(), playbackState: currentState } }) @@ -112,12 +140,14 @@ export class PeerTubeEmbedApi { }) // PeerTube specific capabilities - if (this.isWebtorrent()) { this.embed.player.webtorrent().on('autoResolutionUpdate', () => this.loadWebTorrentResolutions()) this.embed.player.webtorrent().on('videoFileUpdate', () => this.loadWebTorrentResolutions()) + + this.loadWebTorrentResolutions() } else { this.embed.player.p2pMediaLoader().on('resolutionChange', () => this.loadP2PMediaLoaderResolutions()) + this.embed.player.p2pMediaLoader().on('resolutionsLoaded', () => this.loadP2PMediaLoaderResolutions()) } this.embed.player.on('volumechange', () => { @@ -179,6 +209,6 @@ export class PeerTubeEmbedApi { } private isWebtorrent () { - return this.embed.player.webtorrent + return !!this.embed.player.webtorrent } }