Skip to content

Commit

Permalink
Merge pull request #25 from markolofsen/dev
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
markolofsen authored Mar 8, 2023
2 parents c1768f5 + 2483fdb commit cdb63ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Player/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlayerConfigProps } from 'pixel-streaming'
const defaultConfig: PlayerConfigProps = {
debugMode: 'on',
showToolbar: true,
psHost: '',
psHost: 'ws://127.0.0.1:80',
psConfig: {
// https://metaeditor.io/docs/metaeditor/settings/player
autoPlay: false,
Expand Down
31 changes: 24 additions & 7 deletions src/pages/player.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import { useRouter } from 'next/router'

// libs
import { PlayerConfigProps } from 'pixel-streaming'
Expand All @@ -9,26 +10,42 @@ import defaultConfig from 'src/components/Player/defaultConfig'

export default function Page() {

const router = useRouter()

// states
const [mounted, setMounted] = React.useState(false)
const [config, setConfig] = React.useState<PlayerConfigProps>(defaultConfig)

const applyConfig = (cfg: object) => {
const mergedConfig: PlayerConfigProps = {
...defaultConfig,
...cfg,
}

// alert(JSON.stringify(mergedConfig, null, 2))
setConfig(mergedConfig)
}

React.useEffect(() => {
if (!router.isReady) return

let cfg = localStorage.getItem('playerConfig')
if (cfg) {
const jsonConfig = JSON.parse(cfg)
applyConfig(jsonConfig)

const mergedConfig: PlayerConfigProps = {
...defaultConfig,
...jsonConfig,
} else {
const psHost = router.query.ss
if (psHost) {
applyConfig({
psHost,
})
}

// alert(JSON.stringify(mergedConfig, null, 2))
setConfig(mergedConfig)
}

setMounted(true)

}, [])
}, [router.isReady])

// return (
// <div>
Expand Down

1 comment on commit cdb63ed

@vercel
Copy link

@vercel vercel bot commented on cdb63ed Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.