Skip to content

Commit 39e970b

Browse files
chore: rename methods for posterity
1 parent f33a7d8 commit 39e970b

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

src/api/lichess/streaming.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ export const getLichessGameInfo = async (gameId: string) => {
6767

6868
export const streamLichessGame = async (
6969
gameId: string,
70-
onGameStart: (data: StreamedGame) => void,
70+
onGameInfo: (data: StreamedGame) => void,
7171
onMove: (data: StreamedMove) => void,
7272
onComplete: () => void,
7373
abortSignal?: AbortSignal,
7474
) => {
75-
console.log(`Starting stream for game ${gameId}`)
76-
7775
const stream = fetch(`https://lichess.org/api/stream/game/${gameId}`, {
7876
signal: abortSignal,
7977
headers: {
@@ -83,10 +81,8 @@ export const streamLichessGame = async (
8381

8482
const onMessage = (message: any) => {
8583
if (message.id) {
86-
console.log('Game start message:', message)
87-
onGameStart(message as StreamedGame)
84+
onGameInfo(message as StreamedGame)
8885
} else if (message.uci || message.lm) {
89-
console.log('Move message:', message)
9086
onMove({
9187
fen: message.fen,
9288
uci: message.uci || message.lm,

src/components/Home/LiveChessBoard.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const LiveChessBoard: React.FC = () => {
3737
const abortController = useRef<AbortController | null>(null)
3838

3939
const handleGameStart = useCallback((gameData: StreamedGame) => {
40-
console.log('Live board - Game started:', gameData)
4140
if (gameData.fen) {
4241
setCurrentFen(gameData.fen)
4342
}
@@ -51,15 +50,13 @@ export const LiveChessBoard: React.FC = () => {
5150
}, [])
5251

5352
const handleMove = useCallback((moveData: StreamedMove) => {
54-
console.log('Live board - New move:', moveData)
5553
if (moveData.fen) {
5654
setCurrentFen(moveData.fen)
5755
}
5856
}, [])
5957

6058
const handleStreamComplete = useCallback(() => {
6159
console.log('Live board - Stream completed')
62-
// Try to get a new live game
6360
fetchNewGame()
6461
}, [])
6562

@@ -83,7 +80,6 @@ export const LiveChessBoard: React.FC = () => {
8380
isLive: true,
8481
})
8582

86-
// Start streaming the new game
8783
streamLichessGame(
8884
tvGame.gameId,
8985
handleGameStart,

src/hooks/useLichessStreamController.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,11 @@ export const useLichessStreamController = (): LichessStreamController => {
8484
})
8585
}, [clearReconnectTimeout])
8686

87-
const handleGameStart = useCallback(
87+
const handleStreamedGameInfo = useCallback(
8888
(gameData: StreamedGame) => {
8989
setGame((prev) => {
90-
console.log('CHECKING FOR GAME END', prev?.id, gameData.id)
9190
// if the game is already loaded, this is a game termination message
9291
if (prev?.id === gameData.id) {
93-
console.log('GAME ENDED')
94-
9592
setStreamState((prev) => ({
9693
...prev,
9794
gameEnded: true,
@@ -123,8 +120,6 @@ export const useLichessStreamController = (): LichessStreamController => {
123120

124121
const handleMove = useCallback(
125122
(moveData: StreamedMove) => {
126-
console.log('HANDLE MOVE:', moveData)
127-
128123
streamMoves.current.push(moveData)
129124

130125
if (moveData.wc !== undefined && moveData.bc !== undefined) {
@@ -154,12 +149,6 @@ export const useLichessStreamController = (): LichessStreamController => {
154149
try {
155150
const newGame = parseLichessStreamMove(moveData, prev)
156151

157-
if (!newGame.loaded) {
158-
if (newGame.loadedFen === moveData.fen) {
159-
console.log('LOADED GAME')
160-
}
161-
}
162-
163152
return {
164153
...newGame,
165154
loaded: newGame.loaded
@@ -176,8 +165,6 @@ export const useLichessStreamController = (): LichessStreamController => {
176165
)
177166

178167
const handleStreamComplete = useCallback(() => {
179-
console.log('Stream completed')
180-
181168
setStreamState((prev) => ({
182169
...prev,
183170
isConnected: false,
@@ -207,16 +194,14 @@ export const useLichessStreamController = (): LichessStreamController => {
207194

208195
try {
209196
// Start streaming directly - the stream API will handle invalid game IDs
210-
// Note: isConnected will be set when we receive the first data (in handleGameStart or handleMove)
197+
// Note: isConnected will be set when we receive the first data (in handleStreamedGameInfo or handleMove)
211198
await streamLichessGame(
212199
gameId,
213-
handleGameStart,
200+
handleStreamedGameInfo,
214201
handleMove,
215202
handleStreamComplete,
216203
abortController.current.signal,
217204
)
218-
219-
console.log('Stream completed')
220205
} catch (error) {
221206
console.error('Stream error:', error)
222207

@@ -235,7 +220,7 @@ export const useLichessStreamController = (): LichessStreamController => {
235220
abortController.current = null
236221
}
237222
},
238-
[handleGameStart, handleMove, handleStreamComplete],
223+
[handleStreamedGameInfo, handleMove, handleStreamComplete],
239224
)
240225

241226
useEffect(() => {

0 commit comments

Comments
 (0)