clean up
This commit is contained in:
parent
581a2330de
commit
1ca84b30c6
12 changed files with 47 additions and 192 deletions
|
|
@ -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)
|
||||
};
|
||||
|
|
@ -12,7 +12,6 @@ import { broadcastMsg } from './broadcastMsg';
|
|||
import { isLoggedIn } from './isLoggedIn';
|
||||
import type { ClientMessage, ClientProfil } from './types_front';
|
||||
import { openProfilePopup } from './openProfilePopup';
|
||||
import { actionBtnPopUpClear } from './actionBtnPopUpClear';
|
||||
import { actionBtnPopUpBlock } from './actionBtnPopUpBlock';
|
||||
import { windowStateHidden } from './windowStateHidden';
|
||||
|
||||
|
|
@ -167,8 +166,8 @@ function quitChat (socket: Socket) {
|
|||
if (socket) {
|
||||
logout(socket);
|
||||
setTitle('Chat Page');
|
||||
systemWindow.innerHTML = "";
|
||||
chatWindow.textContent = "";
|
||||
// systemWindow.innerHTML = "";
|
||||
// chatWindow.textContent = "";
|
||||
connected(socket);
|
||||
} else {
|
||||
getSocket();
|
||||
|
|
@ -228,12 +227,12 @@ async function openMessagePopup(message: string) {
|
|||
|
||||
const modalmessage = document.getElementById("modal-message") ?? null;
|
||||
if(!message) return
|
||||
const obj:string = JSON.parse(message);
|
||||
const obj = JSON.parse(message);
|
||||
if (modalmessage) {
|
||||
const messageElement = document.createElement("div");
|
||||
messageElement.innerHTML = `
|
||||
<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>`;
|
||||
modalmessage.appendChild(messageElement);
|
||||
modalmessage.scrollTop = modalmessage.scrollHeight;
|
||||
|
|
@ -245,16 +244,10 @@ async function openMessagePopup(message: string) {
|
|||
// The popup now exists → attach the event
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
|
||||
|
||||
|
||||
let socket = getSocket();
|
||||
let blockMessage: boolean;
|
||||
setTimeout(async () => {
|
||||
|
||||
// Listen for the 'connect' event
|
||||
socket.on("connect", async () => {
|
||||
|
||||
|
|
@ -283,7 +276,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
systemWindow.appendChild(messageElement);
|
||||
systemWindow.scrollTop = systemWindow.scrollHeight;
|
||||
});
|
||||
}, 0);
|
||||
},0);
|
||||
|
||||
// Listen for messages from the server "MsgObjectServer"
|
||||
socket.on("MsgObjectServer", (data: { message: ClientMessage}) => {
|
||||
|
|
@ -342,23 +335,11 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
profil.SenderName = getUser()?.name ?? "";
|
||||
openProfilePopup(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);
|
||||
actionBtnPopUpClear(profil, socket);
|
||||
actionBtnPopUpInvite(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) => {
|
||||
let icon = '⛔';
|
||||
if (inviteMsgFlag) {
|
||||
|
|
@ -371,21 +352,15 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
socket.on('blockBtn', (data: blockedUnBlocked) => {
|
||||
const blockUserBtn = document.querySelector("#popup-b-block");
|
||||
if (blockUserBtn) {
|
||||
|
||||
// console.log(' =================== >>> User State:', data.userState);
|
||||
// console.log(' =================== >>> UserTarget:', data.userTarget);
|
||||
// console.log(' =================== >>> By:', data.by);
|
||||
let message = "";
|
||||
if (data.userState === "block") {message = "un-block", blockMessage = true} else{message = "block", blockMessage = false}
|
||||
blockUserBtn.textContent = message;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
socket.on('logout', () => {
|
||||
quitChat(socket);
|
||||
});
|
||||
|
|
@ -397,7 +372,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
//receives broadcast of the next GAME
|
||||
socket.on('nextGame', (message: string) => {
|
||||
openMessagePopup(message);
|
||||
// addMessage(message);
|
||||
})
|
||||
|
||||
let toggle = false
|
||||
|
|
@ -431,7 +405,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
socket.once('welcome', (data) => {
|
||||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
||||
const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement;
|
||||
chatWindow.innerHTML = '';
|
||||
// chatWindow.innerHTML = '';
|
||||
buddies.textContent = '';
|
||||
buddies.innerHTML = '';
|
||||
connected(socket);
|
||||
|
|
@ -448,16 +422,12 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
const chatWindow = document.getElementById('t-chatbox') as HTMLDivElement;
|
||||
const sendtextbox = document.getElementById('t-chat-window') 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 bquit = document.getElementById('b-quit') as HTMLDivElement;
|
||||
const systemWindow = document.getElementById('system-box') as HTMLDivElement;
|
||||
const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement;
|
||||
|
||||
chatWindow.textContent = '';
|
||||
chatWindow.innerHTML = '';
|
||||
// chatWindow.textContent = '';
|
||||
// chatWindow.innerHTML = '';
|
||||
buddies.textContent = '';
|
||||
buddies.innerHTML = '';
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
"fastify-plugin": "^5.1.0",
|
||||
"joi": "^18.0.2",
|
||||
"otp": "^1.1.2",
|
||||
"typebox": "^1.0.65",
|
||||
"typebox": "^1.0.69",
|
||||
"uuidv7": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
"fastify": "^5.6.2",
|
||||
"fastify-cli": "^7.4.1",
|
||||
"fastify-plugin": "^5.1.0",
|
||||
"typebox": "^1.0.65"
|
||||
"typebox": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.19.3",
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@
|
|||
"@fastify/websocket": "^11.2.0",
|
||||
"fastify": "^5.6.2",
|
||||
"fastify-plugin": "^5.1.0",
|
||||
"socket.io": "^4.8.2",
|
||||
"typebox": "^1.0.65"
|
||||
"socket.io": "^4.8.3",
|
||||
"typebox": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.19.3",
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : string, is
|
|||
};
|
||||
|
||||
async function onReady(fastify: FastifyInstance) {
|
||||
// shows address for connection au server transcendance
|
||||
const session = process.env.SESSION_MANAGER ?? '';
|
||||
if (session) {
|
||||
const part = session.split('/')[1];
|
||||
|
|
@ -154,30 +153,10 @@ async function onReady(fastify: FastifyInstance) {
|
|||
|
||||
fastify.io.on('connection', (socket: Socket) => {
|
||||
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;
|
||||
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! : ' });
|
||||
// Send object directly — DO NOT wrap it in a string
|
||||
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);
|
||||
list_SocketListener(fastify, socket);
|
||||
|
|
@ -185,13 +164,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
socket.on('updateClientName', (object) => {
|
||||
const userFromFrontend = object || 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) {
|
||||
// console.log(color.red, 'DEBUG LOG: whoAMi activated', userFromFrontend.oldUser, color.reset);
|
||||
// if (client === null) {
|
||||
// console.log('ERROR: clientName is NULL');
|
||||
// return;
|
||||
// };
|
||||
if (client) {
|
||||
client.user = userFromFrontend.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;
|
||||
|
||||
if (!clientName) return;
|
||||
// console.log(color.green, `Client logging out: ${clientName} (${socket.id})`);
|
||||
const obj: ClientMessage = {
|
||||
command: '',
|
||||
destination: 'system-info',
|
||||
|
|
@ -222,15 +194,12 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderUserID: '',
|
||||
};
|
||||
broadcast(fastify, obj, socket.id);
|
||||
// Optional: remove from map
|
||||
clientChat.delete(socket.id);
|
||||
// Ensure socket is fully disconnected
|
||||
if (socket.connected) socket.disconnect(true);
|
||||
});
|
||||
|
||||
socket.on('disconnecting', (reason) => {
|
||||
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 (clientName !== null) {
|
||||
|
|
@ -258,7 +227,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
socket.on('client_left', (data) => {
|
||||
void data;
|
||||
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) {
|
||||
const obj: ClientMessage = {
|
||||
command: '',
|
||||
|
|
@ -276,10 +244,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderUserName: '',
|
||||
SenderUserID: '',
|
||||
};
|
||||
// console.log(color.blue, 'DEBUG LOG: BROADCASTS OUT :', obj.SenderWindowID);
|
||||
|
||||
broadcast(fastify, obj, obj.SenderWindowID);
|
||||
// clientChat.delete(obj.user);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -287,7 +252,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
socket.on('privMessage', (data) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
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) {
|
||||
const obj: ClientMessage = {
|
||||
command: prvMessage.command,
|
||||
|
|
@ -305,38 +269,26 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderUserName: '',
|
||||
SenderUserID:'',
|
||||
};
|
||||
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
|
||||
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
||||
// clientChat.delete(obj.user);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('profilMessage', async (data: string) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
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);
|
||||
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);
|
||||
// clientChat.delete(obj.user);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('inviteGame', async (data: string) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||
// const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||
|
||||
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
||||
if (clientName !== null) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
@ -346,15 +298,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||
const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`);
|
||||
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 (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
|
||||
const message: blockedUnBlocked = {
|
||||
userState: 'block',
|
||||
|
|
@ -380,13 +324,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||
const UserToBlock: User | null = getUserByName(users, `${profilBlock.user}`);
|
||||
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() ?? [];
|
||||
if (!UserAskingToBlock || !UserToBlock || !usersBlocked) return;
|
||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||
|
|
@ -408,13 +345,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
}
|
||||
|
||||
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);
|
||||
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
||||
// console.log(color.green, 'remove A BLOCKED USER:', usersBlocked2);
|
||||
if (clientName !== null) {
|
||||
const blockedMessage = 'I have un-blocked you';
|
||||
if (clientName !== null) {
|
||||
|
|
@ -431,29 +362,13 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderWindowID: socket.id,
|
||||
Sendertext: 'You have un-blocked',
|
||||
};
|
||||
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
|
||||
socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}💚`);
|
||||
// clientChat.delete(obj.user);
|
||||
}
|
||||
// profilBlock.Sendertext = `'You have un-blocked '`;
|
||||
sendBlocked(fastify, blockedMessage, profilBlock);
|
||||
// const message: blockedUnBlocked =
|
||||
// {
|
||||
// userState: "un-block",
|
||||
// userTarget: "",
|
||||
// by: "",
|
||||
|
||||
// };
|
||||
// socket.emit('blockBtn', message);
|
||||
}
|
||||
}
|
||||
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);
|
||||
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
||||
// console.log(color.green, 'ALL BLOCKED USERS:', usersBlocked2);
|
||||
if (clientName !== null) {
|
||||
const blockedMessage = 'I have blocked you';
|
||||
profilBlock.Sendertext = 'You have blocked ';
|
||||
|
|
@ -471,19 +386,9 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderWindowID: socket.id,
|
||||
Sendertext: 'You have blocked',
|
||||
};
|
||||
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
|
||||
socket.emit('privMessageCopy', `${obj.Sendertext}: ${UserToBlock.name}⛔`);
|
||||
// clientChat.delete(obj.user);
|
||||
}
|
||||
sendBlocked(fastify, blockedMessage, profilBlock);
|
||||
// const message: blockedUnBlocked =
|
||||
// {
|
||||
// userState: "block",
|
||||
// userTarget: UserToBlock.name,
|
||||
// by: UserAskingToBlock.name,
|
||||
|
||||
// };
|
||||
// socket.emit('blockBtn', message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { clientChat } from './app';
|
|||
import { FastifyInstance } from 'fastify';
|
||||
import { getUserByName } from './getUserByName';
|
||||
import type { User } from '@shared/database/mixin/user';
|
||||
import { color } from './app';
|
||||
import { checkNamePair } from './checkNamePair';
|
||||
import { whoBlockedMe } from './whoBlockedMe';
|
||||
|
||||
|
|
@ -16,7 +15,6 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
|||
for (const socket of sockets) {
|
||||
const clientInfo = clientChat.get(socket.id);
|
||||
if (!clientInfo?.user) {
|
||||
console.log(color.red, `Skipping socket ${socket.id} (no user found)`);
|
||||
continue;
|
||||
}
|
||||
let blockMsgFlag: boolean = false;
|
||||
|
|
@ -25,12 +23,9 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
|||
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
|
||||
|
||||
if (socket.id === sender) {
|
||||
console.log(color.red, 'sKip Sender ', socket.id);
|
||||
continue;
|
||||
}
|
||||
console.log(`BROADCAST blockFlag=${blockMsgFlag} : Target ${clientInfo.user}`);
|
||||
if (!blockMsgFlag) {
|
||||
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
|
||||
socket.emit('MsgObjectServer', { message: data });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { FastifyInstance } from 'fastify';
|
||||
import { clientChat, color } from './app';
|
||||
import { clientChat } from './app';
|
||||
|
||||
/**
|
||||
* function broadcast a clickable link
|
||||
|
|
@ -8,13 +8,11 @@ import { clientChat, color } from './app';
|
|||
*/
|
||||
export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) {
|
||||
const link = gameLink ? await gameLink : undefined;
|
||||
console.log(color.green, 'link===========> ', link);
|
||||
const sockets = await fastify.io.fetchSockets();
|
||||
// fastify.io.fetchSockets().then((sockets) => {
|
||||
for (const socket of sockets) {
|
||||
const clientInfo = clientChat.get(socket.id);
|
||||
if (!clientInfo?.user) {
|
||||
console.log(color.yellow, `DEBUG LOG: Skipping socket ${socket.id} (no user found)`);
|
||||
continue;
|
||||
}
|
||||
if (link) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { sendGameLinkToChatService } from './sendGameLinkToChatService';
|
|||
*/
|
||||
export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
|
||||
socket.on('nextGame', () => {
|
||||
const link = createNextGame();
|
||||
const link: string = createNextGame();
|
||||
const game: Promise<string> = sendGameLinkToChatService(link);
|
||||
broadcastNextGame(fastify, game);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
||||
"@typescript-eslint/parser": "^8.50.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.51.0",
|
||||
"@typescript-eslint/parser": "^8.51.0",
|
||||
"eslint": "^9.39.2",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.2.7",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.50.1",
|
||||
"typescript-eslint": "^8.51.0",
|
||||
"vite": "^7.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@redocly/cli": "^2.14.0",
|
||||
"@redocly/cli": "^2.14.1",
|
||||
"bindings": "^1.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
"@fastify/websocket": "^11.2.0",
|
||||
"fastify": "^5.6.2",
|
||||
"fastify-plugin": "^5.1.0",
|
||||
"socket.io": "^4.8.2",
|
||||
"typebox": "^1.0.65"
|
||||
"socket.io": "^4.8.3",
|
||||
"typebox": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.19.3",
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
"fastify": "^5.6.2",
|
||||
"fastify-cli": "^7.4.1",
|
||||
"fastify-plugin": "^5.1.0",
|
||||
"typebox": "^1.0.65"
|
||||
"typebox": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.19.3",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue