Shun Miyazawa 1 год назад
Родитель
Сommit
9c8f6991c4

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

@@ -1,6 +1,7 @@
 import { GlobalSocketEventName } from '@growi/core/dist/interfaces';
 import { Server } from 'socket.io';
 
+import { SocketEventName } from '~/interfaces/websocket';
 import loggerFactory from '~/utils/logger';
 
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -159,6 +160,11 @@ class SocketIoService {
     const yjsConnectionManager = getYjsConnectionManager();
     this.io.on('connection', (socket) => {
       socket.on(GlobalSocketEventName.YDocSync, async({ pageId, initialValue }) => {
+        // Tell client that a draft has been created
+        socket
+          .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
+          .emit(SocketEventName.YjsUpdated, true);
+
         try {
           await yjsConnectionManager.handleYDocSync(pageId, initialValue, socket);
         }

+ 0 - 8
apps/app/src/server/service/yjs-connection-manager.ts

@@ -3,10 +3,7 @@ import { MongodbPersistence } from 'y-mongodb-provider';
 import { YSocketIO } from 'y-socket.io/dist/server';
 import * as Y from 'yjs';
 
-import { SocketEventName } from '~/interfaces/websocket';
-
 import { getMongoUri } from '../util/mongoose-utils';
-import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 
 const MONGODB_PERSISTENCE_COLLECTION_NAME = 'yjs-writings';
 const MONGODB_PERSISTENCE_FLUSH_SIZE = 100;
@@ -76,11 +73,6 @@ class YjsConnectionManager {
       await this.mdb.flushDocument(pageId);
     });
 
-    // Tell client that a draft has been created
-    socket
-      .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
-      .emit(SocketEventName.YjsUpdated, true);
-
     persistedYdoc.destroy();
   }