]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/standalone/videos/embed.ts
Handle playlist methods in embed api
[github/Chocobozzz/PeerTube.git] / client / src / standalone / videos / embed.ts
index 7372c80c6757fe901835d00d953c7c6f270cc4ca..a7fb087b19995a51fad3ff57983302cfa638d93f 100644 (file)
@@ -211,6 +211,36 @@ export class PeerTubeEmbed {
     return params.has(name) ? params.get(name) : defaultValue
   }
 
+  async playNextVideo () {
+    const next = this.getNextPlaylistElement()
+    if (!next) {
+      console.log('Next element not found in playlist.')
+      return
+    }
+
+    this.currentPlaylistElement = next
+
+    return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
+  }
+
+  async playPreviousVideo () {
+    const previous = this.getPreviousPlaylistElement()
+    if (!previous) {
+      console.log('Previous element not found in playlist.')
+      return
+    }
+
+    this.currentPlaylistElement = previous
+
+    await this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
+  }
+
+  getCurrentPosition () {
+    if (!this.currentPlaylistElement) return -1
+
+    return this.currentPlaylistElement.position
+  }
+
   async init () {
     try {
       this.userTokens = Tokens.load()
@@ -342,30 +372,6 @@ export class PeerTubeEmbed {
     })
   }
 
-  private async playNextVideo () {
-    const next = this.getNextPlaylistElement()
-    if (!next) {
-      console.log('Next element not found in playlist.')
-      return
-    }
-
-    this.currentPlaylistElement = next
-
-    return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
-  }
-
-  private async playPreviousVideo () {
-    const previous = this.getPreviousPlaylistElement()
-    if (!previous) {
-      console.log('Previous element not found in playlist.')
-      return
-    }
-
-    this.currentPlaylistElement = previous
-
-    return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
-  }
-
   private async loadVideoAndBuildPlayer (uuid: string) {
     const res = await this.loadVideo(uuid)
     if (res === undefined) return