This commit is contained in:
bgoulard 2026-01-09 11:14:16 +01:00 committed by Nigel
parent a65b8a9067
commit 8564088a3b
2 changed files with 26 additions and 25 deletions

View file

@ -1,6 +1,6 @@
import { FastifyPluginAsync } from 'fastify'; import { FastifyPluginAsync } from 'fastify';
import { Static, Type } from 'typebox'; import { Static, Type } from 'typebox';
import { broadcastNextGame} from '../broadcastNextGame'; import { broadcastNextGame } from '../broadcastNextGame';
export const ChatReq = Type.Object({ export const ChatReq = Type.Object({
message: Type.String(), message: Type.String(),
@ -28,22 +28,22 @@ export type ChatReq = Static<typeof ChatReq>;
const route: FastifyPluginAsync = async (fastify): Promise<void> => { const route: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.post('/api/chat/broadcast', { fastify.post('/api/chat/broadcast', {
schema: { schema: {
body: { body: {
type: 'object', type: 'object',
required: ['nextGame'], required: ['nextGame'],
properties: { properties: {
nextGame: { type: 'string' } nextGame: { type: 'string' },
} },
} },
} },
}, async (req, reply) => { }, async (req, reply) => {
const gameLink: Promise<string> = Promise.resolve(req.body as string ); const gameLink: Promise<string> = Promise.resolve(req.body as string);
if (gameLink) if (gameLink) {
broadcastNextGame(fastify, gameLink); broadcastNextGame(fastify, gameLink);
}
return reply.send({ status: 'ok' }); return reply.send({ status: 'ok' });
}); });
}; };
export default route; export default route;

View file

@ -205,19 +205,20 @@ class StateI {
this.fastify.db.setPongGameOutcome(gameId, { id: game.userLeft, score: game.score[0] }, { id: game.userRight, score: game.score[1] }, outcome, game.local); this.fastify.db.setPongGameOutcome(gameId, { id: game.userLeft, score: game.score[0] }, { id: game.userRight, score: game.score[1] }, outcome, game.local);
this.fastify.log.info('SetGameOutcome !'); this.fastify.log.info('SetGameOutcome !');
if (!game.local) { if (!game.local) {
let payload = {'nextGame':chat_text}; const payload = { 'nextGame':chat_text };
try { try {
const resp = await fetch("http://app-chat/api/chat/broadcast", { const resp = await fetch('http://app-chat/api/chat/broadcast', {
method:'POST', method:'POST',
headers:{'Content-type':'application/json'}, headers:{ 'Content-type':'application/json' },
body: JSON.stringify(payload), body: JSON.stringify(payload),
}); });
if (!resp.ok) if (!resp.ok) { throw (resp); }
throw(resp); else { this.fastify.log.info('game-end info to chat success'); }
else }
this.fastify.log.info("game-end info to chat success"); // disable eslint for err catching
} catch (e : any) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
catch (e : any) {
this.fastify.log.error(`game-end info to chat failed: ${e}`); this.fastify.log.error(`game-end info to chat failed: ${e}`);
} }
} }