Browse Source

front

master
Pheuw1 2 years ago
parent
commit
0ca8b2eab8
  1. 5
      back/volume/src/chat/chat.gateway.ts
  2. 4
      front/volume/src/components/Channels.svelte
  3. 9
      front/volume/src/components/Chat.svelte

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

@ -38,6 +38,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async handleDisconnect (socket: Socket): Promise<void> {
await this.onLeaveChannel(socket)
socket.disconnect()
}
@SubscribeMessage('joinChannel')
@ -84,7 +85,6 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async onLeaveChannel (socket: Socket): Promise<void> {
const id = socket.id as any
await this.connectedUserRepository.delete({ socket: id })
socket.disconnect()
}
@SubscribeMessage('addMessage')
@ -99,7 +99,8 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const createdMessage: Message = await this.messageService.createMessage(
message
)
socket.in(channel.toString()).emit('newMessage', createdMessage)
console.log(createdMessage)
socket.in(channel.id.toString()).emit('newMessage', createdMessage)
}
@SubscribeMessage('kickUser')

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

@ -187,9 +187,11 @@
on:keydown={() => removeChannel(_channels.id)}>🗑️</button
>
<button on:click={() => inviteChannel(_channels.id)}>🤝</button>
{#if _channels.isPrivate}
<button on:click={() => changePassword(_channels.id)}
>Edit Password</button
>
{/if}
</div>
</li>{/each}
{:else}
@ -227,7 +229,7 @@
}
.channels {
background-color: #5f5e5e;
background-color: #343a40;
border: 1px solid #dedede;
border-radius: 5px;
padding: 1rem;

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

@ -29,14 +29,15 @@
});
socket.on("newMessage", (msg: chatMessagesType) => {
console.log(msg)
chatMessages = [...chatMessages, msg];
});
onDestroy(() => {
io.emit("LeaveChanel", async (response) => {
socket.emit("LeaveChanel", async (response) => {
console.log(response.status);
});
io.disconnect();
socket.disconnect();
});
//--------------------------------------------------------------------------------/
@ -378,9 +379,9 @@
justify-content: center;
align-items: center;
}
.chat {
background-color: #5f5e5e;
background-color: #343a40;
border: 1px solid #dedede;
border-radius: 5px;
padding: 1rem;

Loading…
Cancel
Save