diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/Project.iml b/.idea/Project.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/.idea/Project.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..5055868
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..03d9549
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..74f1bcb
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/prettier.xml b/.idea/prettier.xml
new file mode 100644
index 0000000..b0c1c68
--- /dev/null
+++ b/.idea/prettier.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..d843f34
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/routes/chats/[id]/+page.svelte b/src/routes/chats/[id]/+page.svelte
index dbed15f..2b7b5f9 100644
--- a/src/routes/chats/[id]/+page.svelte
+++ b/src/routes/chats/[id]/+page.svelte
@@ -5,6 +5,7 @@
import Message from "$lib/components/Message.svelte";
import UserChat from '$lib/components/ui/UserChat.svelte';
import { onMount, tick } from 'svelte';
+ import { initSocket } from '$lib/stores/socket';
export let data;
export let messages = data.messages.messages;
@@ -12,6 +13,13 @@
let messageText = '';
+ let socket = initSocket(); // Initialiser le socket
+
+ socket.on("new-message", (message) => {
+ console.log('Recu du nouveau message', message);
+ messages = [...messages , message ];
+ console.log(messages);
+ });
async function sendMessage() {
// Appel API pour envoyer le message
const response = await fetch(`/api/channels/${data.channelId}/messages`, {
@@ -23,9 +31,12 @@
});
if (response.ok) {
- messageText = '';
+ let newMessage =await response.json();
+
// Envoyer le message avec les sockets (à implémenter)
+ socket.emit('new-message', newMessage);
console.log('Message envoyé avec succès');
+ messageText = '';
}else{
console.log('Erreur lors de l\'envoi du message');
}
diff --git a/vite.config.ts b/vite.config.ts
index 042f8a7..83cdb8e 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -14,6 +14,10 @@ const webSocketServer = {
socket.on('new-channel', (channel) => {
io.emit('new-channel', channel)
});
+ socket.on('new-message', (message) => {
+ console.log('Diffudion du nouveau message', message,"<= ici");
+ io.emit('new-message', message)
+ });
});
}
}