Skip to content

Commit 8334b6a

Browse files
committed
Prototype of showing log messages coming from the phone
1 parent d9fa02c commit 8334b6a

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/components/Go.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import {getShortUUID, useProjectJobListener, useStartShipOnMount} from '@cli/uti
44
import {getJobBuildsRetry} from '@cli/api/index.js'
55

66
import {CommandContext, GameContext, JobProgress, QRCodeTerminal} from './index.js'
7-
import { Job, Platform } from '@cli/types/api.js'
7+
import {Job, Platform} from '@cli/types/api.js'
8+
import {useGoRuntimeLogListener} from '@cli/utils/hooks/useGoRuntimeLogListener.js'
89

910
interface Props {
1011
onComplete: () => void
1112
onError: (error: any) => void
1213
}
1314

14-
export const Go = ({onComplete, onError}: Props): JSX.Element| null => {
15+
export const Go = ({onComplete, onError}: Props): JSX.Element | null => {
1516
const {command} = useContext(CommandContext)
1617
const {gameId} = useContext(GameContext)
1718
if (!command || !gameId) return null
@@ -23,18 +24,27 @@ interface GoCommandProps extends Props {
2324
gameId: string
2425
}
2526

26-
const GoCommand = ({command, gameId, onComplete, onError}: GoCommandProps): JSX.Element | null=> {
27+
const LogListener = ({projectId, buildId}: {projectId: string; buildId: string}) => {
28+
useGoRuntimeLogListener({projectId, buildId})
29+
return null
30+
}
31+
32+
const GoCommand = ({command, gameId, onComplete, onError}: GoCommandProps): JSX.Element | null => {
2733
const flags = {follow: false, platform: 'go'}
2834

35+
const [buildId, setBuildId] = useState<string | null>(null)
36+
const [qrCodeData, setQRCodeData] = useState<string | null>(null)
37+
2938
const {jobs: startedJobs} = useStartShipOnMount(command, flags, onError)
3039

3140
const handleJobCompleted = async (job: Job) => {
3241
if (job.type != Platform.GO) return
3342
const [goBuild] = await getJobBuildsRetry(job.id, command.getGameId())
43+
setBuildId(goBuild.id)
3444
setQRCodeData(getShortUUID(goBuild.id))
3545
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
3646
await sleep(500)
37-
onComplete()
47+
//onComplete()
3848
}
3949

4050
const handleJobFailed = (job: any) => {
@@ -48,10 +58,13 @@ const GoCommand = ({command, gameId, onComplete, onError}: GoCommandProps): JSX.
4858
onJobFailed: handleJobFailed,
4959
})
5060

51-
const [qrCodeData, setQRCodeData] = useState<string | null>(null)
52-
53-
if (qrCodeData) {
54-
return <QRCodeTerminal data={qrCodeData} />
61+
if (qrCodeData && buildId) {
62+
return (
63+
<>
64+
<QRCodeTerminal data={qrCodeData} />
65+
<LogListener projectId={gameId} buildId={buildId} />
66+
</>
67+
)
5568
}
5669

5770
if (startedJobs && startedJobs?.length > 0) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {WebSocketListener, useWebSocket} from './useWebSocket.js'
2+
3+
export interface GoRuntimeLogListenerProps {
4+
projectId: string
5+
buildId: string
6+
}
7+
8+
export function useGoRuntimeLogListener({projectId, buildId}: GoRuntimeLogListenerProps) {
9+
const listener: WebSocketListener = {
10+
async eventHandler(pattern: string, rawLog: any) {
11+
console.log(`[Go Runtime Log] ${JSON.stringify(rawLog)}`)
12+
},
13+
getPattern: () => [`project.${projectId}:build.${buildId}:runtime-log`],
14+
}
15+
16+
useWebSocket([listener])
17+
}

0 commit comments

Comments
 (0)