Cleaned un the type obj - now consistant through out

This commit is contained in:
NigeParis 2025-12-17 10:20:07 +01:00
parent f5366bf9e1
commit e543116b5d
2 changed files with 32 additions and 8 deletions

View file

@ -31,6 +31,21 @@ export type blockedUnBlocked =
by: string, 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,
};
// get the name of the machine used to connect // get the name of the machine used to connect
const machineHostName = window.location.hostname; const machineHostName = window.location.hostname;
console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow); console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow);
@ -242,7 +257,7 @@ 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:any = JSON.parse(message); const obj:string = JSON.parse(message);
if (modalmessage) { if (modalmessage) {
const messageElement = document.createElement("div"); const messageElement = document.createElement("div");
messageElement.innerHTML = ` messageElement.innerHTML = `
@ -341,7 +356,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
profil.SenderID = getUser()?.id ?? ""; profil.SenderID = getUser()?.id ?? "";
profil.SenderName = getUser()?.name ?? ""; profil.SenderName = getUser()?.name ?? "";
openProfilePopup(profil); openProfilePopup(profil);
console.log(`DEBUG LOG: userId:${profil.userID}: senderID ${profil.SenderID}' senderID:${getUser()?.id}`); 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}`); 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); actionBtnPopUpClear(profil, socket);

View file

@ -189,7 +189,7 @@ async function onReady(fastify: FastifyInstance) {
socket.on('message', (message: string) => { socket.on('message', (message: string) => {
// console.info(color.blue, 'DEBUG LOG: Socket connected!', color.reset, socket.id); // 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); // console.log( color.blue, 'DEBUG LOG: Received message from client', color.reset, message);
const obj: ClientMessage = JSON.parse(message) as ClientMessage; const obj: obj = JSON.parse(message) as ClientMessage;
clientChat.set(socket.id, { user: obj.user, lastSeen: Date.now() }); clientChat.set(socket.id, { user: obj.user, 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}`); // 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! : ' });
@ -247,15 +247,18 @@ async function onReady(fastify: FastifyInstance) {
if (!clientName) return; if (!clientName) return;
console.log(color.green, `Client logging out: ${clientName} (${socket.id})`); console.log(color.green, `Client logging out: ${clientName} (${socket.id})`);
const obj = { const obj: obj = {
command: '', command: '',
destination: 'system-info', destination: 'system-info',
type: 'chat' as const, type: 'chat' as const,
user: clientName, user: clientName,
token: '', token: '',
text: 'LEFT the chat', text: 'LEFT the chat',
timestamp: Date.now(), frontendUserName: '',
SenderWindowID: socket.id, frontendUser: '',
timestamp: Date.now(),
SenderWindowID: socket.id,
Sendertext: '',
}; };
broadcast(fastify, obj, socket.id); broadcast(fastify, obj, socket.id);
// Optional: remove from map // Optional: remove from map
@ -274,15 +277,18 @@ async function onReady(fastify: FastifyInstance) {
if (reason === 'transport error') return; if (reason === 'transport error') return;
if (clientName !== null) { if (clientName !== null) {
const obj = { const obj: obj = {
command: '', command: '',
destination: 'system-info', destination: 'system-info',
type: 'chat', type: 'chat',
user: clientName, user: clientName,
token: '', token: '',
text: 'LEFT the chat', text: 'LEFT the chat',
frontendUserName: '',
frontendUser: '',
timestamp: Date.now(), timestamp: Date.now(),
SenderWindowID: socket.id, SenderWindowID: socket.id,
Sendertext: '',
}; };
broadcast(fastify, obj, obj.SenderWindowID); broadcast(fastify, obj, obj.SenderWindowID);
@ -299,15 +305,18 @@ async function onReady(fastify: FastifyInstance) {
); );
if (clientName !== null) { if (clientName !== null) {
const obj = { const obj: obj = {
command: '', command: '',
destination: 'system-info', destination: 'system-info',
type: 'chat', type: 'chat',
user: clientName, user: clientName,
token: '', token: '',
text: 'LEFT the chat but the window is still open', text: 'LEFT the chat but the window is still open',
frontendUserName: '',
frontendUser: '',
timestamp: Date.now(), timestamp: Date.now(),
SenderWindowID: socket.id, SenderWindowID: socket.id,
Sendertext: '',
}; };
// console.log(color.blue, 'DEBUG LOG: BROADCASTS OUT :', obj.SenderWindowID); // console.log(color.blue, 'DEBUG LOG: BROADCASTS OUT :', obj.SenderWindowID);