diff --git a/frontend/src/chat/chat.ts b/frontend/src/chat/chat.ts index 2389a4d..6b08ada 100644 --- a/frontend/src/chat/chat.ts +++ b/frontend/src/chat/chat.ts @@ -43,6 +43,14 @@ declare module "ft_state" { } } +class DivPrivate extends HTMLElement { + constructor() { + super(); + } +} + +customElements.define("div-private", DivPrivate); + export function getSocket(): Socket { if (window.__state.chatSock === undefined) window.__state.chatSock = io(window.location.host, { diff --git a/frontend/src/chat/chatHelperFunctions/inviteToPlayPong.ts b/frontend/src/chat/chatHelperFunctions/inviteToPlayPong.ts index a159323..3c140b0 100644 --- a/frontend/src/chat/chatHelperFunctions/inviteToPlayPong.ts +++ b/frontend/src/chat/chatHelperFunctions/inviteToPlayPong.ts @@ -13,6 +13,5 @@ import { addMessage } from './addMessage'; export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) { profil.SenderName = getUser()?.name ?? ''; if (profil.SenderName === profil.user) return; - addMessage(`You invited to play: ${profil.user}🏓`) senderSocket.emit('inviteGame', JSON.stringify(profil)); }; \ No newline at end of file diff --git a/frontend/src/routing.ts b/frontend/src/routing.ts index 4c9d3d4..b998314 100644 --- a/frontend/src/routing.ts +++ b/frontend/src/routing.ts @@ -235,7 +235,7 @@ if (!window.__state._routingHandler) { if (sameOrigin) { e.preventDefault(); - navigateTo(url.pathname); + navigateTo(`${url.pathname}${url.search}`); } }); diff --git a/openapi-template/modelGenericInterfaces.mustache b/openapi-template/modelGenericInterfaces.mustache index 68e5747..bcc3094 100644 --- a/openapi-template/modelGenericInterfaces.mustache +++ b/openapi-template/modelGenericInterfaces.mustache @@ -1,5 +1,5 @@ /** - * {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}} + * {{#lambda.indented_star_1}}{{{unedDescription}}}{{/lambda.indented_star_1}} * @export * @interface {{classname}} */ @@ -9,7 +9,7 @@ export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{/additionalPropertiesType}} {{#vars}} /** - * {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}} + * {{#lambda.indented_star_4}}{{{unedDescription}}}{{/lambda.indented_star_4}} * @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%> * @memberof {{classname}} {{#deprecated}} diff --git a/src/@shared/src/utils/index.ts b/src/@shared/src/utils/index.ts index 30648ba..e15ca1b 100644 --- a/src/@shared/src/utils/index.ts +++ b/src/@shared/src/utils/index.ts @@ -143,7 +143,7 @@ export function isNullish(v: T | undefined | null): v is null | undefined { return v === null || v === undefined; } -export function escape(s: string): string { +export function e(s: string): string { return s.replace( /[^0-9A-Za-z ]/g, c => '&#' + c.charCodeAt(0) + ';', diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index dff4530..964bf23 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -18,10 +18,9 @@ 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 { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener'; import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me'; -import type { ClientInfo, blockedUnBlocked } from './chat_types'; +import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types'; declare const __SERVICE_NAME: string; @@ -103,7 +102,7 @@ async function onReady(fastify: FastifyInstance) { broadcast(fastify, obj, obj.SenderWindowID); fastify.log.info(`Client connected: ${socket.id}`); }); - //nextGame_SocketListener(fastify, socket); + list_SocketListener(fastify, socket); socket.on('updateClientName', (object) => { @@ -217,13 +216,11 @@ 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); + const linkGame: Response | undefined = await setGameLink(fastify, data); if (!linkGame) return; - const tmp: any = await linkGame?.json(); - const link: string = `'Click me'`; - - console.log(link); - const inviteHtml: string = 'invites you to a game' + link; + const tmp: inviteUserTOGame = await linkGame?.json() as inviteUserTOGame; + const link: string = `Click me`; + const inviteHtml: string = 'invites you to a game ' + link; if (clientName !== null) { sendInvite(fastify, inviteHtml, profilInvite); } diff --git a/src/chat/src/chatBackHelperFunctions/makeProfil.ts b/src/chat/src/chatBackHelperFunctions/makeProfil.ts index 3fe3465..7a6301d 100644 --- a/src/chat/src/chatBackHelperFunctions/makeProfil.ts +++ b/src/chat/src/chatBackHelperFunctions/makeProfil.ts @@ -3,7 +3,7 @@ import type { ClientProfil } from '../chat_types'; import type { User } from '@shared/database/mixin/user'; import { getUserByName } from './getUserByName'; import { Socket } from 'socket.io'; -import { escape } from '@shared/utils'; +import { e } from '@shared/utils'; /** * function makeProfil - translates the Users[] to a one user looking by name @@ -32,7 +32,7 @@ export async function makeProfil(fastify: FastifyInstance, user: string, socket: user: `${allUsers.name}`, loginName: loginState, userID: `${allUsers?.id ?? ''}`, - text: escape(allUsers.desc), + text: e(allUsers.desc), timestamp: Date.now(), SenderWindowID: socket.id, SenderName: '', diff --git a/src/chat/src/chatBackHelperFunctions/sendInvite.ts b/src/chat/src/chatBackHelperFunctions/sendInvite.ts index d4ea121..5c1c183 100644 --- a/src/chat/src/chatBackHelperFunctions/sendInvite.ts +++ b/src/chat/src/chatBackHelperFunctions/sendInvite.ts @@ -26,7 +26,7 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr const sockets = await fastify.io.fetchSockets(); let targetSocket; for (const socket of sockets) { - const clientInfo: string = clientChat.get(socket.id)?.user || ''; + const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined; targetSocket = socket || null; if (!targetSocket) continue; if (clientInfo === profil.user) { @@ -36,12 +36,12 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr command: `@${clientInfo}`, destination: 'inviteMsg', type: 'chat', - user: profil.SenderName, + user: profil.user, token: '', text: getGameNumber(), timestamp: Date.now(), SenderWindowID: socket.id, - userID: '', + userID: profil.userID, frontendUserName: '', frontendUser: '', SenderUserName: profil.SenderName, diff --git a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts index 9fc1629..44f72aa 100644 --- a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts +++ b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts @@ -27,7 +27,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess for (const socket of sockets) { if (socket.id === sender) continue; - const UserID = getUserByName(allUsers, data.user)?.id ?? ''; + const UserID: string = getUserByName(allUsers, data.user as string)?.id as string ?? undefined; const list:BlockRelation[] = whoBlockedMe(fastify, UserID); const clientInfo = clientChat.get(socket.id); if (!clientInfo) continue; diff --git a/src/chat/src/chat_types.ts b/src/chat/src/chat_types.ts index 50e19f2..9a921b1 100644 --- a/src/chat/src/chat_types.ts +++ b/src/chat/src/chat_types.ts @@ -16,7 +16,6 @@ export type ClientMessage = { innerHtml?: string, }; - export type ClientProfil = { command: string, destination: string, @@ -35,7 +34,6 @@ export type ClientProfil = { }; - export interface ClientInfo { user: string; socket: string @@ -49,21 +47,11 @@ export type blockedUnBlocked = by: string, }; - -// export type obj = -// { -// command: string, -// destination: string, -// type: string, -// user: string, -// frontendUserName: string, -// frontendUser: string, -// token: string, -// text: string, -// timestamp: number, -// SenderWindowID: string, -// Sendertext: string, -// }; +export type inviteUserTOGame = { + user1: string, + user2: string, + gameId: string +} export type BlockRelation = { blocked: string; diff --git a/src/chat/src/createNextGame.ts b/src/chat/src/createNextGame.ts deleted file mode 100644 index 68c3071..0000000 --- a/src/chat/src/createNextGame.ts +++ /dev/null @@ -1,6 +0,0 @@ -// /** -// /* 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 deleted file mode 100644 index b496ffd..0000000 --- a/src/chat/src/nextGame_SocketListener.ts +++ /dev/null @@ -1,20 +0,0 @@ -// 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 diff --git a/src/chat/src/setGameLink.ts b/src/chat/src/setGameLink.ts index 796f72d..210bdee 100644 --- a/src/chat/src/setGameLink.ts +++ b/src/chat/src/setGameLink.ts @@ -1,33 +1,29 @@ import { FastifyInstance } from 'fastify'; +import type { ClientProfil } from './chat_types'; -export async function setGameLink(fastify: FastifyInstance): Promise { - +export async function setGameLink(fastify: FastifyInstance, data: string): 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); - } + const profilInvite: ClientProfil = JSON.parse(data) || ''; - else { fastify.log.info('game-end info to chat success'); - console.log("caht detect success :)"); - // console.log("chat gets:", await resp.json()); - } - return resp; + const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` }; + 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) { + throw (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}`); + else { + fastify.log.info('game-end info to chat success'); } - }; \ No newline at end of file + 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 510b591..efe0b40 100644 --- a/src/pong/src/routes/createPausedGame.ts +++ b/src/pong/src/routes/createPausedGame.ts @@ -31,13 +31,10 @@ const route: FastifyPluginAsync = async (fastify): Promise => { }, }, 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', {gameId: resp})); + return (res.makeResponse(200, 'success', 'createPausedGame.success', { gameId: resp })); }, ); }; diff --git a/src/pong/src/state.ts b/src/pong/src/state.ts index 5d94cb9..67cf8b7 100644 --- a/src/pong/src/state.ts +++ b/src/pong/src/state.ts @@ -223,12 +223,16 @@ class StateI { } public newPausedGame(suid1: string, suid2: string): GameId | undefined { +<<<<<<< HEAD if ( !this.users.has(suid1 as UserId) || !this.users.has(suid2 as UserId) ) { return undefined; } +======= + +>>>>>>> 78eb546 (Added U Game system) const uid1: UserId = suid1 as UserId; const uid2: UserId = suid2 as UserId; const g = new Pong(uid1, uid2);