fastify.log.info done
This commit is contained in:
parent
69ba60b03d
commit
b69a452810
13 changed files with 82 additions and 118 deletions
|
|
@ -132,11 +132,11 @@ services:
|
|||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||
- PROVIDER_FILE=/extra/providers.toml
|
||||
- SESSION_MANAGER=${SESSION_MANAGER}
|
||||
logging:
|
||||
driver: gelf
|
||||
options:
|
||||
gelf-address: "udp://127.0.0.1:12201"
|
||||
tag: "{{.Name}}"
|
||||
# logging:
|
||||
# driver: gelf
|
||||
# options:
|
||||
# gelf-address: "udp://127.0.0.1:12201"
|
||||
# tag: "{{.Name}}"
|
||||
|
||||
###############
|
||||
# PONG #
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
@import "tailwindcss";
|
||||
@font-face {
|
||||
font-family: "Nimbus Mono L";
|
||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
||||
font-family: "DejaVu Sans Mono";
|
||||
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||
}
|
||||
|
||||
@tailwind utilities;
|
||||
|
|
|
|||
|
|
@ -15,21 +15,9 @@ import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock';
|
|||
import { windowStateHidden } from './chatHelperFunctions/windowStateHidden';
|
||||
import type { blockedUnBlocked, obj } from './types_front';
|
||||
|
||||
export const color = {
|
||||
red: 'color: red;',
|
||||
green: 'color: green;',
|
||||
yellow: 'color: orange;',
|
||||
blue: 'color: blue;',
|
||||
reset: '',
|
||||
};
|
||||
|
||||
|
||||
const MAX_SYSTEM_MESSAGES = 10;
|
||||
let inviteMsgFlag: boolean = false;
|
||||
|
||||
// get the name of the machine used to connect
|
||||
const machineHostName = window.location.hostname;
|
||||
console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow);
|
||||
|
||||
export let __socket: Socket | undefined = undefined;
|
||||
document.addEventListener('ft:pageChange', () => {
|
||||
|
|
@ -73,7 +61,7 @@ async function windowStateVisable() {
|
|||
const socketId = __socket || undefined;
|
||||
let oldName = localStorage.getItem("oldName") || undefined;
|
||||
|
||||
if (socketId === undefined || oldName === undefined) {console.log("%SOCKET ID", color.red); return;}
|
||||
if (socketId === undefined || oldName === undefined) {return;};
|
||||
let user = await updateUser();
|
||||
if(user === null) return;
|
||||
socketId.emit('client_entered', {
|
||||
|
|
@ -166,14 +154,11 @@ async function connected(socket: Socket): Promise<void> {
|
|||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
||||
const loggedIn = isLoggedIn();
|
||||
if (!loggedIn) throw('Not Logged in');
|
||||
console.log('%cloggedIn:',color.blue, loggedIn?.name);
|
||||
let oldUser = localStorage.getItem("oldName") ?? "";
|
||||
console.log('%coldUser:',color.yellow, oldUser);
|
||||
if (loggedIn?.name === undefined) {console.log('');return ;}
|
||||
if (loggedIn?.name === undefined) {return ;};
|
||||
oldUser = loggedIn.name ?? "";
|
||||
// const res = await client.guestLogin();
|
||||
let user = await updateUser();
|
||||
console.log('%cUser?name:',color.yellow, user?.name);
|
||||
localStorage.setItem("oldName", oldUser);
|
||||
buddies.textContent = "";
|
||||
socket.emit('list', {
|
||||
|
|
@ -376,11 +361,8 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
const bquit = document.getElementById('b-quit') as HTMLDivElement;
|
||||
const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement;
|
||||
|
||||
// chatWindow.textContent = '';
|
||||
// chatWindow.innerHTML = '';
|
||||
buddies.textContent = '';
|
||||
buddies.innerHTML = '';
|
||||
|
||||
const buttonPro = document.getElementById("close-modal") ?? null;
|
||||
|
||||
if (buttonPro)
|
||||
|
|
@ -491,8 +473,10 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
});
|
||||
|
||||
// Enter key to send message
|
||||
sendtextbox!.addEventListener('keydown', (event) => {
|
||||
sendtextbox.addEventListener('keydown', (event) => {
|
||||
if(!sendtextbox) return;
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
sendButton?.click();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
@import "tailwindcss";
|
||||
|
||||
@font-face {
|
||||
font-family: "Nimbus Mono L";
|
||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
||||
font-family: "DejaVu Sans Mono";
|
||||
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
@import "tailwindcss";
|
||||
@font-face {
|
||||
font-family: "Nimbus Mono L";
|
||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
||||
font-family: "DejaVu Sans Mono";
|
||||
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||
}
|
||||
|
||||
@tailwind utilities;
|
||||
|
|
|
|||
|
|
@ -21,26 +21,14 @@ import { setGameLink } from './setGameLink';
|
|||
import { nextGame_SocketListener } from './nextGame_SocketListener';
|
||||
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
|
||||
|
||||
// colors for console.log
|
||||
export const color = {
|
||||
red: '\x1b[31m',
|
||||
green: '\x1b[32m',
|
||||
yellow: '\x1b[33m',
|
||||
blue: '\x1b[34m',
|
||||
reset: '\x1b[0m',
|
||||
};
|
||||
|
||||
declare const __SERVICE_NAME: string;
|
||||
|
||||
// Global map of clients
|
||||
// key = socket, value = clientname
|
||||
interface ClientInfo {
|
||||
user: string;
|
||||
socket: string
|
||||
lastSeen: number;
|
||||
}
|
||||
|
||||
|
||||
export type blockedUnBlocked =
|
||||
{
|
||||
userState: string,
|
||||
|
|
@ -125,20 +113,16 @@ function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : string, is
|
|||
const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
||||
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
||||
if (!UserToBlock) {
|
||||
console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`);
|
||||
return '';
|
||||
};
|
||||
if (!UserAskingToBlock) {
|
||||
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
|
||||
return '';
|
||||
};
|
||||
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||
if (userAreBlocked) {
|
||||
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`);
|
||||
return UserAskingToBlock.name;
|
||||
}
|
||||
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
|
||||
return '';
|
||||
};
|
||||
|
||||
|
|
@ -147,7 +131,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
if (session) {
|
||||
const part = session.split('/')[1];
|
||||
const machineName = part.split('.')[0];
|
||||
console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login');
|
||||
fastify.log.info(`Connect at : https://${machineName}:8888/`);
|
||||
}
|
||||
|
||||
fastify.io.on('connection', (socket: Socket) => {
|
||||
|
|
@ -156,6 +140,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
clientChat.set(socket.id, { user: obj.user, socket: socket.id, lastSeen: Date.now() });
|
||||
socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
|
||||
broadcast(fastify, obj, obj.SenderWindowID);
|
||||
fastify.log.info(`Client connected: ${socket.id}`);
|
||||
});
|
||||
nextGame_SocketListener(fastify, socket);
|
||||
list_SocketListener(fastify, socket);
|
||||
|
|
@ -166,7 +151,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
if (userFromFrontend.oldUser !== userFromFrontend.user) {
|
||||
if (client) {
|
||||
client.user = userFromFrontend.user;
|
||||
console.log(color.yellow, `'DEBUG LOG: client.user is, '${client.user}'`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -218,7 +202,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
SenderUserName: '',
|
||||
SenderUserID: '',
|
||||
};
|
||||
|
||||
broadcast(fastify, obj, obj.SenderWindowID);
|
||||
}
|
||||
});
|
||||
|
|
@ -272,6 +255,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
socket.on('profilMessage', async (data: string) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
||||
|
|
@ -287,7 +271,6 @@ async function onReady(fastify: FastifyInstance) {
|
|||
|
||||
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
||||
if (clientName !== null) {
|
||||
console.log(`DEBUG LOG: clientName =${clientName}`);
|
||||
sendInvite(fastify, inviteHtml, profilInvite);
|
||||
}
|
||||
});
|
||||
|
|
@ -397,29 +380,18 @@ async function onReady(fastify: FastifyInstance) {
|
|||
const userNameFromFrontend = data?.userName || null;
|
||||
const userFromFrontend = data?.user || null;
|
||||
let clientName = clientChat.get(socket.id)?.user || null;
|
||||
// const client = clientChat.get(socket.id) || null;
|
||||
let text = 'is back in the chat';
|
||||
|
||||
if (clientName === null) {
|
||||
console.log('ERROR: clientName is NULL'); return;
|
||||
fastify.log.error('ERROR: clientName is NULL'); return;
|
||||
};
|
||||
// if (client === null) {
|
||||
// console.log('ERROR: client is NULL'); return;
|
||||
// };
|
||||
if (userNameFromFrontend !== userFromFrontend) {
|
||||
text = `'is back in the chat, I used to be called '${userNameFromFrontend}`;
|
||||
clientName = userFromFrontend;
|
||||
if (clientName === null) {
|
||||
console.log('ERROR: clientName is NULL'); return;
|
||||
fastify.log.error('ERROR: clientName is NULL'); return;
|
||||
};
|
||||
// if (client) {
|
||||
// client.user = clientName;
|
||||
// }
|
||||
}
|
||||
// console.log(
|
||||
// color.green,
|
||||
// `Client entered the Chat: ${clientName} (${socket.id})`,
|
||||
// );
|
||||
if (clientName !== null) {
|
||||
const obj: ClientMessage = {
|
||||
command: '',
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import { clientChat } from './app';
|
|||
export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) {
|
||||
const link = gameLink ? await gameLink : undefined;
|
||||
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) {
|
||||
|
|
@ -18,6 +17,5 @@ export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Pro
|
|||
if (link) {
|
||||
socket.emit('nextGame', link);
|
||||
}
|
||||
// console.log(color.green, `'DEBUG LOG: Broadcast to:', ${data.command} message: ${data.text}`);
|
||||
}
|
||||
};
|
||||
|
|
@ -27,6 +27,9 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
|||
}
|
||||
if (!blockMsgFlag) {
|
||||
socket.emit('MsgObjectServer', { message: data });
|
||||
if (data.SenderUserID) {
|
||||
fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,16 @@ import { clientChat } from '../app';
|
|||
import { FastifyInstance } from 'fastify';
|
||||
import { sendPrivMessage } from './sendPrivMessage';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* function needed to transfer the game number
|
||||
*/
|
||||
|
||||
function getGameNumber():string {
|
||||
const gameNumber = '123456GameNum';
|
||||
return gameNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* function looks for the user online in the chat
|
||||
* and sends emit to invite - format HTML to make clickable
|
||||
|
|
@ -12,8 +22,8 @@ import { sendPrivMessage } from './sendPrivMessage';
|
|||
* @param profil
|
||||
*/
|
||||
|
||||
export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
||||
fastify.io.fetchSockets().then((sockets) => {
|
||||
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
||||
const sockets = await fastify.io.fetchSockets();
|
||||
let targetSocket;
|
||||
for (const socket of sockets) {
|
||||
const clientInfo: string = clientChat.get(socket.id)?.user || '';
|
||||
|
|
@ -28,7 +38,7 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
|
|||
type: 'chat',
|
||||
user: profil.SenderName,
|
||||
token: '',
|
||||
text: ' needs some text to work',
|
||||
text: getGameNumber(),
|
||||
timestamp: Date.now(),
|
||||
SenderWindowID: socket.id,
|
||||
userID: '',
|
||||
|
|
@ -44,5 +54,4 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
|
|||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -47,17 +47,17 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation []
|
|||
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
||||
|
||||
const sockets = await fastify.io.fetchSockets();
|
||||
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
||||
const allUsers: User[] = fastify.db.getAllUsers() ?? [];
|
||||
const senderSocket = sockets.find(socket => socket.id === sender);
|
||||
for (const socket of sockets) {
|
||||
const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
|
||||
const UserID = getUserByName(allUsers, data.user)?.id ?? '';
|
||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||
const clientInfo = clientChat.get(socket.id);
|
||||
if (!clientInfo?.user) {
|
||||
continue;
|
||||
}
|
||||
let blockMsgFlag: boolean = false;
|
||||
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
||||
const UserByID = getUserByName(allUsers, clientInfo.user) ?? '';
|
||||
if (UserByID === '') {
|
||||
return;
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
|||
}
|
||||
if (!blockMsgFlag) {
|
||||
socket.emit('MsgObjectServer', { message: data });
|
||||
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` });
|
||||
if (senderSocket) {
|
||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@ import type { ClientProfil } from '../chat_types';
|
|||
* @param SenderWindowID
|
||||
*/
|
||||
|
||||
export function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) {
|
||||
fastify.io.fetchSockets().then((sockets) => {
|
||||
export async function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) {
|
||||
const sockets = await fastify.io.fetchSockets();
|
||||
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
|
||||
if (senderSocket) {
|
||||
senderSocket.emit('profilMessage', profil);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -24,7 +24,6 @@ const start = async () => {
|
|||
f.log.info('Requested to shutdown');
|
||||
process.exit(134);
|
||||
});
|
||||
console.log('-------->Serving static files from:');
|
||||
await f.register(app, {});
|
||||
await f.listen({ port: 80, host: '0.0.0.0' });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,6 @@ export class StateI {
|
|||
socket.on('debugInfo', () => this.debugSocket(socket));
|
||||
|
||||
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
||||
if (socket) {console.log('Socket:', socket.id);};
|
||||
}
|
||||
|
||||
private updateClient(socket: SSocket): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue