Browse Source

socket fix and chat routing

master
Pheuw1 2 years ago
parent
commit
3fa6755eed
  1. 9
      back/volume/src/chat/chat.gateway.ts
  2. 15
      front/volume/src/components/Channels.svelte
  3. 36
      front/volume/src/components/Chat.svelte

9
back/volume/src/chat/chat.gateway.ts

@ -42,7 +42,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async handleConnection (socket: Socket): Promise<void> {}
async handleDisconnect (socket: Socket): Promise<void> {}
async handleDisconnect (socket: Socket): Promise<void> {
console.log('socket %s has disconnected', socket.id)
}
@SubscribeMessage('joinChannel')
async onJoinChannel (socket: Socket, connect: ConnectionDto): Promise<void> {
@ -135,7 +137,10 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const connect = (await this.connectedUserRepository.findOneBy({
user: user.id
})) as ConnectedUser
await this.onLeaveChannel(socket)
// await this.onLeaveChannel(socket)
await this.server.sockets.sockets
.get(connect.socket)
?.leave(channel.id.toString())
this.server.sockets.sockets.get(connect.socket)?.disconnect()
}
}

15
front/volume/src/components/Channels.svelte

@ -238,7 +238,7 @@
<div class="channels" on:click|stopPropagation on:keydown|stopPropagation>
<div>
{#if channels.length > 0}
<h2>Channels <button style="margin-right :auto;" on:click={() => getChannels()}>🔄</button> </h2>
<h2 >Channels <button class="refresh" on:click={() => getChannels()}>🔄</button> </h2>
{#each channels as channel}
<li>
<span>{channel.name} : {channel.id}</span>
@ -352,6 +352,19 @@
font-size: 100%;
}
.refresh {
display: inline-block;
background-color: rgb(187, 187, 187);
color: #a0a0a0;
border: none;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
outline: none;
position:relative;
top:-10px;
right:auto
}
.button {
background-color: #6b8e23;
color: #ffffff;

36
front/volume/src/components/Chat.svelte

@ -56,7 +56,6 @@
socket.disconnect();
});
//--------------------------------------------------------------------------------/
const sendMessage = () => {
@ -140,8 +139,8 @@
body: JSON.stringify({ id: target.ftId }),
});
}
if (response.ok) show_popup("User blocked", false);
else show_popup("Failed to block user", false);
if (response.ok) await show_popup("User blocked", false);
else await show_popup("Failed to block user", false);
};
//--------------------------------------------------------------------------------/
@ -164,11 +163,9 @@
},
body: JSON.stringify({ data: [target.ftId, duration]}),
});
socket.emit("kickUser", channel.id, $store.ftId, target.ftId);
socket.emit("kickUser", channel.id, $store.ftId, target.ftId)
dispatch("return-home");
}
if (response.ok) {
show_popup("User banned", false);
} else show_popup("Failed to ban user", false);
};
//--------------------------------------------------------------------------------/
@ -190,8 +187,8 @@
body: JSON.stringify({ id: target.ftId }),
});
}
if (response.ok) show_popup("User unbanned",false);
else show_popup("Failed to unban user",false);
if (response.ok) await show_popup("User unbanned",false);
else await show_popup("Failed to unban user",false);
};
//--------------------------------------------------------------------------------/
@ -204,7 +201,8 @@
if (response.ok) {
const target = await response.json();
socket.emit("kickUser", {chan : channel.id, from : $store.ftId, to: target.ftId});
} else {show_popup("merde",false)}
dispatch("return-home");
} else {await show_popup("merde",false)}
};
//--------------------------------------------------------------------------------/
@ -227,8 +225,8 @@
body: JSON.stringify({ data: [target.ftId, +prompt] }),
});
}
if (response.ok) show_popup("User muted",false);
else show_popup("Failed to mute user",false);
if (response.ok) await show_popup("User muted",false);
else await show_popup("Failed to mute user",false);
};
//--------------------------------------------------------------------------------/
@ -251,9 +249,9 @@
});
}
if (response.ok) {
show_popup("User admined",false);
await show_popup("User admined",false);
} else {
show_popup("Failed to admin user",false);
await show_popup("Failed to admin user",false);
}
};
@ -277,9 +275,9 @@
});
}
if (response.ok) {
show_popup("User admined", false);
await show_popup("User admined", false);
} else {
show_popup("Failed to admin user", false);
await show_popup("Failed to admin user", false);
}
};
@ -288,10 +286,10 @@
const leaveChannel = async () => {
await show_popup("Press \"Okay\" to leave this channel?", false);
if ($content == 'ok') {
socket.emit("LeaveChanel", async (response) => {
console.log(response.status);
socket.emit("leaveChannel");
dispatch("return-home");
});
socket.disconnect()
}
}
function onSendMessage() {

Loading…
Cancel
Save