Add online/disconnect color on Search, not finish

This commit is contained in:
2024-01-11 17:34:00 +01:00
parent 56d352fead
commit 4c114a34df
6 changed files with 230 additions and 7 deletions

View File

@ -0,0 +1,87 @@
class Notice {
constructor(client) {
this.client = client;
this.connect();
this.online_users_setter = undefined;
this.online_users = {};
await client.notice.getOnlineUser(
async (content) => {
this.online_users = content;
this.rewrite_usernames(profiles);
}
)
}
async connect() {
let url = `${window.location.protocol[4] === 's' ? 'wss' : 'ws'}://${window.location.host}/ws/chat/notice`;
this.chatSocket = new WebSocket(url);
this.chatSocket.onmessage = (event) =>{
let data = JSON.parse(event.data);
console.log("invite");
//console.log("notice: ", data);
if (data.type == "invite")
this.receiveInvite(data);
else if (data.type == "online_user")
this.receiveOnlineUser(data);
}
}
async disconnect() {
if (this.chatSocket == undefined)
this.chatSocket.close();
}
async sendInvite(id_inviter, id_inviteds) {
if (this.chatSocket == undefined)
return;
this.chatSocket.send(JSON.stringify({
type: "invite",
targets: id_inviteds,
}));
}
async receiveInvite(data) {
if (data.content === "notice return") {
if (data.status == 200)
return
// Notification pour dire que la notif a été bien envoyé
else if (data.status == 404)
return
// Pas connecté
}
else {
// Géré la reception de l'invitation
}
}
async getOnlineUser(online_users_setter) {
if (this.chatSocket == undefined)
return;
this.online_users_setter = online_users_setter;
this.chatSocket.send(JSON.stringify({
type: "online_user",
targets: "all",
}));
}
async receiveOnlineUser(data) {
console.log("receiveOnlineUser");
if (data.content !== undefined &&
this.online_users_setter !== undefined) {
this.online_users_setter(data.content);
}
}
}
export {Notice}

View File

@ -5,6 +5,7 @@ import { Channels } from './chat/channels.js';
import { MyProfile } from "./MyProfile.js";
import { navigateTo } from "../index.js"
import { Tourmanents } from "./tournament/tournaments.js";
import {Notice} from "./chat/notice.js"
function getCookie(name)
{
@ -29,6 +30,8 @@ class Client
this.channels = new Channels(this);
this.channel = undefined;
this.notice = new Notice(this);
}
async isAuthentificate()