aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/player/player.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/standalone/player/player.ts')
-rw-r--r--client/src/standalone/player/player.ts31
1 files changed, 18 insertions, 13 deletions
diff --git a/client/src/standalone/player/player.ts b/client/src/standalone/player/player.ts
index 9776fda12..bbe37a42b 100644
--- a/client/src/standalone/player/player.ts
+++ b/client/src/standalone/player/player.ts
@@ -17,7 +17,7 @@ const PASSTHROUGH_EVENTS = [
17 */ 17 */
18export class PeerTubePlayer { 18export class PeerTubePlayer {
19 19
20 private eventRegistrar: EventRegistrar = new EventRegistrar() 20 private readonly eventRegistrar: EventRegistrar = new EventRegistrar()
21 private channel: Channel.MessagingChannel 21 private channel: Channel.MessagingChannel
22 private readyPromise: Promise<void> 22 private readyPromise: Promise<void>
23 23
@@ -31,8 +31,8 @@ export class PeerTubePlayer {
31 * @param scope 31 * @param scope
32 */ 32 */
33 constructor ( 33 constructor (
34 private embedElement: HTMLIFrameElement, 34 private readonly embedElement: HTMLIFrameElement,
35 private scope?: string 35 private readonly scope?: string
36 ) { 36 ) {
37 this.eventRegistrar.registerTypes(PASSTHROUGH_EVENTS) 37 this.eventRegistrar.registerTypes(PASSTHROUGH_EVENTS)
38 38
@@ -90,6 +90,7 @@ export class PeerTubePlayer {
90 90
91 /** 91 /**
92 * Tell the embed to change the audio volume 92 * Tell the embed to change the audio volume
93 *
93 * @param value A number from 0 to 1 94 * @param value A number from 0 to 1
94 */ 95 */
95 async setVolume (value: number) { 96 async setVolume (value: number) {
@@ -98,14 +99,16 @@ export class PeerTubePlayer {
98 99
99 /** 100 /**
100 * Get the current volume level in the embed. 101 * Get the current volume level in the embed.
102 *
101 * @param value A number from 0 to 1 103 * @param value A number from 0 to 1
102 */ 104 */
103 async getVolume (): Promise<number> { 105 async getVolume (): Promise<number> {
104 return this.sendMessage<void, number>('getVolume') 106 return this.sendMessage<undefined, number>('getVolume')
105 } 107 }
106 108
107 /** 109 /**
108 * Tell the embed to change the current caption 110 * Tell the embed to change the current caption
111 *
109 * @param value Caption id 112 * @param value Caption id
110 */ 113 */
111 async setCaption (value: string) { 114 async setCaption (value: string) {
@@ -116,11 +119,12 @@ export class PeerTubePlayer {
116 * Get video captions 119 * Get video captions
117 */ 120 */
118 async getCaptions (): Promise<PeerTubeTextTrack[]> { 121 async getCaptions (): Promise<PeerTubeTextTrack[]> {
119 return this.sendMessage<void, PeerTubeTextTrack[]>('getCaptions') 122 return this.sendMessage<undefined, PeerTubeTextTrack[]>('getCaptions')
120 } 123 }
121 124
122 /** 125 /**
123 * Tell the embed to seek to a specific position (in seconds) 126 * Tell the embed to seek to a specific position (in seconds)
127 *
124 * @param seconds 128 * @param seconds
125 */ 129 */
126 async seek (seconds: number) { 130 async seek (seconds: number) {
@@ -143,21 +147,21 @@ export class PeerTubePlayer {
143 * resolutions change. 147 * resolutions change.
144 */ 148 */
145 async getResolutions (): Promise<PeerTubeResolution[]> { 149 async getResolutions (): Promise<PeerTubeResolution[]> {
146 return this.sendMessage<void, PeerTubeResolution[]>('getResolutions') 150 return this.sendMessage<undefined, PeerTubeResolution[]>('getResolutions')
147 } 151 }
148 152
149 /** 153 /**
150 * Retrieve a list of available playback rates. 154 * Retrieve a list of available playback rates.
151 */ 155 */
152 async getPlaybackRates (): Promise<number[]> { 156 async getPlaybackRates (): Promise<number[]> {
153 return this.sendMessage<void, number[]>('getPlaybackRates') 157 return this.sendMessage<undefined, number[]>('getPlaybackRates')
154 } 158 }
155 159
156 /** 160 /**
157 * Get the current playback rate. Defaults to 1 (1x playback rate). 161 * Get the current playback rate. Defaults to 1 (1x playback rate).
158 */ 162 */
159 async getPlaybackRate (): Promise<number> { 163 async getPlaybackRate (): Promise<number> {
160 return this.sendMessage<void, number>('getPlaybackRate') 164 return this.sendMessage<undefined, number>('getPlaybackRate')
161 } 165 }
162 166
163 /** 167 /**
@@ -188,7 +192,7 @@ export class PeerTubePlayer {
188 * Get video position currently played (starts from 1) 192 * Get video position currently played (starts from 1)
189 */ 193 */
190 async getCurrentPosition () { 194 async getCurrentPosition () {
191 return this.sendMessage<void, number>('getCurrentPosition') 195 return this.sendMessage<undefined, number>('getCurrentPosition')
192 } 196 }
193 197
194 private constructChannel () { 198 private constructChannel () {
@@ -201,8 +205,8 @@ export class PeerTubePlayer {
201 } 205 }
202 206
203 private prepareToBeReady () { 207 private prepareToBeReady () {
204 let readyResolve: Function 208 let readyResolve: () => void
205 let readyReject: Function 209 let readyReject: () => void
206 210
207 this.readyPromise = new Promise<void>((res, rej) => { 211 this.readyPromise = new Promise<void>((res, rej) => {
208 readyResolve = res 212 readyResolve = res
@@ -219,7 +223,8 @@ export class PeerTubePlayer {
219 private sendMessage<TIn, TOut> (method: string, params?: TIn): Promise<TOut> { 223 private sendMessage<TIn, TOut> (method: string, params?: TIn): Promise<TOut> {
220 return new Promise<TOut>((resolve, reject) => { 224 return new Promise<TOut>((resolve, reject) => {
221 this.channel.call({ 225 this.channel.call({
222 method, params, 226 method,
227 params,
223 success: result => resolve(result), 228 success: result => resolve(result),
224 error: error => reject(error) 229 error: error => reject(error)
225 }) 230 })
@@ -228,4 +233,4 @@ export class PeerTubePlayer {
228} 233}
229 234
230// put it on the window as well as the export 235// put it on the window as well as the export
231(window[ 'PeerTubePlayer' ] as any) = PeerTubePlayer 236(window['PeerTubePlayer'] as any) = PeerTubePlayer