Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #54 from stroeer/fix/BB-2137-fix-inactive-tabs-err…
Browse files Browse the repository at this point in the history
…or-endcard

only have one interval and clear it when ticker is 0
  • Loading branch information
evaschmuhl authored Aug 31, 2022
2 parents d5331c6 + c3f63e7 commit b5ca8d1
Show file tree
Hide file tree
Showing 5 changed files with 1,688 additions and 1,627 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.1",
"version": "2.0.2",
"name": "@stroeer/stroeer-videoplayer-plugin-endcard",
"description": "Ströer Videoplayer Endcard Plugin",
"main": "dist/stroeerVideoplayer-endcard-plugin.umd.js",
Expand Down
14 changes: 10 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,28 @@ class EndcardPlugin {
'[data-role="plugin-endcard-progress-value"]'
)! as HTMLElement
let remainingTime = this.revolverplayTime

const revolverplayTicker = (): void => {
ticker(this.revolverplayTime, remainingTime, progressSvgCircle, () => {
ticker(this.revolverplayTime, remainingTime, progressSvgCircle)
remainingTime--
if (remainingTime < 0) {
this.clearRevolverplayTimer()
this.play(0, true)
this.dispatchEvent('plugin-endcard:revolverplay')
this.onRevolverplayCallback()
})
remainingTime--
}
}

revolverplayTicker()
this.intervalTicker = setInterval(revolverplayTicker, 1000)
if (this.intervalTicker === null) {
this.intervalTicker = setInterval(revolverplayTicker, 1000)
}
}

clearRevolverplayTimer = (): void => {
if (this.intervalTicker !== null) {
clearInterval(this.intervalTicker)
this.intervalTicker = null
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/revolverplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ const updateCircleStyle = (el: HTMLElement, value: number): void => {
el.style.strokeDashoffset = String(value)
}

const ticker = (time: number, remainingTime: number, el: HTMLElement, cb: Function): void => {
const ticker = (time: number, remainingTime: number, el: HTMLElement): void => {
const value = ((time - remainingTime) / time) * 100

updateCircleStyle(el, getCircleProgress(value))
if (remainingTime < 0) {
cb()
}
}

export {
Expand Down
9 changes: 3 additions & 6 deletions tests/revolverplay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import { ticker } from '../src/revolverplay'

test('ticker should work correctly', () => {
const line = document.createElement('line')
const func1 = jest.fn()

ticker(7, 2, line, func1)
ticker(7, 2, line)
expect(line.style.strokeDashoffset).toEqual('55.053269661507535')
expect(func1).not.toHaveBeenCalled()

ticker(5, -1, line, func1)
ticker(5, -1, line)
expect(line.style.strokeDashoffset).toEqual('-38.53728876305527')
expect(func1).toHaveBeenCalled()
})
})
Loading

0 comments on commit b5ca8d1

Please sign in to comment.