This commit is contained in:
NigeParis 2025-12-30 14:32:34 +01:00 committed by Maix0
parent 581a2330de
commit 1ca84b30c6
12 changed files with 47 additions and 192 deletions

View file

@ -1,13 +0,0 @@
import { clearChatWindow } from './clearChatWindow';
import { Socket } from 'socket.io-client';
import type { ClientProfil } from './types_front';
export function actionBtnPopUpClear(profil: ClientProfil, senderSocket: Socket) {
setTimeout(() => {
const clearTextBtn = document.querySelector("#popup-b-clear");
clearTextBtn?.addEventListener("click", () => {
clearChatWindow(senderSocket);
});
}, 0)
};

View file

@ -12,7 +12,6 @@ import { broadcastMsg } from './broadcastMsg';
import { isLoggedIn } from './isLoggedIn'; import { isLoggedIn } from './isLoggedIn';
import type { ClientMessage, ClientProfil } from './types_front'; import type { ClientMessage, ClientProfil } from './types_front';
import { openProfilePopup } from './openProfilePopup'; import { openProfilePopup } from './openProfilePopup';
import { actionBtnPopUpClear } from './actionBtnPopUpClear';
import { actionBtnPopUpBlock } from './actionBtnPopUpBlock'; import { actionBtnPopUpBlock } from './actionBtnPopUpBlock';
import { windowStateHidden } from './windowStateHidden'; import { windowStateHidden } from './windowStateHidden';
@ -167,8 +166,8 @@ function quitChat (socket: Socket) {
if (socket) { if (socket) {
logout(socket); logout(socket);
setTitle('Chat Page'); setTitle('Chat Page');
systemWindow.innerHTML = ""; // systemWindow.innerHTML = "";
chatWindow.textContent = ""; // chatWindow.textContent = "";
connected(socket); connected(socket);
} else { } else {
getSocket(); getSocket();
@ -228,12 +227,12 @@ async function openMessagePopup(message: string) {
const modalmessage = document.getElementById("modal-message") ?? null; const modalmessage = document.getElementById("modal-message") ?? null;
if(!message) return if(!message) return
const obj:string = JSON.parse(message); const obj = JSON.parse(message);
if (modalmessage) { if (modalmessage) {
const messageElement = document.createElement("div"); const messageElement = document.createElement("div");
messageElement.innerHTML = ` messageElement.innerHTML = `
<div class="profile-info" <div class="profile-info"
<div id="profile-about">Next Game Message ${incrementCounter()}: ${obj}</div> <div id="profile-about">Next Game Message ${incrementCounter()}: ${obj.link}</div>
</div>`; </div>`;
modalmessage.appendChild(messageElement); modalmessage.appendChild(messageElement);
modalmessage.scrollTop = modalmessage.scrollHeight; modalmessage.scrollTop = modalmessage.scrollHeight;
@ -245,16 +244,10 @@ async function openMessagePopup(message: string) {
// The popup now exists → attach the event // The popup now exists → attach the event
} }
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn { function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
let socket = getSocket(); let socket = getSocket();
let blockMessage: boolean; let blockMessage: boolean;
setTimeout(async () => { setTimeout(async () => {
// Listen for the 'connect' event // Listen for the 'connect' event
socket.on("connect", async () => { socket.on("connect", async () => {
@ -342,23 +335,11 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
profil.SenderName = getUser()?.name ?? ""; profil.SenderName = getUser()?.name ?? "";
openProfilePopup(profil); openProfilePopup(profil);
socket.emit('isBlockdBtn', profil); socket.emit('isBlockdBtn', profil);
// console.log(`DEBUG LOG: userId:${profil.userID}: senderID${profil.SenderID}' senderID:${getUser()?.id}`);
// console.log(`DEBUG LOG: user:${profil.user}: sender:${profil.SenderName}' senderID:${getUser()?.name}`);
socket.emit('check_Block_button', profil); socket.emit('check_Block_button', profil);
actionBtnPopUpClear(profil, socket);
actionBtnPopUpInvite(profil, socket); actionBtnPopUpInvite(profil, socket);
actionBtnPopUpBlock(profil, socket); actionBtnPopUpBlock(profil, socket);
}); });
// socket.on('inviteGame', (invite: ClientProfil) => {
// const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
// const messageElement = document.createElement("div");
// messageElement.innerHTML =`🏓${invite.SenderName}: ${invite.innerHtml}`;
// chatWindow.appendChild(messageElement);
// chatWindow.scrollTop = chatWindow.scrollHeight;
// });
socket.on('blockUser', (blocked: ClientProfil) => { socket.on('blockUser', (blocked: ClientProfil) => {
let icon = '⛔'; let icon = '⛔';
if (inviteMsgFlag) { if (inviteMsgFlag) {
@ -371,21 +352,15 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
} }
}); });
socket.on('blockBtn', (data: blockedUnBlocked) => { socket.on('blockBtn', (data: blockedUnBlocked) => {
const blockUserBtn = document.querySelector("#popup-b-block"); const blockUserBtn = document.querySelector("#popup-b-block");
if (blockUserBtn) { if (blockUserBtn) {
// console.log(' =================== >>> User State:', data.userState);
// console.log(' =================== >>> UserTarget:', data.userTarget);
// console.log(' =================== >>> By:', data.by);
let message = ""; let message = "";
if (data.userState === "block") {message = "un-block", blockMessage = true} else{message = "block", blockMessage = false} if (data.userState === "block") {message = "un-block", blockMessage = true} else{message = "block", blockMessage = false}
blockUserBtn.textContent = message; blockUserBtn.textContent = message;
} }
}); });
socket.on('logout', () => { socket.on('logout', () => {
quitChat(socket); quitChat(socket);
}); });
@ -397,7 +372,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
//receives broadcast of the next GAME //receives broadcast of the next GAME
socket.on('nextGame', (message: string) => { socket.on('nextGame', (message: string) => {
openMessagePopup(message); openMessagePopup(message);
// addMessage(message);
}) })
let toggle = false let toggle = false
@ -431,7 +405,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
socket.once('welcome', (data) => { socket.once('welcome', (data) => {
const buddies = document.getElementById('div-buddies') as HTMLDivElement; const buddies = document.getElementById('div-buddies') as HTMLDivElement;
const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement; const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement;
chatWindow.innerHTML = ''; // chatWindow.innerHTML = '';
buddies.textContent = ''; buddies.textContent = '';
buddies.innerHTML = ''; buddies.innerHTML = '';
connected(socket); connected(socket);
@ -448,16 +422,12 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement; const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement;
const sendtextbox = document.getElementById('t-chat-window') as HTMLButtonElement; const sendtextbox = document.getElementById('t-chat-window') as HTMLButtonElement;
const clearText = document.getElementById('b-clear') as HTMLButtonElement; const clearText = document.getElementById('b-clear') as HTMLButtonElement;
// const bwhoami = document.getElementById('b-whoami') as HTMLButtonElement;
// const bconnected = document.getElementById('b-help') as HTMLButtonElement;
const username = document.getElementById('username') as HTMLDivElement;
const buddies = document.getElementById('div-buddies') as HTMLDivElement; const buddies = document.getElementById('div-buddies') as HTMLDivElement;
const bquit = document.getElementById('b-quit') as HTMLDivElement; const bquit = document.getElementById('b-quit') as HTMLDivElement;
const systemWindow = document.getElementById('system-box') as HTMLDivElement;
const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement; const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement;
chatWindow.textContent = ''; // chatWindow.textContent = '';
chatWindow.innerHTML = ''; // chatWindow.innerHTML = '';
buddies.textContent = ''; buddies.textContent = '';
buddies.innerHTML = ''; buddies.innerHTML = '';

View file

@ -20,7 +20,7 @@
"fastify-plugin": "^5.1.0", "fastify-plugin": "^5.1.0",
"joi": "^18.0.2", "joi": "^18.0.2",
"otp": "^1.1.2", "otp": "^1.1.2",
"typebox": "^1.0.65", "typebox": "^1.0.69",
"uuidv7": "^1.1.0" "uuidv7": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {

View file

@ -27,7 +27,7 @@
"fastify": "^5.6.2", "fastify": "^5.6.2",
"fastify-cli": "^7.4.1", "fastify-cli": "^7.4.1",
"fastify-plugin": "^5.1.0", "fastify-plugin": "^5.1.0",
"typebox": "^1.0.65" "typebox": "^1.0.69"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.19.3", "@types/node": "^22.19.3",

View file

@ -26,8 +26,8 @@
"@fastify/websocket": "^11.2.0", "@fastify/websocket": "^11.2.0",
"fastify": "^5.6.2", "fastify": "^5.6.2",
"fastify-plugin": "^5.1.0", "fastify-plugin": "^5.1.0",
"socket.io": "^4.8.2", "socket.io": "^4.8.3",
"typebox": "^1.0.65" "typebox": "^1.0.69"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.19.3", "@types/node": "^22.19.3",

View file

@ -144,7 +144,6 @@ function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : string, is
}; };
async function onReady(fastify: FastifyInstance) { async function onReady(fastify: FastifyInstance) {
// shows address for connection au server transcendance
const session = process.env.SESSION_MANAGER ?? ''; const session = process.env.SESSION_MANAGER ?? '';
if (session) { if (session) {
const part = session.split('/')[1]; const part = session.split('/')[1];
@ -154,30 +153,10 @@ async function onReady(fastify: FastifyInstance) {
fastify.io.on('connection', (socket: Socket) => { fastify.io.on('connection', (socket: Socket) => {
socket.on('message', (message: string) => { socket.on('message', (message: string) => {
// console.info(color.blue, 'DEBUG LOG: Socket connected!', color.reset, socket.id);
// console.log( color.blue, 'DEBUG LOG: Received message from client', color.reset, message);
const obj: ClientMessage = JSON.parse(message) as ClientMessage; const obj: ClientMessage = JSON.parse(message) as ClientMessage;
clientChat.set(socket.id, { user: obj.user, socket: socket.id, lastSeen: Date.now() }); clientChat.set(socket.id, { user: obj.user, socket: socket.id, lastSeen: Date.now() });
// console.log(color.green, 'DEBUG LOG: Message from client', color.reset, `Sender: login name: ${obj.user} - windowID ${obj.SenderWindowID} - text message: ${obj.text}`);
socket.emit('welcome', { msg: 'Welcome to the chat! : ' }); socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
// Send object directly — DO NOT wrap it in a string
broadcast(fastify, obj, obj.SenderWindowID); broadcast(fastify, obj, obj.SenderWindowID);
// const users: User[] = fastify.db.getAllUsers() ?? [];
// console.log('DEBUG: senderWindow :', getUserById(users, obj.SenderUserID)?.name);
// fastify.io.fetchSockets().then((sockets) => {
// for (const socket of sockets) {
// const clientInfo = clientChat.get(socket.id);
// if (!clientInfo?.user) {
// console.log(color.yellow, `Skipping socket ${socket.id} (no user found)`);
// continue;
// }
// console.log('DEBUG: UserIDWindow :', getUserByName(users, clientInfo.user)?.id);
// const IDUser = getUserByName(users, clientInfo.user)?.id;
// console.log(filter_Blocked_user(fastify, obj, IDUser?? ""));
// }
// });
// console.log(color.red, 'DEBUG LOG: connected in the Chat :', connectedUser(fastify.io), color.reset);
}); });
nextGame_SocketListener(fastify, socket); nextGame_SocketListener(fastify, socket);
list_SocketListener(fastify, socket); list_SocketListener(fastify, socket);
@ -185,13 +164,7 @@ async function onReady(fastify: FastifyInstance) {
socket.on('updateClientName', (object) => { socket.on('updateClientName', (object) => {
const userFromFrontend = object || null; const userFromFrontend = object || null;
const client = clientChat.get(socket.id) || null; const client = clientChat.get(socket.id) || null;
// console.log(color.red, 'DEBUG LOG: whoAMi activated', userFromFrontend, color.reset, socket.id);
if (userFromFrontend.oldUser !== userFromFrontend.user) { if (userFromFrontend.oldUser !== userFromFrontend.user) {
// console.log(color.red, 'DEBUG LOG: whoAMi activated', userFromFrontend.oldUser, color.reset);
// if (client === null) {
// console.log('ERROR: clientName is NULL');
// return;
// };
if (client) { if (client) {
client.user = userFromFrontend.user; client.user = userFromFrontend.user;
console.log(color.yellow, `'DEBUG LOG: client.user is, '${client.user}'`); console.log(color.yellow, `'DEBUG LOG: client.user is, '${client.user}'`);
@ -204,7 +177,6 @@ async function onReady(fastify: FastifyInstance) {
const clientName = clientInfo?.user; const clientName = clientInfo?.user;
if (!clientName) return; if (!clientName) return;
// console.log(color.green, `Client logging out: ${clientName} (${socket.id})`);
const obj: ClientMessage = { const obj: ClientMessage = {
command: '', command: '',
destination: 'system-info', destination: 'system-info',
@ -222,15 +194,12 @@ async function onReady(fastify: FastifyInstance) {
SenderUserID: '', SenderUserID: '',
}; };
broadcast(fastify, obj, socket.id); broadcast(fastify, obj, socket.id);
// Optional: remove from map
clientChat.delete(socket.id); clientChat.delete(socket.id);
// Ensure socket is fully disconnected
if (socket.connected) socket.disconnect(true); if (socket.connected) socket.disconnect(true);
}); });
socket.on('disconnecting', (reason) => { socket.on('disconnecting', (reason) => {
const clientName = clientChat.get(socket.id)?.user || null; const clientName = clientChat.get(socket.id)?.user || null;
// console.log(color.green, `Client disconnecting: ${clientName} (${socket.id}) reason:`, reason,);
if (reason === 'transport error') return; if (reason === 'transport error') return;
if (clientName !== null) { if (clientName !== null) {
@ -258,7 +227,6 @@ async function onReady(fastify: FastifyInstance) {
socket.on('client_left', (data) => { socket.on('client_left', (data) => {
void data; void data;
const clientName = clientChat.get(socket.id)?.user || null; const clientName = clientChat.get(socket.id)?.user || null;
// const leftChat = data || null; console.log(color.green, `Left the Chat User: ${clientName} id Socket: ${socket.id} reason:`, leftChat.why,);
if (clientName !== null) { if (clientName !== null) {
const obj: ClientMessage = { const obj: ClientMessage = {
command: '', command: '',
@ -276,10 +244,7 @@ async function onReady(fastify: FastifyInstance) {
SenderUserName: '', SenderUserName: '',
SenderUserID: '', SenderUserID: '',
}; };
// console.log(color.blue, 'DEBUG LOG: BROADCASTS OUT :', obj.SenderWindowID);
broadcast(fastify, obj, obj.SenderWindowID); broadcast(fastify, obj, obj.SenderWindowID);
// clientChat.delete(obj.user);
} }
}); });
@ -287,7 +252,6 @@ async function onReady(fastify: FastifyInstance) {
socket.on('privMessage', (data) => { socket.on('privMessage', (data) => {
const clientName: string = clientChat.get(socket.id)?.user || ''; const clientName: string = clientChat.get(socket.id)?.user || '';
const prvMessage: ClientMessage = JSON.parse(data) || ''; const prvMessage: ClientMessage = JSON.parse(data) || '';
// console.log(color.blue, `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target Name:`, prvMessage.command,);
if (clientName !== null) { if (clientName !== null) {
const obj: ClientMessage = { const obj: ClientMessage = {
command: prvMessage.command, command: prvMessage.command,
@ -305,38 +269,26 @@ async function onReady(fastify: FastifyInstance) {
SenderUserName: '', SenderUserName: '',
SenderUserID:'', SenderUserID:'',
}; };
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
sendPrivMessage(fastify, obj, obj.SenderWindowID); sendPrivMessage(fastify, obj, obj.SenderWindowID);
// clientChat.delete(obj.user);
} }
}); });
socket.on('profilMessage', async (data: string) => { socket.on('profilMessage', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || ''; const clientName: string = clientChat.get(socket.id)?.user || '';
const profilMessage: ClientMessage = JSON.parse(data) || ''; const profilMessage: ClientMessage = JSON.parse(data) || '';
// const users: User[] = fastify.db.getAllUsers() ?? [];
// console.log(color.yellow, 'DEBUG LOG: ALL USERS EVER CONNECTED:', users);
// console.log(color.blue, `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target profil:`, profilMessage.user);
const profile: ClientProfil = await makeProfil(fastify, profilMessage.user, socket); const profile: ClientProfil = await makeProfil(fastify, profilMessage.user, socket);
if (clientName !== null) { if (clientName !== null) {
// const testuser: User | null = getUserByName(users, profilMessage.user);
// console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
// console.log(color.blue, 'DEBUG - profil message MESSAGE OUT :', profile.SenderWindowID);
sendProfil(fastify, profile, profile.SenderWindowID); sendProfil(fastify, profile, profile.SenderWindowID);
// clientChat.delete(obj.user);
} }
}); });
socket.on('inviteGame', async (data: string) => { socket.on('inviteGame', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || ''; const clientName: string = clientChat.get(socket.id)?.user || '';
const profilInvite: ClientProfil = JSON.parse(data) || ''; const profilInvite: ClientProfil = JSON.parse(data) || '';
// const users: User[] = fastify.db.getAllUsers() ?? [];
const inviteHtml: string = 'invites you to a game ' + setGameLink(''); const inviteHtml: string = 'invites you to a game ' + setGameLink('');
if (clientName !== null) { if (clientName !== null) {
console.log(`DEBUG LOG: clientName =${clientName}`); console.log(`DEBUG LOG: clientName =${clientName}`);
// const testuser: User | null = getUserByName(users, profilInvite.user ?? '');
// console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
sendInvite(fastify, inviteHtml, profilInvite); sendInvite(fastify, inviteHtml, profilInvite);
} }
}); });
@ -346,15 +298,7 @@ async function onReady(fastify: FastifyInstance) {
const users: User[] = fastify.db.getAllUsers() ?? []; const users: User[] = fastify.db.getAllUsers() ?? [];
const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`); const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`);
const UserAskingToBlock: User | null = getUserByName(users, `${profilBlock.SenderName}`); const UserAskingToBlock: User | null = getUserByName(users, `${profilBlock.SenderName}`);
// console.log(color.yellow, `user to block: ${profilBlock.user}`);
// console.log(color.yellow, UserToBlock);
// console.log(color.yellow, `user Asking to block: ${profilBlock.SenderName}`);
// console.log(color.yellow, UserAskingToBlock);
// console.log(color.red, clientName);
if (!UserAskingToBlock || !UserToBlock) return; if (!UserAskingToBlock || !UserToBlock) return;
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) { if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
const message: blockedUnBlocked = { const message: blockedUnBlocked = {
userState: 'block', userState: 'block',
@ -380,13 +324,6 @@ async function onReady(fastify: FastifyInstance) {
const users: User[] = fastify.db.getAllUsers() ?? []; const users: User[] = fastify.db.getAllUsers() ?? [];
const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`); const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`);
const UserAskingToBlock: User | null = getUserByName(users, `${profilBlock.SenderName}`); const UserAskingToBlock: User | null = getUserByName(users, `${profilBlock.SenderName}`);
// console.log(color.yellow, `user to block: ${profilBlock.user}`);
// console.log(color.yellow, UserToBlock);
// console.log(color.yellow, `user Asking to block: ${profilBlock.SenderName}`);
// console.log(color.yellow, UserAskingToBlock);
// console.log(color.red, clientName);
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? []; const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
if (!UserAskingToBlock || !UserToBlock || !usersBlocked) return; if (!UserAskingToBlock || !UserToBlock || !usersBlocked) return;
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked); const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
@ -408,13 +345,7 @@ async function onReady(fastify: FastifyInstance) {
} }
if (userAreBlocked) { if (userAreBlocked) {
// console.log(color.green, 'Both users are blocked as requested');
// return true; // or any other action you need to take
// console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
fastify.db.removeBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id); fastify.db.removeBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
// console.log(color.green, 'remove A BLOCKED USER:', usersBlocked2);
if (clientName !== null) { if (clientName !== null) {
const blockedMessage = 'I have un-blocked you'; const blockedMessage = 'I have un-blocked you';
if (clientName !== null) { if (clientName !== null) {
@ -431,29 +362,13 @@ async function onReady(fastify: FastifyInstance) {
SenderWindowID: socket.id, SenderWindowID: socket.id,
Sendertext: 'You have un-blocked', Sendertext: 'You have un-blocked',
}; };
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}💚`); socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}💚`);
// clientChat.delete(obj.user);
} }
// profilBlock.Sendertext = `'You have un-blocked '`;
sendBlocked(fastify, blockedMessage, profilBlock); sendBlocked(fastify, blockedMessage, profilBlock);
// const message: blockedUnBlocked =
// {
// userState: "un-block",
// userTarget: "",
// by: "",
// };
// socket.emit('blockBtn', message);
} }
} }
else { else {
// console.log(color.red, 'The users are not blocked in this way');
// console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
fastify.db.addBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id); fastify.db.addBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
// console.log(color.green, 'ALL BLOCKED USERS:', usersBlocked2);
if (clientName !== null) { if (clientName !== null) {
const blockedMessage = 'I have blocked you'; const blockedMessage = 'I have blocked you';
profilBlock.Sendertext = 'You have blocked '; profilBlock.Sendertext = 'You have blocked ';
@ -471,19 +386,9 @@ async function onReady(fastify: FastifyInstance) {
SenderWindowID: socket.id, SenderWindowID: socket.id,
Sendertext: 'You have blocked', Sendertext: 'You have blocked',
}; };
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}`); socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}`);
// clientChat.delete(obj.user);
} }
sendBlocked(fastify, blockedMessage, profilBlock); sendBlocked(fastify, blockedMessage, profilBlock);
// const message: blockedUnBlocked =
// {
// userState: "block",
// userTarget: UserToBlock.name,
// by: UserAskingToBlock.name,
// };
// socket.emit('blockBtn', message);
} }
} }
}); });

View file

@ -3,7 +3,6 @@ import { clientChat } from './app';
import { FastifyInstance } from 'fastify'; import { FastifyInstance } from 'fastify';
import { getUserByName } from './getUserByName'; import { getUserByName } from './getUserByName';
import type { User } from '@shared/database/mixin/user'; import type { User } from '@shared/database/mixin/user';
import { color } from './app';
import { checkNamePair } from './checkNamePair'; import { checkNamePair } from './checkNamePair';
import { whoBlockedMe } from './whoBlockedMe'; import { whoBlockedMe } from './whoBlockedMe';
@ -16,7 +15,6 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
for (const socket of sockets) { for (const socket of sockets) {
const clientInfo = clientChat.get(socket.id); const clientInfo = clientChat.get(socket.id);
if (!clientInfo?.user) { if (!clientInfo?.user) {
console.log(color.red, `Skipping socket ${socket.id} (no user found)`);
continue; continue;
} }
let blockMsgFlag: boolean = false; let blockMsgFlag: boolean = false;
@ -25,12 +23,9 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false; blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
if (socket.id === sender) { if (socket.id === sender) {
console.log(color.red, 'sKip Sender ', socket.id);
continue; continue;
} }
console.log(`BROADCAST blockFlag=${blockMsgFlag} : Target ${clientInfo.user}`);
if (!blockMsgFlag) { if (!blockMsgFlag) {
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
socket.emit('MsgObjectServer', { message: data }); socket.emit('MsgObjectServer', { message: data });
} }
} }

View file

@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'; import { FastifyInstance } from 'fastify';
import { clientChat, color } from './app'; import { clientChat } from './app';
/** /**
* function broadcast a clickable link * function broadcast a clickable link
@ -8,13 +8,11 @@ import { clientChat, color } from './app';
*/ */
export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) { export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) {
const link = gameLink ? await gameLink : undefined; const link = gameLink ? await gameLink : undefined;
console.log(color.green, 'link===========> ', link);
const sockets = await fastify.io.fetchSockets(); const sockets = await fastify.io.fetchSockets();
// fastify.io.fetchSockets().then((sockets) => { // fastify.io.fetchSockets().then((sockets) => {
for (const socket of sockets) { for (const socket of sockets) {
const clientInfo = clientChat.get(socket.id); const clientInfo = clientChat.get(socket.id);
if (!clientInfo?.user) { if (!clientInfo?.user) {
console.log(color.yellow, `DEBUG LOG: Skipping socket ${socket.id} (no user found)`);
continue; continue;
} }
if (link) { if (link) {

View file

@ -13,7 +13,7 @@ import { sendGameLinkToChatService } from './sendGameLinkToChatService';
*/ */
export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) { export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
socket.on('nextGame', () => { socket.on('nextGame', () => {
const link = createNextGame(); const link: string = createNextGame();
const game: Promise<string> = sendGameLinkToChatService(link); const game: Promise<string> = sendGameLinkToChatService(link);
broadcastNextGame(fastify, game); broadcastNextGame(fastify, game);
}); });

View file

@ -23,17 +23,17 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.2", "@eslint/js": "^9.39.2",
"@typescript-eslint/eslint-plugin": "^8.50.1", "@typescript-eslint/eslint-plugin": "^8.51.0",
"@typescript-eslint/parser": "^8.50.1", "@typescript-eslint/parser": "^8.51.0",
"eslint": "^9.39.2", "eslint": "^9.39.2",
"husky": "^9.1.7", "husky": "^9.1.7",
"lint-staged": "^16.2.7", "lint-staged": "^16.2.7",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"typescript-eslint": "^8.50.1", "typescript-eslint": "^8.51.0",
"vite": "^7.3.0" "vite": "^7.3.0"
}, },
"dependencies": { "dependencies": {
"@redocly/cli": "^2.14.0", "@redocly/cli": "^2.14.1",
"bindings": "^1.5.0" "bindings": "^1.5.0"
} }
} }

View file

@ -22,8 +22,8 @@
"@fastify/websocket": "^11.2.0", "@fastify/websocket": "^11.2.0",
"fastify": "^5.6.2", "fastify": "^5.6.2",
"fastify-plugin": "^5.1.0", "fastify-plugin": "^5.1.0",
"socket.io": "^4.8.2", "socket.io": "^4.8.3",
"typebox": "^1.0.65" "typebox": "^1.0.69"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.19.3", "@types/node": "^22.19.3",

View file

@ -26,7 +26,7 @@
"fastify": "^5.6.2", "fastify": "^5.6.2",
"fastify-cli": "^7.4.1", "fastify-cli": "^7.4.1",
"fastify-plugin": "^5.1.0", "fastify-plugin": "^5.1.0",
"typebox": "^1.0.65" "typebox": "^1.0.69"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.19.3", "@types/node": "^22.19.3",