@shaxpir/duiduidui-models 1.6.15 → 1.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/repo/ShareSync.d.ts +6 -0
- package/dist/repo/ShareSync.js +54 -9
- package/package.json +1 -1
package/dist/repo/ShareSync.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class ShareSyncFactory {
|
|
|
29
29
|
private static INSTANCE;
|
|
30
30
|
static initialize(encryption: Encryption, options: ShareSyncOptions): void;
|
|
31
31
|
static get(): ShareSync;
|
|
32
|
+
static shutdown(): void;
|
|
32
33
|
}
|
|
33
34
|
export declare class ShareSync {
|
|
34
35
|
private _debug;
|
|
@@ -43,6 +44,10 @@ export declare class ShareSync {
|
|
|
43
44
|
private _socket;
|
|
44
45
|
private _connection;
|
|
45
46
|
private _listener;
|
|
47
|
+
private _onSocketOpen;
|
|
48
|
+
private _onSocketMessage;
|
|
49
|
+
private _onSocketClose;
|
|
50
|
+
private _onSocketError;
|
|
46
51
|
private _storage;
|
|
47
52
|
private _durableStore;
|
|
48
53
|
private _storageFactory?;
|
|
@@ -78,4 +83,5 @@ export declare class ShareSync {
|
|
|
78
83
|
setAutoBatchEnabled(enabled: boolean): void;
|
|
79
84
|
isAutoBatchEnabled(): boolean;
|
|
80
85
|
flush(): void;
|
|
86
|
+
shutdown(): void;
|
|
81
87
|
}
|
package/dist/repo/ShareSync.js
CHANGED
|
@@ -67,6 +67,12 @@ class ShareSyncFactory {
|
|
|
67
67
|
static get() {
|
|
68
68
|
return ShareSyncFactory.INSTANCE;
|
|
69
69
|
}
|
|
70
|
+
static shutdown() {
|
|
71
|
+
if (ShareSyncFactory.INSTANCE) {
|
|
72
|
+
ShareSyncFactory.INSTANCE.shutdown();
|
|
73
|
+
ShareSyncFactory.INSTANCE = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
exports.ShareSyncFactory = ShareSyncFactory;
|
|
72
78
|
ShareSyncFactory.INSTANCE = null;
|
|
@@ -90,26 +96,31 @@ class ShareSync {
|
|
|
90
96
|
shareSync._socket = new reconnecting_websocket_1.default(options.urlProvider);
|
|
91
97
|
}
|
|
92
98
|
function updateSocketIsOpen() {
|
|
93
|
-
shareSync._socketIsOpen = shareSync._socket.readyState === reconnecting_websocket_1.default.OPEN;
|
|
99
|
+
shareSync._socketIsOpen = shareSync._socket ? shareSync._socket.readyState === reconnecting_websocket_1.default.OPEN : false;
|
|
94
100
|
}
|
|
95
101
|
// The listener should forward all events: open, message, close, error
|
|
96
102
|
shareSync._listener = options.connectionListener;
|
|
97
|
-
|
|
103
|
+
// Store event handlers as instance variables so we can remove them during shutdown
|
|
104
|
+
shareSync._onSocketOpen = (event) => {
|
|
98
105
|
updateSocketIsOpen();
|
|
99
106
|
shareSync._listener.onSocketEvent('open', event);
|
|
100
|
-
}
|
|
101
|
-
shareSync.
|
|
107
|
+
};
|
|
108
|
+
shareSync._onSocketMessage = (event) => {
|
|
102
109
|
updateSocketIsOpen();
|
|
103
110
|
shareSync._listener.onSocketEvent('message', event);
|
|
104
|
-
}
|
|
105
|
-
shareSync.
|
|
111
|
+
};
|
|
112
|
+
shareSync._onSocketClose = (event) => {
|
|
106
113
|
updateSocketIsOpen();
|
|
107
114
|
shareSync._listener.onSocketEvent('close', event);
|
|
108
|
-
}
|
|
109
|
-
shareSync.
|
|
115
|
+
};
|
|
116
|
+
shareSync._onSocketError = (event) => {
|
|
110
117
|
updateSocketIsOpen();
|
|
111
118
|
shareSync._listener.onSocketEvent('error', event);
|
|
112
|
-
}
|
|
119
|
+
};
|
|
120
|
+
shareSync._socket.addEventListener('open', shareSync._onSocketOpen);
|
|
121
|
+
shareSync._socket.addEventListener('message', shareSync._onSocketMessage);
|
|
122
|
+
shareSync._socket.addEventListener('close', shareSync._onSocketClose);
|
|
123
|
+
shareSync._socket.addEventListener('error', shareSync._onSocketError);
|
|
113
124
|
// Initialize DurableStore first if enabled, then create connection with it
|
|
114
125
|
if (shareSync._hasDurableStore) {
|
|
115
126
|
shareSync.initializeDurableStore(options).then(() => {
|
|
@@ -464,5 +475,39 @@ class ShareSync {
|
|
|
464
475
|
this._durableStore.flush();
|
|
465
476
|
}
|
|
466
477
|
}
|
|
478
|
+
shutdown() {
|
|
479
|
+
console.log('[ShareSync] Shutting down...');
|
|
480
|
+
// Remove event listeners before closing the socket to prevent handlers from firing during shutdown
|
|
481
|
+
if (this._socket) {
|
|
482
|
+
if (this._onSocketOpen) {
|
|
483
|
+
this._socket.removeEventListener('open', this._onSocketOpen);
|
|
484
|
+
}
|
|
485
|
+
if (this._onSocketMessage) {
|
|
486
|
+
this._socket.removeEventListener('message', this._onSocketMessage);
|
|
487
|
+
}
|
|
488
|
+
if (this._onSocketClose) {
|
|
489
|
+
this._socket.removeEventListener('close', this._onSocketClose);
|
|
490
|
+
}
|
|
491
|
+
if (this._onSocketError) {
|
|
492
|
+
this._socket.removeEventListener('error', this._onSocketError);
|
|
493
|
+
}
|
|
494
|
+
this._socket.close();
|
|
495
|
+
this._socket = null;
|
|
496
|
+
}
|
|
497
|
+
// Close the ShareDB connection
|
|
498
|
+
if (this._connection) {
|
|
499
|
+
this._connection.close();
|
|
500
|
+
this._connection = null;
|
|
501
|
+
}
|
|
502
|
+
// Clear the model cache
|
|
503
|
+
if (this._modelCache) {
|
|
504
|
+
this._modelCache.clear();
|
|
505
|
+
}
|
|
506
|
+
// Clear DurableStore references
|
|
507
|
+
this._storage = null;
|
|
508
|
+
this._durableStore = null;
|
|
509
|
+
this._storageFactory = null;
|
|
510
|
+
console.log('[ShareSync] Shutdown complete');
|
|
511
|
+
}
|
|
467
512
|
}
|
|
468
513
|
exports.ShareSync = ShareSync;
|