diff options
Diffstat (limited to 'client/src/standalone/videos/embed-api.ts')
-rw-r--r-- | client/src/standalone/videos/embed-api.ts | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index 61e5d0b9a..a9263555d 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import './embed.scss' | 1 | import './embed.scss' |
2 | 2 | ||
3 | import * as Channel from 'jschannel' | 3 | import * as Channel from 'jschannel' |
4 | import { PeerTubeResolution } from '../player/definitions' | 4 | import { PeerTubeResolution, PeerTubeTextTrack } from '../player/definitions' |
5 | import { PeerTubeEmbed } from './embed' | 5 | import { PeerTubeEmbed } from './embed' |
6 | 6 | ||
7 | /** | 7 | /** |
@@ -44,6 +44,9 @@ export class PeerTubeEmbedApi { | |||
44 | channel.bind('setResolution', (txn, resolutionId) => this.setResolution(resolutionId)) | 44 | channel.bind('setResolution', (txn, resolutionId) => this.setResolution(resolutionId)) |
45 | channel.bind('getResolutions', (txn, params) => this.resolutions) | 45 | channel.bind('getResolutions', (txn, params) => this.resolutions) |
46 | 46 | ||
47 | channel.bind('getCaptions', (txn, params) => this.getCaptions()) | ||
48 | channel.bind('setCaption', (txn, id) => this.setCaption(id)), | ||
49 | |||
47 | channel.bind('setPlaybackRate', (txn, playbackRate) => this.embed.player.playbackRate(playbackRate)) | 50 | channel.bind('setPlaybackRate', (txn, playbackRate) => this.embed.player.playbackRate(playbackRate)) |
48 | channel.bind('getPlaybackRate', (txn, params) => this.embed.player.playbackRate()) | 51 | channel.bind('getPlaybackRate', (txn, params) => this.embed.player.playbackRate()) |
49 | channel.bind('getPlaybackRates', (txn, params) => this.embed.player.options_.playbackRates) | 52 | channel.bind('getPlaybackRates', (txn, params) => this.embed.player.options_.playbackRates) |
@@ -71,6 +74,26 @@ export class PeerTubeEmbedApi { | |||
71 | this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId | 74 | this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId |
72 | } | 75 | } |
73 | 76 | ||
77 | private getCaptions (): PeerTubeTextTrack[] { | ||
78 | return this.embed.player.textTracks().tracks_.map(t => { | ||
79 | return { | ||
80 | id: t.id, | ||
81 | src: t.src, | ||
82 | label: t.label, | ||
83 | mode: t.mode as any | ||
84 | } | ||
85 | }) | ||
86 | } | ||
87 | |||
88 | private setCaption (id: string) { | ||
89 | const tracks = this.embed.player.textTracks().tracks_ | ||
90 | |||
91 | for (const track of tracks) { | ||
92 | if (track.id === id) track.mode = 'showing' | ||
93 | else track.mode = 'disabled' | ||
94 | } | ||
95 | } | ||
96 | |||
74 | /** | 97 | /** |
75 | * Let the host know that we're ready to go! | 98 | * Let the host know that we're ready to go! |
76 | */ | 99 | */ |
@@ -80,17 +103,19 @@ export class PeerTubeEmbedApi { | |||
80 | } | 103 | } |
81 | 104 | ||
82 | private setupStateTracking () { | 105 | private setupStateTracking () { |
83 | let currentState: 'playing' | 'paused' | 'unstarted' = 'unstarted' | 106 | let currentState: 'playing' | 'paused' | 'unstarted' | 'ended' = 'unstarted' |
84 | 107 | ||
85 | setInterval(() => { | 108 | setInterval(() => { |
86 | const position = this.element.currentTime | 109 | const position = this.element.currentTime |
87 | const volume = this.element.volume | 110 | const volume = this.element.volume |
111 | const duration = this.element.duration | ||
88 | 112 | ||
89 | this.channel.notify({ | 113 | this.channel.notify({ |
90 | method: 'playbackStatusUpdate', | 114 | method: 'playbackStatusUpdate', |
91 | params: { | 115 | params: { |
92 | position, | 116 | position, |
93 | volume, | 117 | volume, |
118 | duration: this.embed.player.duration(), | ||
94 | playbackState: currentState | 119 | playbackState: currentState |
95 | } | 120 | } |
96 | }) | 121 | }) |
@@ -106,6 +131,11 @@ export class PeerTubeEmbedApi { | |||
106 | this.channel.notify({ method: 'playbackStatusChange', params: 'paused' }) | 131 | this.channel.notify({ method: 'playbackStatusChange', params: 'paused' }) |
107 | }) | 132 | }) |
108 | 133 | ||
134 | this.element.addEventListener('ended', ev => { | ||
135 | currentState = 'ended' | ||
136 | this.channel.notify({ method: 'playbackStatusChange', params: 'ended' }) | ||
137 | }) | ||
138 | |||
109 | // PeerTube specific capabilities | 139 | // PeerTube specific capabilities |
110 | 140 | ||
111 | if (this.isWebtorrent()) { | 141 | if (this.isWebtorrent()) { |