Skip to content

Commit

Permalink
fix playlist for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Jan 14, 2025
1 parent 6c8e446 commit 433bd9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/pages/Scenes/ScenesPlaylist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export default function ScenesPlaylist({
: scenePLintervals[scenePLactiveIndex] || 2) * 1000,
scenePL,
scenePLactiveIndex,
scenePLrepeat
scenePLrepeat,
url: window.localStorage.getItem('ledfx-host')
})
} else {
workerRef.current.postMessage({ action: 'stop' })
Expand Down
21 changes: 13 additions & 8 deletions src/workers/timerWorker.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable no-restricted-globals */

import { Ledfx } from '../api/ledfx'

interface WorkerMessage {
interface WorkerMessageTimer {
action: 'start' | 'stop'
interval: number
scenePL: string[]
scenePLactiveIndex: number
scenePLrepeat: boolean
url: string
}

let timer: ReturnType<typeof setInterval> | null = null

self.onmessage = async function (e: MessageEvent<WorkerMessage>) {
const { action, interval, scenePL, scenePLactiveIndex, scenePLrepeat } =
self.onmessage = async function (e: MessageEvent<WorkerMessageTimer>) {
const { action, interval, scenePL, scenePLactiveIndex, scenePLrepeat, url } =
e.data

if (action === 'start') {
Expand All @@ -31,9 +30,15 @@ self.onmessage = async function (e: MessageEvent<WorkerMessage>) {

const nextSceneId = scenePL[nextIndex]
try {
await Ledfx('/api/scenes', 'PUT', {
id: nextSceneId,
action: 'activate'
await fetch(url + '/api/scenes', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: nextSceneId,
action: 'activate'
})
})
self.postMessage({ action: 'sceneChanged', nextIndex })
} catch (error) {
Expand Down

0 comments on commit 433bd9d

Please sign in to comment.