From 96aae68cc47b7ac9b9400d5b5cf95acdf9fe38da Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Apr 2020 14:39:31 +0200 Subject: [PATCH] Add "ended" embed API event --- client/src/standalone/player/package.json | 2 +- client/src/standalone/videos/embed-api.ts | 7 ++++++- support/doc/api/embeds.md | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/src/standalone/player/package.json b/client/src/standalone/player/package.json index 591c3ee3d..ba36b8ad3 100644 --- a/client/src/standalone/player/package.json +++ b/client/src/standalone/player/package.json @@ -1,7 +1,7 @@ { "name": "@peertube/embed-api", "private": false, - "version": "0.0.1", + "version": "0.0.3", "description": "API to communicate with the PeerTube player embed", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts index 61e5d0b9a..c5fbe07fa 100644 --- a/client/src/standalone/videos/embed-api.ts +++ b/client/src/standalone/videos/embed-api.ts @@ -80,7 +80,7 @@ export class PeerTubeEmbedApi { } private setupStateTracking () { - let currentState: 'playing' | 'paused' | 'unstarted' = 'unstarted' + let currentState: 'playing' | 'paused' | 'unstarted' | 'ended' = 'unstarted' setInterval(() => { const position = this.element.currentTime @@ -106,6 +106,11 @@ export class PeerTubeEmbedApi { this.channel.notify({ method: 'playbackStatusChange', params: 'paused' }) }) + this.element.addEventListener('ended', ev => { + currentState = 'ended' + this.channel.notify({ method: 'playbackStatusChange', params: 'ended' }) + }) + // PeerTube specific capabilities if (this.isWebtorrent()) { diff --git a/support/doc/api/embeds.md b/support/doc/api/embeds.md index b1791ea13..a4236c521 100644 --- a/support/doc/api/embeds.md +++ b/support/doc/api/embeds.md @@ -123,7 +123,8 @@ Fired every half second to provide the current status of playback. The parameter } ``` -The `volume` field contains the volume from `0` (silent) to `1` (full volume). The `playbackState` can be `playing` or `paused`. More states may be added later. +The `volume` field contains the volume from `0` (silent) to `1` (full volume). +The `playbackState` can be `unstarted`, `playing`, `paused` or `ended`. More states may be added later. ## Event `playbackStatusChange`