From 315cb16b6b6556fe1c734e01ab1ab285b7e8316f Mon Sep 17 00:00:00 2001 From: Whykioh Date: Thu, 30 Apr 2026 14:06:19 +0200 Subject: [PATCH] initial commit --- client/src/App.jsx | 60 ++++++++++++++++++++++++++++++++++++++++++++++ server/index.js | 13 ++++++++++ 2 files changed, 73 insertions(+) create mode 100644 client/src/App.jsx create mode 100644 server/index.js diff --git a/client/src/App.jsx b/client/src/App.jsx new file mode 100644 index 0000000..47e8a3e --- /dev/null +++ b/client/src/App.jsx @@ -0,0 +1,60 @@ +import { useState, useEffect } from 'react'; +import io from 'socket.io-client'; + +const socket = io('http://chat.viensonjette.fr'); // Ton URL de reverse proxy + +function App() { + const [user, setUser] = useState(null); + const [form, setForm] = useState({ pseudo: '', age: '', city: '', rooms: ['general'] }); + + const joinChat = () => { + if (form.pseudo) { + setUser(form); + socket.emit('join_system', form); + } + }; + + if (!user) { + return ( +
+

{">"} Authentification_

+ setForm({...form, pseudo: e.target.value})} /> + setForm({...form, age: e.target.value})} /> + +
+ ); + } + + return ; +} + +// Composant simplifié pour le Chat +function ChatScreen({ user }) { + const [msg, setMsg] = useState(""); + const [list, setList] = useState([]); + + useEffect(() => { + socket.on('receive_msg', (data) => setList((prev) => [...prev, data])); + }, []); + + const send = () => { + socket.emit('send_msg', { text: msg, room: 'general', pseudo: user.pseudo }); + setMsg(""); + }; + + return ( +
+
+ {list.map((m, i) =>

[{m.pseudo}]: {m.text}

)} +
+ setMsg(e.target.value)} className="bg-gray-900 w-full p-2" /> + +
+ ); +} + +export default App; \ No newline at end of file diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..86ae778 --- /dev/null +++ b/server/index.js @@ -0,0 +1,13 @@ +const io = require('socket.io')(3001, { cors: { origin: "*" } }); + +io.on('connection', (socket) => { + socket.on('join_system', (data) => { + socket.join(data.rooms); // On rejoint les salons choisis + console.log(`${data.pseudo} est entré dans: ${data.rooms}`); + }); + + socket.on('send_msg', (data) => { + // On envoie le message à tout le monde dans le salon spécifié + io.to(data.room).emit('receive_msg', data); + }); +}); \ No newline at end of file