Explorar el Código

use const socket event name

ryoji-s hace 2 años
padre
commit
369ad7b636

+ 3 - 0
apps/app/src/interfaces/websocket.ts

@@ -25,6 +25,9 @@ export const SocketEventName = {
   // Hackmd
   // Hackmd
   EditingWithHackmd: 'page:editingWithHackmd',
   EditingWithHackmd: 'page:editingWithHackmd',
 
 
+  // YDoc
+  YDocSync: 'ydoc:sync',
+  YDocSyncError: 'ydoc:sync:error',
 } as const;
 } as const;
 export type SocketEventName = typeof SocketEventName[keyof typeof SocketEventName];
 export type SocketEventName = typeof SocketEventName[keyof typeof SocketEventName];
 
 

+ 3 - 2
apps/app/src/server/service/socket-io.js

@@ -1,6 +1,7 @@
 import { Server } from 'socket.io';
 import { Server } from 'socket.io';
 import { YSocketIO } from 'y-socket.io/dist/server';
 import { YSocketIO } from 'y-socket.io/dist/server';
 
 
+import { SocketEventName } from '~/interfaces/websocket';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -165,13 +166,13 @@ class SocketIoService {
 
 
   setupYjsConnection() {
   setupYjsConnection() {
     this.io.on('connection', (socket) => {
     this.io.on('connection', (socket) => {
-      socket.on('ydoc:sync', async({ pageId, initialValue }) => {
+      socket.on(SocketEventName.YDocSync, async({ pageId, initialValue }) => {
         try {
         try {
           await this.yjsConnectionManager.handleYDocSync(pageId, initialValue);
           await this.yjsConnectionManager.handleYDocSync(pageId, initialValue);
         }
         }
         catch (error) {
         catch (error) {
           logger.warn(error.message);
           logger.warn(error.message);
-          socket.emit('ydoc:sync:error', 'An error occurred during YDoc synchronization.');
+          socket.emit(SocketEventName.YDocSyncError, 'An error occurred during YDoc synchronization.');
         }
         }
       });
       });
     });
     });