-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use socket.io for Temporal -> Svelte updates.
- Loading branch information
1 parent
ef880cd
commit 92869ae
Showing
5 changed files
with
100 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
import { Snake, Round } from './workflows'; | ||
import { request, Agent } from 'undici'; | ||
import { io } from 'socket.io-client'; | ||
|
||
const agent = new Agent({ | ||
keepAliveTimeout: 10, | ||
keepAliveMaxTimeout: 10 | ||
}); | ||
const socket = io('http://localhost:5173'); | ||
|
||
export async function snakeWork(durationMs: number) { | ||
// sleep for duration | ||
await new Promise((resolve) => setTimeout(resolve, durationMs)); | ||
} | ||
|
||
export async function snakeMovedNotification(snake: Snake) { | ||
await request(`http://localhost:5173/api/signal`, { | ||
dispatcher: agent, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
action: 'snakeMoved', | ||
snake: snake, | ||
}) | ||
}); | ||
socket.emit('snakeMoved', snake); | ||
} | ||
|
||
export async function roundUpdateNotification(round: Round) { | ||
await request(`http://localhost:5173/api/game`, { | ||
dispatcher: agent, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
action: 'roundUpdate', | ||
round: { ...round, stale: undefined }, | ||
}) | ||
}); | ||
socket.emit('roundUpdate', { ...round, stale: undefined }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters