Skip to content

Commit

Permalink
Unify player params
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciofierrom committed Dec 3, 2024
1 parent e5a86b2 commit d100372
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions app/javascript/controllers/player_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,24 @@ export default class extends Controller {
debug("env", window.rails_env)
switch(window.rails_env) {
case Env.Prod:
return YoutubePlayer.create(this.#mkYTPlayerParams())
return YoutubePlayer.create(this.#mkPlayerParams())
case Env.Dev:
if(window.is_cypress === "true") {
return DummyPlayer.create(this.#mkDummyParams())
return DummyPlayer.create(this.#mkPlayerParams())
} else {
return YoutubePlayer.create(this.#mkYTPlayerParams())
return YoutubePlayer.create(this.#mkPlayerParams())
}
case Env.Test:
return DummyPlayer.create(this.#mkDummyParams())
return DummyPlayer.create(this.#mkPlayerParams())
default:
return DummyPlayer.create(this.#mkDummyParams())
return DummyPlayer.create(this.#mkPlayerParams())
}
}

/*
* The paramateres to initialize the Youtube Player
*/
#mkYTPlayerParams() {
#mkPlayerParams() {
return {
videoId: this.videoIdValue,
edit: this.editValue,
Expand All @@ -280,25 +280,6 @@ export default class extends Controller {
}
}

/*
* The parameters to initialize the Dummy Player
*/
#mkDummyParams() {
return {
currentTime: 0,
duration: 500,
onPlaying: () => {
this.dispatch("videoLoaded")
if(this.hasDurationTarget) {
this.durationTarget.value = parseFloat(this.player.duration)
}
},
onLoadError: () => {
this.dispatch("videoLoadFailed")
},
}
}

/*
* Check if an URL path matches the section edit route
*
Expand Down

0 comments on commit d100372

Please sign in to comment.