WIP game link hard coded for the moment

This commit is contained in:
NigeParis 2026-01-11 18:16:28 +01:00
parent 6a55b28c2a
commit 62705c4a7e
5 changed files with 71 additions and 37 deletions

View file

@ -18,7 +18,7 @@ import { makeProfil } from './chatBackHelperFunctions/makeProfil';
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
import { sendProfil } from './chatBackHelperFunctions/sendProfil';
import { setGameLink } from './setGameLink';
import { nextGame_SocketListener } from './nextGame_SocketListener';
//import { nextGame_SocketListener } from './nextGame_SocketListener';
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me';
import type { ClientInfo, blockedUnBlocked } from './chat_types';
@ -103,7 +103,7 @@ async function onReady(fastify: FastifyInstance) {
broadcast(fastify, obj, obj.SenderWindowID);
fastify.log.info(`Client connected: ${socket.id}`);
});
nextGame_SocketListener(fastify, socket);
//nextGame_SocketListener(fastify, socket);
list_SocketListener(fastify, socket);
socket.on('updateClientName', (object) => {
@ -217,8 +217,13 @@ async function onReady(fastify: FastifyInstance) {
socket.on('inviteGame', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || '';
const profilInvite: ClientProfil = JSON.parse(data) || '';
const linkGame: Response | undefined = await setGameLink(fastify);
if (!linkGame) return;
const tmp: any = await linkGame?.json();
const link: string = `'<a href=\'https://localhost:8888/pong?game=${tmp.payload.gameId}\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>Click me</a>'`;
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
console.log(link);
const inviteHtml: string = 'invites you to a game' + link;
if (clientName !== null) {
sendInvite(fastify, inviteHtml, profilInvite);
}

View file

@ -1,6 +1,6 @@
/**
/* TODO find the description info for profil / or profil game link and return
**/
export function createNextGame() {
return '<a href=\'https://localhost:8888/app/\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>The next Game is Starting click here to watch</a>';
};
// /**
// /* TODO find the description info for profil / or profil game link and return
// **/
// export function createNextGame() {
// return '<a href=\'https://localhost:8888/app/\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>The next Game is Starting click here to watch</a>';
// };

View file

@ -1,20 +1,20 @@
import type { FastifyInstance } from 'fastify';
import { broadcastNextGame } from './broadcastNextGame';
import { Socket } from 'socket.io';
import { createNextGame } from './createNextGame';
import { sendGameLinkToChatService } from './sendGameLinkToChatService';
// import type { FastifyInstance } from 'fastify';
// import { broadcastNextGame } from './broadcastNextGame';
// import { Socket } from 'socket.io';
// import { createNextGame } from './createNextGame';
// import { sendGameLinkToChatService } from './sendGameLinkToChatService';
/**
* function listens to the socket for a nextGame emit
* once triggered it broadcasts the pop up
* TODO plug this into backend of the game Chat
* @param fastify
* @param socket
*/
export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
socket.on('nextGame', () => {
const link: string = createNextGame();
const game: Promise<string> = sendGameLinkToChatService(link);
broadcastNextGame(fastify, game);
});
}
// /**
// * function listens to the socket for a nextGame emit
// * once triggered it broadcasts the pop up
// * TODO plug this into backend of the game Chat
// * @param fastify
// * @param socket
// */
// export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
// socket.on('nextGame', () => {
// const link: string = createNextGame();
// const game: Promise<string> = sendGameLinkToChatService(link);
// broadcastNextGame(fastify, game);
// });
// }

View file

@ -1,6 +1,33 @@
export function setGameLink(link: string): string {
if (!link) {
link = '<a href=\'https://google.com\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>Click me</a>';
import { FastifyInstance } from 'fastify';
export async function setGameLink(fastify: FastifyInstance): Promise<Response | undefined> {
let payload = {"user1":"019bad60-1e4a-7e28-af95-a8a88146107a", "user2":"019bad56-6468-748d-827e-110eb6aa4514"};
try {
const resp = await fetch('http://app-pong/api/pong/createPausedGame', {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify(payload),
});
if (!resp.ok) {
console.log("chat detect fail :( ", resp.status);
throw (resp);
}
else { fastify.log.info('game-end info to chat success');
console.log("caht detect success :)");
// console.log("chat gets:", await resp.json());
}
return resp;
}
// disable eslint for err catching
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch (e: any) {
fastify.log.error(`game-end info to chat failed: ${e}`);
}
return link;
};

View file

@ -22,20 +22,22 @@ type CreatePausedGameResponse = MakeStaticResponse<typeof CreatePausedGameRespon
const route: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.post<{ Body: CreatePausedGameParam }>(
'/createPausedGame',
'/api/pong/createPausedGame',
{
schema: {
body: CreatePausedGameParam,
response: CreatePausedGameResponse,
operationId: 'pongCreatePauseGame',
operationId: 'createPauseGame',
},
},
async function(req, res) {
console.log('herererererererererer');
const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId);
console.log('resp - game id: ',resp );
if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); }
// else
return (res.makeResponse(200, 'success', 'createPausedGame.success'));
return (res.makeResponse(200, 'success', 'createPausedGame.success', {gameId: resp}));
},
);
};