فهرست منبع

refactor yjs connection manager

ryoji-s 2 سال پیش
والد
کامیت
3c7f333437
2فایلهای تغییر یافته به همراه6 افزوده شده و 8 حذف شده
  1. 1 6
      apps/app/src/server/service/socket-io.js
  2. 5 2
      apps/app/src/server/service/yjsConnectionManager.ts

+ 1 - 6
apps/app/src/server/service/socket-io.js

@@ -1,5 +1,4 @@
 import { Server } from 'socket.io';
-import { YSocketIO } from 'y-socket.io/dist/server';
 
 import { SocketEventName } from '~/interfaces/websocket';
 import loggerFactory from '~/utils/logger';
@@ -38,12 +37,8 @@ class SocketIoService {
     });
     this.io.attach(server);
 
-    // create the YScoketIO instance
-    this.ysocketio = new YSocketIO(this.io);
-    this.ysocketio.initialize();
-
     // create the YjsConnectionManager instance
-    this.yjsConnectionManager = new YjsConnectionManager(this.ysocketio);
+    this.yjsConnectionManager = new YjsConnectionManager(this.io);
 
     // create namespace for admin
     this.adminNamespace = this.io.of('/admin');

+ 5 - 2
apps/app/src/server/service/yjsConnectionManager.ts

@@ -1,3 +1,4 @@
+import type { Server } from 'socket.io';
 import { MongodbPersistence } from 'y-mongodb-provider';
 import { YSocketIO } from 'y-socket.io/dist/server';
 import * as Y from 'yjs';
@@ -13,8 +14,10 @@ class YjsConnectionManager {
 
   private mdb: MongodbPersistence;
 
-  constructor(ysocketio: YSocketIO) {
-    this.ysocketio = ysocketio;
+  constructor(io: Server) {
+    this.ysocketio = new YSocketIO(io);
+    this.ysocketio.initialize();
+
     this.mdb = new MongodbPersistence(getMongoUri(), {
       collectionName: MONGODB_PERSISTENCE_COLLECTION_NAME,
       flushSize: MONGODB_PERSISTENCE_FLUSH_SIZE,