diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts
index 16849c6..dff4530 100644
--- a/src/chat/src/app.ts
+++ b/src/chat/src/app.ts
@@ -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 = `'Click me'`;
- 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);
}
diff --git a/src/chat/src/createNextGame.ts b/src/chat/src/createNextGame.ts
index c8c1115..68c3071 100644
--- a/src/chat/src/createNextGame.ts
+++ b/src/chat/src/createNextGame.ts
@@ -1,6 +1,6 @@
-/**
-/* TODO find the description info for profil / or profil game link and return
-**/
-export function createNextGame() {
- return 'The next Game is Starting click here to watch';
-};
+// /**
+// /* TODO find the description info for profil / or profil game link and return
+// **/
+// export function createNextGame() {
+// return 'The next Game is Starting click here to watch';
+// };
diff --git a/src/chat/src/nextGame_SocketListener.ts b/src/chat/src/nextGame_SocketListener.ts
index 90bc470..b496ffd 100644
--- a/src/chat/src/nextGame_SocketListener.ts
+++ b/src/chat/src/nextGame_SocketListener.ts
@@ -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 = sendGameLinkToChatService(link);
- broadcastNextGame(fastify, game);
- });
-}
\ No newline at end of file
+// /**
+// * 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 = sendGameLinkToChatService(link);
+// broadcastNextGame(fastify, game);
+// });
+// }
\ No newline at end of file
diff --git a/src/chat/src/setGameLink.ts b/src/chat/src/setGameLink.ts
index 3401655..796f72d 100644
--- a/src/chat/src/setGameLink.ts
+++ b/src/chat/src/setGameLink.ts
@@ -1,6 +1,33 @@
-export function setGameLink(link: string): string {
- if (!link) {
- link = 'Click me';
- }
- return link;
-};
\ No newline at end of file
+import { FastifyInstance } from 'fastify';
+
+
+export async function setGameLink(fastify: FastifyInstance): Promise {
+
+
+ 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}`);
+ }
+ };
\ No newline at end of file
diff --git a/src/pong/src/routes/createPausedGame.ts b/src/pong/src/routes/createPausedGame.ts
index 9b89258..510b591 100644
--- a/src/pong/src/routes/createPausedGame.ts
+++ b/src/pong/src/routes/createPausedGame.ts
@@ -22,20 +22,22 @@ type CreatePausedGameResponse = MakeStaticResponse => {
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}));
},
);
};