Add "ended" embed API event
authorChocobozzz <me@florianbigard.com>
Wed, 8 Apr 2020 12:39:31 +0000 (14:39 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 8 Apr 2020 12:39:31 +0000 (14:39 +0200)
client/src/standalone/player/package.json
client/src/standalone/videos/embed-api.ts
support/doc/api/embeds.md

index 591c3ee3d9fdd094cbb60fefae051d3ef08094b8..ba36b8ad3c231f82d108655a1a84623b766d6df1 100644 (file)
@@ -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"
index 61e5d0b9a696f4fdad3994236ce9b83bab11b029..c5fbe07fa56c851cf60f01fdb9380ed66affe460 100644 (file)
@@ -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()) {
index b1791ea136d96cd8da49c52ff7dc088114de681e..a4236c521b90df2f2f5d977e235bc174b3b99014 100644 (file)
@@ -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`