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

feat: 雑に singleton で実装 #65

Open
wants to merge 9 commits into
base: feat/v0.6.0
Choose a base branch
from

Conversation

naporin0624
Copy link

No description provided.

@@ -21,6 +21,7 @@
"lucide-react": "^0.378.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"reconnecting-websocket": "^4.4.0",
Copy link
Author

Choose a reason for hiding this comment

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

websocket つなげるならこれ使うのがおすすめ

) => void
}
}

const headlessStreamDeck = new HeadlessStreamDeckImpl<unknown>()
Copy link
Author

Choose a reason for hiding this comment

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

StreamDeck と外部サーバーとやり取りする部分は connection を複数持てるようにすることで singleton で定義できるようにする

Comment on lines 57 to 97
useEffect(() => {
const open = () => {
console.log('Opened')
}
headlessStreamDeck.addEventListener('open', open)

if (payload?.event === 'inputs') {
const p: SendToPropertyInspector<SendInputs> = payload as SendToPropertyInspector<SendInputs>
console.log('inputs', p.payload.inputs)
setInputs(p.payload.inputs)
}
},
},
const didReceiveSettings = (s: unknown) => {
console.log('Settings received', s)
setSettings(s as T)
}
headlessStreamDeck.addEventListener(
'didReceiveGlobalSettings',
didReceiveSettings,
)

// TODO: 型をもっと扱いやすく厳密にする
// Actionごとにカスタムしたくなると思うので、もっと冗長性を持たせる
// 例えばSettings, コールバック関数を外部から設定できるようにして、StreamDeckとの接続のみを担うコンポーネントを切り出す
// actionInfo.action で描画先を変更するのではなく、もっと細かく分ける
))
const sendToPropertyInspector = (payload: unknown) => {
if (!payload) return
if (typeof payload !== 'object') return
if (!('event' in payload)) return

// TODO: Apply colours
// addDynamicStyles(inInfo.colors);
}
if (payload?.event === 'inputs') {
const p: SendToPropertyInspector<SendInputs>
= payload as SendToPropertyInspector<SendInputs>
console.log('inputs', p.payload.inputs)
setInputs(p.payload.inputs)
}
}

headlessStreamDeck.addEventListener(
'sendToPropertyInspector',
sendToPropertyInspector,
)

return () => {
headlessStreamDeck.removeEventListener('open', open)
headlessStreamDeck.removeEventListener(
'didReceiveGlobalSettings',
didReceiveSettings,
)
}
}, [])
Copy link
Author

Choose a reason for hiding this comment

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

singleton なので初期化タイミングと情報を読み取るタイミングを分けられる

Comment on lines 25 to 38
window.connectElgatoStreamDeckSocket = (
inPort,
inUUID,
inRegisterEvent,
inInfo,
inActionInfo,
) => {
headlessStreamDeck.add(inPort, {
inPropertyInspectorUUID: inUUID,
inRegisterEvent,
inInfo,
inActionInfo,
})
}
Copy link
Author

@naporin0624 naporin0624 Sep 23, 2024

Choose a reason for hiding this comment

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

App.tsx が読み込まれたタイミングで初期化

やってないけど(多分 vite だったら難読化, global 変数の minify は勝手にされないので)
window.connectElgatoStreamDeckSocket だけ切り出して、そのファイルだけ難読化しないという手が使える.....と思う

Comment on lines 45 to 55
const actionInfos = useSyncExternalStore(
useCallback((onStoreChange) => {
onStoreChange()
headlessStreamDeck.addEventListener('open', onStoreChange)
return () => {
headlessStreamDeck.removeEventListener('open', onStoreChange)
}
}, []),
useCallback(() => headlessStreamDeck.getInfos(), []),
() => [],
)
Copy link
Author

Choose a reason for hiding this comment

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

StreamDeck class を触接触っても connection 情報が得られないので open イベントごとに actionInfo をリストで取り直す

import { Connection, ConnectParameters, HeadlessStreamDeck, StreamDeckEventMap } from './types'
import ReconnectingWebSocket from 'reconnecting-websocket'

export class HeadlessStreamDeckImpl<T> implements HeadlessStreamDeck<T> {
Copy link
Author

Choose a reason for hiding this comment

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

コネクションをため込んでまとめてイベント publish したり受け取ったりするクラス。

@FlowingSPDG
Copy link
Owner

@naporin0624 アザス!!!!!!!
すんごい、多忙で見れてない間にもcommitが増えている 𝐿𝑂𝑉𝐸です❣️

来週中に確認します!かならず!!!!!!!

@naporin0624
Copy link
Author

@naporin0624 アザス!!!!!!! すんごい、多忙で見れてない間にもcommitが増えている 𝐿𝑂𝑉𝐸です❣️

来週中に確認します!かならず!!!!!!!

@FlowingSPDG 全然大丈夫!完璧にしたくてやってるだけ!実機持ってないから動作確認はできないので test で担保してるけど動かなくなってたらごめん

setSettings(s as T)
}
headlessStreamDeck.addEventListener(
'didReceiveGlobalSettings',
Copy link
Author

Choose a reason for hiding this comment

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

ミスってるがもう一方のプルリクで直してある

Copy link
Author

Choose a reason for hiding this comment

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

headlessStreamDeck.addEventListener('didReceiveSettings', handler)

Source/pi/src/sd/headless.ts Outdated Show resolved Hide resolved
@FlowingSPDG
Copy link
Owner

@naporin0624 めちゃくちゃ放置して申し訳ない~~!!!
これ動作チェックして問題なかったらマージしようと思うんすけど、 #66 をテストして #65, #66 の順番でマージすればおっけです🤔 ?

@naporin0624
Copy link
Author

@naporin0624 めちゃくちゃ放置して申し訳ない~~!!!

これ動作チェックして問題なかったらマージしようと思うんすけど、 #66 をテストして #65, #66 の順番でマージすればおっけです🤔 ?

@FlowingSPDG そうす!

@FlowingSPDG
Copy link
Owner

@naporin0624 あざすあざす!!
元ブランチが作業中で放置してたっぽくて(俺が悪い)、バックエンド側でエラーが出てるのでエラーを撲滅し次第テストをします! 👊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants