Chat box can be called from F1 and buttons for Games History now in another look
This commit is contained in:
parent
46113553a1
commit
85065d8bb3
5 changed files with 103 additions and 20 deletions
|
|
@ -38,13 +38,14 @@
|
||||||
|
|
||||||
.btn-style-games {
|
.btn-style-games {
|
||||||
@apply
|
@apply
|
||||||
w-35
|
w-40
|
||||||
h-8
|
h-8
|
||||||
border
|
border
|
||||||
border-gray-500
|
border-gray-500
|
||||||
rounded-3xl
|
rounded-3xl
|
||||||
bg-gray-500
|
bg-white
|
||||||
text-white
|
text-blue-800
|
||||||
|
underline underline-offset-4
|
||||||
cursor-pointer
|
cursor-pointer
|
||||||
shadow-[0_2px_0_0_black]
|
shadow-[0_2px_0_0_black]
|
||||||
transition-all
|
transition-all
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import { openMessagePopup } from "./chatHelperFunctions/openMessagePopup";
|
||||||
import { windowStateVisable } from "./chatHelperFunctions/windowStateVisable";
|
import { windowStateVisable } from "./chatHelperFunctions/windowStateVisable";
|
||||||
import { cmdList } from "./chatHelperFunctions/cmdList";
|
import { cmdList } from "./chatHelperFunctions/cmdList";
|
||||||
import { actionBtnTTTGames } from "./chatHelperFunctions/actionBtnTTTGames";
|
import { actionBtnTTTGames } from "./chatHelperFunctions/actionBtnTTTGames";
|
||||||
|
import { showError } from "@app/toast";
|
||||||
|
|
||||||
const MAX_SYSTEM_MESSAGES = 10;
|
const MAX_SYSTEM_MESSAGES = 10;
|
||||||
let inviteMsgFlag: boolean = false;
|
let inviteMsgFlag: boolean = false;
|
||||||
|
|
@ -81,9 +82,72 @@ const sendtextbox = document.getElementById(
|
||||||
) as HTMLButtonElement;
|
) as HTMLButtonElement;
|
||||||
const systemWindow = document.getElementById("chat-system-box") as HTMLDivElement;
|
const systemWindow = document.getElementById("chat-system-box") as HTMLDivElement;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const keysPressed: Record<string, boolean> = {};
|
||||||
|
async function chatKeyToggle() {
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
// if (keysPressed[event.code]) {keysPressed[event.key.toLowerCase()] = false; chatBox.classList.remove("hidden"); return};
|
||||||
|
if (event.repeat) {keysPressed[event.key.toLowerCase()] = false; chatBox.classList.remove("hidden"); return};
|
||||||
|
keysPressed[event.key.toLowerCase()] = true;
|
||||||
|
});
|
||||||
|
document.addEventListener("keyup", (event) => {
|
||||||
|
keysPressed[event.key.toLowerCase()] = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
setInterval( () => {
|
||||||
|
if(keysPressed['f1'] === true) {
|
||||||
|
if (chatBox.classList.contains("hidden")) {
|
||||||
|
chatBox.classList.remove("hidden");
|
||||||
|
overlay.classList.add("opacity-60");
|
||||||
|
chatMessageIn?.classList.add("hidden");
|
||||||
|
chatMessageIn!.textContent = '';
|
||||||
|
sendtextbox.focus();
|
||||||
|
} else {
|
||||||
|
overlay.classList.remove("opacity-60");
|
||||||
|
chatBox.classList.add("hidden");
|
||||||
|
overlay.classList.remove("opacity-60");
|
||||||
|
chatMessageIn?.classList.add("hidden");
|
||||||
|
chatMessageIn!.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(keysPressed['t'] === false) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}, 1000/10);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function initChatSocket() {
|
function initChatSocket() {
|
||||||
let socket = getSocket();
|
let socket = getSocket();
|
||||||
let blockMessage: boolean;
|
// let blockMessage: boolean;
|
||||||
|
if (
|
||||||
|
!chatBox ||
|
||||||
|
!chatMessageIn ||
|
||||||
|
!bquit ||
|
||||||
|
!buttonMessage ||
|
||||||
|
!buttonPro ||
|
||||||
|
!chatButton ||
|
||||||
|
!chatWindow ||
|
||||||
|
!clearText ||
|
||||||
|
!gameMessage ||
|
||||||
|
!myGames ||
|
||||||
|
!myTTTGames ||
|
||||||
|
!modalmessage ||
|
||||||
|
!noGuest ||
|
||||||
|
!notify ||
|
||||||
|
!overlay ||
|
||||||
|
!profilList ||
|
||||||
|
!sendButton ||
|
||||||
|
!sendtextbox ||
|
||||||
|
!systemWindow
|
||||||
|
|
||||||
|
) return showError("fatal error");
|
||||||
|
|
||||||
// Listen for the 'connect' event
|
// Listen for the 'connect' event
|
||||||
socket.on("connect", async () => {
|
socket.on("connect", async () => {
|
||||||
await waitSocketConnected(socket);
|
await waitSocketConnected(socket);
|
||||||
|
|
@ -125,7 +189,7 @@ function initChatSocket() {
|
||||||
});
|
});
|
||||||
chatMessageIn?.classList.add("hidden");
|
chatMessageIn?.classList.add("hidden");
|
||||||
|
|
||||||
|
chatKeyToggle();
|
||||||
// Listen for messages from the server "MsgObjectServer"
|
// Listen for messages from the server "MsgObjectServer"
|
||||||
socket.on("MsgObjectServer", (data: { message: ClientMessage }) => {
|
socket.on("MsgObjectServer", (data: { message: ClientMessage }) => {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
|
|
@ -165,12 +229,12 @@ function initChatSocket() {
|
||||||
if (systemWindow && data.message.destination === "system-info") {
|
if (systemWindow && data.message.destination === "system-info") {
|
||||||
const messageElement = document.createElement("div");
|
const messageElement = document.createElement("div");
|
||||||
messageElement.textContent = `${data.message.user}: ${data.message.text}`;
|
messageElement.textContent = `${data.message.user}: ${data.message.text}`;
|
||||||
systemWindow.appendChild(messageElement);
|
|
||||||
|
|
||||||
// keep only last 10
|
// keep only last 10
|
||||||
while (systemWindow.children.length > MAX_SYSTEM_MESSAGES) {
|
while (systemWindow.children.length > MAX_SYSTEM_MESSAGES) {
|
||||||
systemWindow.removeChild(systemWindow.firstChild!);
|
systemWindow.removeChild(systemWindow.firstChild!);
|
||||||
}
|
}
|
||||||
|
systemWindow.appendChild(messageElement);
|
||||||
systemWindow.scrollTop = systemWindow.scrollHeight;
|
systemWindow.scrollTop = systemWindow.scrollHeight;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -205,9 +269,11 @@ function initChatSocket() {
|
||||||
if (blockUserBtn) {
|
if (blockUserBtn) {
|
||||||
let message = "";
|
let message = "";
|
||||||
if (data.userState === "block") {
|
if (data.userState === "block") {
|
||||||
((message = "un-block"), (blockMessage = true));
|
(message = "un-block");
|
||||||
|
// ((message = "un-block"), (blockMessage = true));
|
||||||
} else {
|
} else {
|
||||||
((message = "block"), (blockMessage = false));
|
// ((message = "block"), (blockMessage = false));
|
||||||
|
(message = "block");
|
||||||
}
|
}
|
||||||
blockUserBtn.textContent = message;
|
blockUserBtn.textContent = message;
|
||||||
}
|
}
|
||||||
|
|
@ -465,7 +531,7 @@ chatButton!.addEventListener("click",() => {
|
||||||
connected(socket);
|
connected(socket);
|
||||||
chatMessageIn?.classList.add("hidden");
|
chatMessageIn?.classList.add("hidden");
|
||||||
chatMessageIn!.textContent = '';
|
chatMessageIn!.textContent = '';
|
||||||
|
sendtextbox.focus();
|
||||||
} else {
|
} else {
|
||||||
chatBox.classList.toggle("hidden");
|
chatBox.classList.toggle("hidden");
|
||||||
overlay.classList.remove("opacity-60");
|
overlay.classList.remove("opacity-60");
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export function cmdList() {
|
||||||
addMessage('\'@quit\' - disconnect user from the chat');
|
addMessage('\'@quit\' - disconnect user from the chat');
|
||||||
addMessage('\'@pong\' - displays your pong match results');
|
addMessage('\'@pong\' - displays your pong match results');
|
||||||
addMessage('\'@ttt\' - displays your ttt match results');
|
addMessage('\'@ttt\' - displays your ttt match results');
|
||||||
|
addMessage('\'F1\' - chat box display toggles on / off');
|
||||||
addMessage('** *********************************** **');
|
addMessage('** *********************************** **');
|
||||||
addMessage('*');
|
addMessage('*');
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ export async function openProfilePopup(profil: ClientProfil) {
|
||||||
<button id="popup-b-invite" class="btn-style popup-b-invite">U Game ?</button>
|
<button id="popup-b-invite" class="btn-style popup-b-invite">U Game ?</button>
|
||||||
<button id="popup-b-block" class="btn-style popup-b-block">Block User</button>
|
<button id="popup-b-block" class="btn-style popup-b-block">Block User</button>
|
||||||
<div id="profile-about" class="text-2xl">About: <span class="recessed">${profil.text}</span> </div>
|
<div id="profile-about" class="text-2xl">About: <span class="recessed">${profil.text}</span> </div>
|
||||||
<button id="popup-b-hGame" class="btn-style-games popup-b-game">My Pong Games</button>
|
<button id="popup-b-hGame" class="btn-style-games popup-b-game">Your Pong Games</button>
|
||||||
<button id="popup-b-hTGame" class="btn-style-games popup-b-TTTgame">My TTT Games</button>
|
<button id="popup-b-hTGame" class="btn-style-games popup-b-TTTgame">My TTT Games</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,20 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
|
socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
|
||||||
broadcast(fastify, obj, obj.SenderWindowID);
|
broadcast(fastify, obj, obj.SenderWindowID);
|
||||||
fastify.log.info(`Client connected: ${socket.id}`);
|
fastify.log.info(`Client connected: ${socket.id}`);
|
||||||
|
const clientInfo = clientChat.get(socket.id);
|
||||||
|
const clientName = clientInfo?.user;
|
||||||
|
|
||||||
|
if (!clientName) return;
|
||||||
|
const connectionMsg: ClientMessage = {
|
||||||
|
command: '',
|
||||||
|
destination: 'system-info',
|
||||||
|
type: 'chat' as const,
|
||||||
|
user: clientName,
|
||||||
|
text: 'is connected au server',
|
||||||
|
timestamp: Date.now(),
|
||||||
|
SenderWindowID: socket.id,
|
||||||
|
};
|
||||||
|
broadcast(fastify, connectionMsg, socket.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
list_SocketListener(fastify, socket);
|
list_SocketListener(fastify, socket);
|
||||||
|
|
@ -355,4 +369,5 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue