fix: minor oopsy in the rebase
This commit is contained in:
parent
317c8b62bf
commit
a65b8a9067
2 changed files with 3 additions and 162 deletions
|
|
@ -48,165 +48,6 @@ export function getSocket(): Socket {
|
||||||
return __socket;
|
return __socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) {
|
|
||||||
profil.SenderName = getUser()?.name ?? '';
|
|
||||||
if (profil.SenderName === profil.user) return;
|
|
||||||
addMessage(`You invited to play: ${profil.user}🏓`)
|
|
||||||
senderSocket.emit('inviteGame', JSON.stringify(profil));
|
|
||||||
};
|
|
||||||
|
|
||||||
function actionBtnPopUpInvite(invite: ClientProfil, senderSocket: Socket) {
|
|
||||||
setTimeout(() => {
|
|
||||||
const InvitePongBtn = document.querySelector("#popup-b-invite");
|
|
||||||
InvitePongBtn?.addEventListener("click", () => {
|
|
||||||
inviteToPlayPong(invite, senderSocket);
|
|
||||||
});
|
|
||||||
}, 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
async function windowStateVisable() {
|
|
||||||
|
|
||||||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
|
||||||
const socketId = __socket || undefined;
|
|
||||||
let oldName = localStorage.getItem("oldName") || undefined;
|
|
||||||
|
|
||||||
if (socketId === undefined || oldName === undefined) {return;};
|
|
||||||
let user = await updateUser();
|
|
||||||
if(user === null) return;
|
|
||||||
socketId.emit('client_entered', {
|
|
||||||
userName: oldName,
|
|
||||||
user: user?.name,
|
|
||||||
});
|
|
||||||
buddies.innerHTML = '';
|
|
||||||
buddies.textContent = '';
|
|
||||||
setTitle('Chat Page');
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
function parseCmdMsg(msgText: string): string[] | undefined {
|
|
||||||
|
|
||||||
if (!msgText?.trim()) return;
|
|
||||||
msgText = msgText.trim();
|
|
||||||
const command: string[] = ['', ''];
|
|
||||||
if (!msgText.startsWith('@')) {
|
|
||||||
command[0] = '@msg';
|
|
||||||
command[1] = msgText;
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
const noArgCommands = ['@quit', '@help', '@cls'];
|
|
||||||
if (noArgCommands.includes(msgText)) {
|
|
||||||
command[0] = msgText;
|
|
||||||
command[1] = '';
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ArgCommands = ['@profile', '@block'];
|
|
||||||
const userName = msgText.indexOf(" ");
|
|
||||||
const cmd2 = msgText.slice(0, userName).trim() ?? "";
|
|
||||||
const user = msgText.slice(userName + 1).trim();
|
|
||||||
if (ArgCommands.includes(cmd2)) {
|
|
||||||
command[0] = cmd2;
|
|
||||||
command[1] = user;
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
const colonIndex = msgText.indexOf(":");
|
|
||||||
if (colonIndex === -1) {
|
|
||||||
command[0] = msgText;
|
|
||||||
command[1] = '';
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
const cmd = msgText.slice(0, colonIndex).trim();
|
|
||||||
const rest = msgText.slice(colonIndex + 1).trim();
|
|
||||||
command[0] = cmd;
|
|
||||||
command[1] = rest;
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitSocketConnected(socket: Socket): Promise<void> {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (socket.connected) return resolve();
|
|
||||||
socket.on("connect", () => resolve());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function quitChat (socket: Socket) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
const systemWindow = document.getElementById('system-box') as HTMLDivElement;
|
|
||||||
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
|
||||||
if (socket) {
|
|
||||||
logout(socket);
|
|
||||||
setTitle('Chat Page');
|
|
||||||
connected(socket);
|
|
||||||
} else {
|
|
||||||
getSocket();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showError('Failed to Quit Chat: Unknown error');
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function logout(socket: Socket) {
|
|
||||||
socket.emit("logout"); // notify server
|
|
||||||
socket.disconnect(); // actually close the socket
|
|
||||||
localStorage.clear();
|
|
||||||
if (__socket !== undefined)
|
|
||||||
__socket.close();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async function connected(socket: Socket): Promise<void> {
|
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
try {
|
|
||||||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
|
||||||
const loggedIn = isLoggedIn();
|
|
||||||
if (!loggedIn) throw('Not Logged in');
|
|
||||||
let oldUser = localStorage.getItem("oldName") ?? "";
|
|
||||||
if (loggedIn?.name === undefined) {return ;};
|
|
||||||
oldUser = loggedIn.name ?? "";
|
|
||||||
// const res = await client.guestLogin();
|
|
||||||
let user = await updateUser();
|
|
||||||
localStorage.setItem("oldName", oldUser);
|
|
||||||
buddies.textContent = "";
|
|
||||||
socket.emit('list', {
|
|
||||||
oldUser: oldUser,
|
|
||||||
user: user?.name,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
showError('Failed to login: Unknown error');
|
|
||||||
}
|
|
||||||
}, 16);
|
|
||||||
};
|
|
||||||
|
|
||||||
let count = 0;
|
|
||||||
function incrementCounter(): number {
|
|
||||||
count += 1;
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function openMessagePopup(message: any) {
|
|
||||||
|
|
||||||
const modalmessage = document.getElementById("modal-message") ?? null;
|
|
||||||
if(!message) return
|
|
||||||
const obj = message;
|
|
||||||
if (modalmessage) {
|
|
||||||
const messageElement = document.createElement("div");
|
|
||||||
messageElement.innerHTML = `
|
|
||||||
<div class="profile-info"
|
|
||||||
<div id="profile-about">Next Game Message ${incrementCounter()}: ${obj.nextGame}</div>
|
|
||||||
</div>`;
|
|
||||||
modalmessage.appendChild(messageElement);
|
|
||||||
modalmessage.scrollTop = modalmessage.scrollHeight;
|
|
||||||
|
|
||||||
}
|
|
||||||
const gameMessage = document.getElementById("game-modal") ?? null;
|
|
||||||
if (gameMessage) {
|
|
||||||
gameMessage.classList.remove("hidden");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
|
function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn {
|
||||||
let socket = getSocket();
|
let socket = getSocket();
|
||||||
let blockMessage: boolean;
|
let blockMessage: boolean;
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@ import { incrementCounter } from "./incrementCounter";
|
||||||
// return count;
|
// return count;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export async function openMessagePopup(message: string) {
|
export async function openMessagePopup(message: any) {
|
||||||
|
|
||||||
const modalmessage = document.getElementById("modal-message") ?? null;
|
const modalmessage = document.getElementById("modal-message") ?? null;
|
||||||
if(!message) return
|
if(!message) return
|
||||||
const obj = JSON.parse(message);
|
const obj = message;
|
||||||
if (modalmessage) {
|
if (modalmessage) {
|
||||||
const messageElement = document.createElement("div");
|
const messageElement = document.createElement("div");
|
||||||
messageElement.innerHTML = `
|
messageElement.innerHTML = `
|
||||||
<div id="profile-about">Next Game Message ${incrementCounter()}: ${obj.link}</div>
|
<div id="profile-about">Next Game Message ${incrementCounter()}: ${obj.nextGame}</div>
|
||||||
`;
|
`;
|
||||||
modalmessage.appendChild(messageElement);
|
modalmessage.appendChild(messageElement);
|
||||||
modalmessage.scrollTop = modalmessage.scrollHeight;
|
modalmessage.scrollTop = modalmessage.scrollHeight;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue