1- import { Server } from "socket.io" ;
2- import { createServer } from 'http' ;
1+ import { Server , Socket } from "socket.io" ;
2+ import notes from "../../assets/ts/notes.js" ;
3+ import { Note } from "../../assets/ts/types.js" ;
34import * as Y from "yjs" ;
45import * as awarenessProtocol from "y-protocols/awareness" ;
5- import fs from 'fs' ;
6- import path from 'path' ;
7- import __dirname from "./assets/ts/_dirname.js" ;
8- const config = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../../config.json' ) , 'utf-8' ) )
9- import notes from "./assets/ts/notes.js" ;
10- import { Note } from "./assets/ts/types.js" ;
11- import Share from "./assets/ts/db/share/Share.js" ;
6+ import Share from "../../assets/ts/db/share/Share.js" ;
7+
128
13- const httpServer = createServer ( ) ;
149
1510const save_note = async ( note : Note ) : Promise < void > => {
1611 await notes . updateNote ( {
@@ -26,12 +21,6 @@ const get_note = async (uuid: string): Promise<Note | undefined> => {
2621}
2722
2823
29- const io = new Server ( httpServer , {
30- cors : { origin : config . corsOptions . origin } ,
31- path : "/socket.io/share" ,
32- transports : [ "websocket" , "polling" ]
33- } ) ;
34-
3524const docs = new Map < string , {
3625 ydoc : Y . Doc ,
3726 awareness : awarenessProtocol . Awareness ,
@@ -40,11 +29,10 @@ const docs = new Map<string, {
4029 icon : string
4130} > ( ) ;
4231
43- io . on ( "connection" , ( socket ) => {
4432
45- console . log ( "Client connected :" , socket . id ) ;
4633
47- // Stocker la room du socket pour l'utiliser dans les autres événements
34+ export default ( io : Server , socket : Socket ) => {
35+
4836 let currentRoom : string | null = null ;
4937
5038 socket . on ( "join-room" , async ( { room, userId } : { room : string , userId : string } ) => {
@@ -263,10 +251,4 @@ io.on("connection", (socket) => {
263251 console . log ( "Client disconnected:" , socket . id ) ;
264252 } ) ;
265253
266- } ) ;
267-
268- console . log ( "Socket.IO server running..." ) ;
269-
270- httpServer . listen ( '3434' , ( ) => {
271- console . log ( `Serveur WebSocket sur le port 3434` ) ;
272- } ) ;
254+ } ;
0 commit comments