Move file tournament; chat can see who is online
This commit is contained in:
@ -3,14 +3,6 @@ class Notice {
|
||||
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() {
|
||||
@ -19,18 +11,26 @@ class 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")
|
||||
else if (data.type == "online_users" || data.type == "disconnect")
|
||||
this.receiveOnlineUser(data);
|
||||
}
|
||||
this.chatSocket.onopen = (event) => {
|
||||
this.online_users = {};
|
||||
this.getOnlineUser();
|
||||
}
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
if (this.chatSocket == undefined)
|
||||
this.chatSocket.close();
|
||||
|
||||
this.chatSocket.send(JSON.stringify({
|
||||
type: "online_users",
|
||||
targets: "all",
|
||||
}));
|
||||
}
|
||||
|
||||
async sendInvite(id_inviter, id_inviteds) {
|
||||
@ -60,26 +60,23 @@ class Notice {
|
||||
}
|
||||
}
|
||||
|
||||
async getOnlineUser(online_users_setter) {
|
||||
async getOnlineUser() {
|
||||
|
||||
if (this.chatSocket == undefined)
|
||||
return;
|
||||
|
||||
this.online_users_setter = online_users_setter;
|
||||
|
||||
this.chatSocket.send(JSON.stringify({
|
||||
type: "online_user",
|
||||
type: "online_users",
|
||||
targets: "all",
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
async receiveOnlineUser(data) {
|
||||
console.log("receiveOnlineUser");
|
||||
if (data.content !== undefined &&
|
||||
this.online_users_setter !== undefined) {
|
||||
|
||||
this.online_users_setter(data.content);
|
||||
if (data.content !== undefined) {
|
||||
this.online_users = data.content;
|
||||
if (this.rewrite_usernames !== undefined)
|
||||
this.rewrite_usernames();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user