Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #25

Merged
merged 1 commit into from
Mar 8, 2023
Merged

fix #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix
  • Loading branch information
mark committed Mar 8, 2023
commit 2483fdb95b9294c16755c0a94253bca4bcd19646
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