Added machine Name to display address of connect in logs
This commit is contained in:
parent
61b8919995
commit
f904a6b6ae
4 changed files with 147 additions and 43 deletions
|
|
@ -141,7 +141,7 @@ services:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- DATABASE_DIR=/volumes/database
|
- DATABASE_DIR=/volumes/database
|
||||||
- PROVIDER_FILE=/extra/providers.toml
|
- PROVIDER_FILE=/extra/providers.toml
|
||||||
|
- SESSION_MANAGER=${SESSION_MANAGER}
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# USER #
|
# USER #
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,13 @@ p {
|
||||||
div-test {
|
div-test {
|
||||||
@apply
|
@apply
|
||||||
text-red-800
|
text-red-800
|
||||||
text-right
|
text-right;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div-notlog {
|
||||||
|
@apply
|
||||||
|
text-red-800
|
||||||
|
text-3xl
|
||||||
|
text-center;
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,21 @@ import client from '@app/api'
|
||||||
import { getUser, updateUser } from "@app/auth";
|
import { getUser, updateUser } from "@app/auth";
|
||||||
import io, { Socket } from 'socket.io-client';
|
import io, { Socket } from 'socket.io-client';
|
||||||
|
|
||||||
|
const color = {
|
||||||
|
red: 'color: red; font-weight: bold;',
|
||||||
|
green: 'color: green; font-weight: bold;',
|
||||||
|
yellow: 'color: orange; font-weight: bold;',
|
||||||
|
blue: 'color: blue; font-weight: bold;',
|
||||||
|
reset: '', // not needed in browser
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// get the name of the machine useed to connect
|
||||||
|
const machineHostName = window.location.hostname;
|
||||||
|
console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let __socket: Socket | undefined = undefined;
|
let __socket: Socket | undefined = undefined;
|
||||||
document.addEventListener('ft:pageChange', () => {
|
document.addEventListener('ft:pageChange', () => {
|
||||||
if (__socket !== undefined)
|
if (__socket !== undefined)
|
||||||
|
|
@ -15,8 +30,10 @@ document.addEventListener('ft:pageChange', () => {
|
||||||
|
|
||||||
|
|
||||||
function getSocket(): Socket {
|
function getSocket(): Socket {
|
||||||
|
let addressHost = `wss://${machineHostName}:8888`;
|
||||||
if (__socket === undefined)
|
if (__socket === undefined)
|
||||||
__socket = io("wss://localhost:8888", {
|
|
||||||
|
__socket = io(addressHost, {
|
||||||
path: "/api/chat/socket.io/",
|
path: "/api/chat/socket.io/",
|
||||||
secure: false,
|
secure: false,
|
||||||
transports: ["websocket"],
|
transports: ["websocket"],
|
||||||
|
|
@ -31,17 +48,11 @@ async function isLoggedIn() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
|
|
||||||
let socket = getSocket();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener("visibilitychange", async () => {
|
|
||||||
|
|
||||||
|
async function windowStateHidden() {
|
||||||
const socketId = __socket || undefined;
|
const socketId = __socket || undefined;
|
||||||
let oldName = localStorage.getItem("oldName") || undefined;
|
let oldName = localStorage.getItem("oldName") || undefined;
|
||||||
if (socketId == undefined) return;
|
if (socketId == undefined) return;
|
||||||
if (document.visibilityState === "hidden") {
|
|
||||||
let userName = await updateUser();
|
let userName = await updateUser();
|
||||||
oldName = userName?.name || undefined;
|
oldName = userName?.name || undefined;
|
||||||
if (oldName === undefined) return;
|
if (oldName === undefined) return;
|
||||||
|
|
@ -51,8 +62,13 @@ document.addEventListener("visibilitychange", async () => {
|
||||||
why: 'tab window hidden - socket not dead',
|
why: 'tab window hidden - socket not dead',
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (document.visibilityState === "visible") {
|
|
||||||
|
|
||||||
|
async function windowStateVisable() {
|
||||||
|
const socketId = __socket || undefined;
|
||||||
|
let oldName = localStorage.getItem("oldName") || undefined;
|
||||||
|
if (socketId == undefined) return;
|
||||||
const res = await client.guestLogin();
|
const res = await client.guestLogin();
|
||||||
let user = await updateUser();
|
let user = await updateUser();
|
||||||
socketId.emit('client_entered', {
|
socketId.emit('client_entered', {
|
||||||
|
|
@ -61,8 +77,59 @@ document.addEventListener("visibilitychange", async () => {
|
||||||
});
|
});
|
||||||
setTitle('Chat Page');
|
setTitle('Chat Page');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
|
||||||
|
let socket = getSocket();
|
||||||
|
|
||||||
|
|
||||||
|
// document.addEventListener("visibilitychange", async () => {
|
||||||
|
|
||||||
|
// const socketId = __socket || undefined;
|
||||||
|
// let oldName = localStorage.getItem("oldName") || undefined;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if (socketId == undefined) return;
|
||||||
|
// if (document.visibilityState === "hidden") {
|
||||||
|
// let userName = await updateUser();
|
||||||
|
// oldName = userName?.name || undefined;
|
||||||
|
// if (oldName === undefined) return;
|
||||||
|
// localStorage.setItem('oldName', oldName);
|
||||||
|
// socketId.emit('client_left', {
|
||||||
|
// user: userName?.name,
|
||||||
|
// why: 'tab window hidden - socket not dead',
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if (document.visibilityState === "visible") {
|
||||||
|
// const res = await client.guestLogin();
|
||||||
|
// let user = await updateUser();
|
||||||
|
// socketId.emit('client_entered', {
|
||||||
|
// userName: oldName,
|
||||||
|
// user: user?.name,
|
||||||
|
// });
|
||||||
|
// setTitle('Chat Page');
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -133,11 +200,7 @@ document.addEventListener("visibilitychange", async () => {
|
||||||
const value = await client.chatTest();
|
const value = await client.chatTest();
|
||||||
if (value.kind === "success") {
|
if (value.kind === "success") {
|
||||||
console.log(value.payload);
|
console.log(value.payload);
|
||||||
} else if (value.kind === "notLoggedIn") {
|
|
||||||
console.log('not logged in');
|
|
||||||
} else {
|
|
||||||
console.log('unknown response: ', value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const addMessage = (text: string) => {
|
const addMessage = (text: string) => {
|
||||||
|
|
@ -147,8 +210,20 @@ document.addEventListener("visibilitychange", async () => {
|
||||||
chatWindow.appendChild(messageElement);
|
chatWindow.appendChild(messageElement);
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
console.log(`Added new message: ${text}`)
|
console.log(`Added new message: ${text}`)
|
||||||
|
return ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (window.location.pathname === "/app/chat") {
|
||||||
|
window.addEventListener("focus", () => {
|
||||||
|
windowStateVisable();
|
||||||
|
console.log("%cWindow is focused on /chat", color.green);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("blur", () => {
|
||||||
|
windowStateHidden();
|
||||||
|
console.log("%cWindow is not focused on /chat", color.red);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
socket.once('welcome', (data) => {
|
socket.once('welcome', (data) => {
|
||||||
addMessage (`${data.msg} ` + getUser()?.name);
|
addMessage (`${data.msg} ` + getUser()?.name);
|
||||||
|
|
@ -253,6 +328,19 @@ document.addEventListener("visibilitychange", async () => {
|
||||||
showError('Failed to login: Unknown error');
|
showError('Failed to login: Unknown error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else if (value.kind === "notLoggedIn") {
|
||||||
|
|
||||||
|
if (!chatWindow) return;
|
||||||
|
const messageElement = document.createElement('div-notlog');
|
||||||
|
messageElement.textContent = "Not Logged in ....";
|
||||||
|
chatWindow.appendChild(messageElement);
|
||||||
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
|
console.log('not logged in');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log('unknown response: ', value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,22 @@ import * as swagger from '@shared/swagger';
|
||||||
import * as utils from '@shared/utils';
|
import * as utils from '@shared/utils';
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
|
|
||||||
|
// colors for console.log
|
||||||
|
export const color = {
|
||||||
|
red: '\x1b[31m',
|
||||||
|
green: '\x1b[32m',
|
||||||
|
yellow: '\x1b[33m',
|
||||||
|
blue: '\x1b[34m',
|
||||||
|
reset: '\x1b[0m',
|
||||||
|
};
|
||||||
|
|
||||||
|
// shows address for connection au server transcendance
|
||||||
|
const session = process.env.SESSION_MANAGER ?? '';
|
||||||
|
const part = session.split('/')[1];
|
||||||
|
const machineName = part.split('.')[0];
|
||||||
|
console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login');
|
||||||
|
|
||||||
|
|
||||||
declare const __SERVICE_NAME: string;
|
declare const __SERVICE_NAME: string;
|
||||||
|
|
||||||
// Global map of clients
|
// Global map of clients
|
||||||
|
|
@ -52,13 +68,6 @@ const app: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||||
export default app;
|
export default app;
|
||||||
export { app };
|
export { app };
|
||||||
|
|
||||||
export const color = {
|
|
||||||
red: '\x1b[31m',
|
|
||||||
green: '\x1b[32m',
|
|
||||||
yellow: '\x1b[33m',
|
|
||||||
blue: '\x1b[34m',
|
|
||||||
reset: '\x1b[0m',
|
|
||||||
};
|
|
||||||
|
|
||||||
type ClientMessage = {
|
type ClientMessage = {
|
||||||
user: string;
|
user: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue