@seafile/sdoc-editor 2.0.159 → 2.0.161

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.
@@ -153,7 +153,7 @@ var insertFragmentList = exports.insertFragmentList = function insertFragmentLis
153
153
  mode: 'lowest'
154
154
  });
155
155
  if (!liEntry) {
156
- var nodes = isListRoot(fragment) ? [(0, _core.generateDefaultText)()].concat((0, _toConsumableArray2["default"])(fragment)) : fragment;
156
+ var nodes = isListRoot(fragment[0]) ? [(0, _core.generateDefaultText)()].concat((0, _toConsumableArray2["default"])(fragment)) : fragment;
157
157
  return _insertFragment(nodes);
158
158
  }
159
159
  _slate.Transforms.insertFragment(editor, [(0, _core.generateDefaultText)()]); // need ' '
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = void 0;
8
+ var _regenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
8
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
9
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createClass"));
10
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/classCallCheck"));
@@ -12,9 +14,42 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/es
12
14
  var _socket = _interopRequireDefault(require("socket.io-client"));
13
15
  var _debug = require("../utils/debug");
14
16
  var _socketManager = _interopRequireDefault(require("./socket-manager"));
15
- var SocketClient = /*#__PURE__*/(0, _createClass2["default"])(function SocketClient(config) {
17
+ var SocketClient = /*#__PURE__*/(0, _createClass2["default"])(function SocketClient(_config) {
16
18
  var _this = this;
17
19
  (0, _classCallCheck2["default"])(this, SocketClient);
20
+ (0, _defineProperty2["default"])(this, "setupEventHandlers", function () {
21
+ _this.socket.on('connect', _this.onConnected);
22
+ _this.socket.on('disconnect', _this.onDisconnected);
23
+ _this.socket.on('connect_error', _this.onConnectError);
24
+ _this.socket.on('join-room', _this.onJoinRoom);
25
+ _this.socket.on('leave-room', _this.onLeaveRoom);
26
+ _this.socket.on('user-updated', _this.onUserUpdated);
27
+ _this.socket.on('reload-image', _this.onReloadImage);
28
+ _this.socket.on('update-document', _this.onReceiveRemoteOperations);
29
+
30
+ // doc replaced
31
+ _this.socket.on('doc-replaced', _this.receiveDocumentReplaced);
32
+ _this.socket.on('doc-replaced-error', _this.receiveDocumentReplacedError);
33
+
34
+ // doc published
35
+ _this.socket.on('doc-published', _this.receivePublishDocument);
36
+ _this.socket.on('doc-published-error', _this.receivePublishDocumentError);
37
+
38
+ // doc removed
39
+ _this.socket.on('doc-removed', _this.receiveRemoveDocument);
40
+ _this.socket.on('doc-removed-error', _this.receiveRemoveDocumentError);
41
+ _this.socket.on('update-cursor', _this.receiveCursorLocation);
42
+
43
+ // notification
44
+ _this.socket.on('new-notification', _this.receiveNewNotification);
45
+
46
+ // participant
47
+ _this.socket.on('participant-added', _this.receiveParticipantAdded);
48
+ _this.socket.on('participant-removed', _this.receiveParticipantRemoved);
49
+ _this.socket.io.on('reconnect', _this.onReconnect);
50
+ _this.socket.io.on('reconnect_attempt', _this.onReconnectAttempt);
51
+ _this.socket.io.on('reconnect_error', _this.onReconnectError);
52
+ });
18
53
  (0, _defineProperty2["default"])(this, "getParams", function () {
19
54
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
55
  var _this$config = _this.config,
@@ -37,7 +72,7 @@ var SocketClient = /*#__PURE__*/(0, _createClass2["default"])(function SocketCli
37
72
  // The reconnect of socketManager needs to be triggered after entering the room again
38
73
  socketManager.onReconnect(result);
39
74
  }
40
- socketManager.dispatchConnectState('onConnected', result);
75
+ socketManager.dispatchConnectState('connect', result);
41
76
  return;
42
77
  }
43
78
 
@@ -67,22 +102,62 @@ var SocketClient = /*#__PURE__*/(0, _createClass2["default"])(function SocketCli
67
102
  var time = new Date().toLocaleString();
68
103
  (0, _debug.clientDebug)('Current time is: %s', time);
69
104
  (0, _debug.clientDebug)('Disconnected due to ping timeout, trying to reconnect...');
70
- _this.socket.connect(function (err) {
71
- if (err) {
72
- (0, _debug.clientDebug)('error, %o', err);
73
- }
74
- });
105
+ setTimeout(function () {
106
+ _this.safeReconnect();
107
+ }, 1000);
75
108
  return;
76
109
  }
77
110
  (0, _debug.clientDebug)('disconnect message: %s', data);
78
111
  var socketManager = _socketManager["default"].getInstance();
79
112
  socketManager.dispatchConnectState('disconnect');
80
113
  });
81
- (0, _defineProperty2["default"])(this, "onConnectError", function (e) {
82
- (0, _debug.clientDebug)('connect_error. %o', e.message);
114
+ (0, _defineProperty2["default"])(this, "onConnectError", function (error) {
115
+ (0, _debug.clientDebug)('connect_error. %s', error.message);
116
+ (0, _debug.clientDebug)('connect_error. %s', error.type);
117
+ (0, _debug.clientDebug)('connect_error. %O', error.context);
118
+ if (error.message.includes('timeout')) {
119
+ setTimeout(function () {
120
+ _this.safeReconnect();
121
+ }, 1000);
122
+ }
83
123
  var socketManager = _socketManager["default"].getInstance();
84
124
  socketManager.dispatchConnectState('connect_error');
85
125
  });
126
+ (0, _defineProperty2["default"])(this, "safeReconnect", /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee() {
127
+ var config, _t;
128
+ return (0, _regenerator2["default"])().w(function (_context) {
129
+ while (1) switch (_context.p = _context.n) {
130
+ case 0:
131
+ _context.p = 0;
132
+ _this.socket.disconnect();
133
+ _this.socket = null;
134
+ _context.n = 1;
135
+ return new Promise(function (resolve) {
136
+ return setTimeout(resolve, 1000);
137
+ });
138
+ case 1:
139
+ config = _this.config;
140
+ _this.socket = (0, _socket["default"])(config.sdocServer, {
141
+ reconnection: true,
142
+ auth: {
143
+ token: config.accessToken
144
+ },
145
+ query: {
146
+ 'sdoc_uuid': config.docUuid
147
+ }
148
+ });
149
+ _this.setupEventHandlers();
150
+ _context.n = 3;
151
+ break;
152
+ case 2:
153
+ _context.p = 2;
154
+ _t = _context.v;
155
+ console.error('Reconnection failed:', _t);
156
+ case 3:
157
+ return _context.a(2);
158
+ }
159
+ }, _callee, null, [[0, 2]]);
160
+ })));
86
161
  (0, _defineProperty2["default"])(this, "sendOperations", function (operations, version, selection, callback) {
87
162
  (0, _debug.clientDebug)('send operations: %O', operations);
88
163
  _this.socket.emit('update-document', _this.getParams({
@@ -203,47 +278,17 @@ var SocketClient = /*#__PURE__*/(0, _createClass2["default"])(function SocketCli
203
278
  var socketManager = _socketManager["default"].getInstance();
204
279
  socketManager.receiveParticipantRemoved(email);
205
280
  });
206
- this.config = config;
281
+ this.config = _config;
207
282
  this.isReconnect = false;
208
- this.socket = (0, _socket["default"])(config.sdocServer, {
283
+ this.socket = (0, _socket["default"])(_config.sdocServer, {
209
284
  reconnection: true,
210
285
  auth: {
211
- token: config.accessToken
286
+ token: _config.accessToken
212
287
  },
213
288
  query: {
214
- 'sdoc_uuid': config.docUuid
289
+ 'sdoc_uuid': _config.docUuid
215
290
  }
216
291
  });
217
- this.socket.on('connect', this.onConnected);
218
- this.socket.on('disconnect', this.onDisconnected);
219
- this.socket.on('connect_error', this.onConnectError);
220
- this.socket.on('join-room', this.onJoinRoom);
221
- this.socket.on('leave-room', this.onLeaveRoom);
222
- this.socket.on('user-updated', this.onUserUpdated);
223
- this.socket.on('reload-image', this.onReloadImage);
224
- this.socket.on('update-document', this.onReceiveRemoteOperations);
225
-
226
- // doc replaced
227
- this.socket.on('doc-replaced', this.receiveDocumentReplaced);
228
- this.socket.on('doc-replaced-error', this.receiveDocumentReplacedError);
229
-
230
- // doc published
231
- this.socket.on('doc-published', this.receivePublishDocument);
232
- this.socket.on('doc-published-error', this.receivePublishDocumentError);
233
-
234
- // doc removed
235
- this.socket.on('doc-removed', this.receiveRemoveDocument);
236
- this.socket.on('doc-removed-error', this.receiveRemoveDocumentError);
237
- this.socket.on('update-cursor', this.receiveCursorLocation);
238
-
239
- // notification
240
- this.socket.on('new-notification', this.receiveNewNotification);
241
-
242
- // participant
243
- this.socket.on('participant-added', this.receiveParticipantAdded);
244
- this.socket.on('participant-removed', this.receiveParticipantRemoved);
245
- this.socket.io.on('reconnect', this.onReconnect);
246
- this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
247
- this.socket.io.on('reconnect_error', this.onReconnectError);
292
+ this.setupEventHandlers();
248
293
  });
249
294
  var _default = exports["default"] = SocketClient;
@@ -335,6 +335,10 @@ var SocketManager = /*#__PURE__*/(0, _createClass2["default"])(function SocketMa
335
335
  (0, _debug.stateDebug)("State Changed: ".concat(_this.state, " -> ").concat(STATE.DISCONNECT));
336
336
  _this.state = STATE.DISCONNECT;
337
337
  }
338
+ if (type === 'connect' && _this.state === STATE.DISCONNECT) {
339
+ (0, _debug.stateDebug)("State Changed: ".concat(_this.state, " -> ").concat(STATE.IDLE));
340
+ _this.state = STATE.IDLE;
341
+ }
338
342
  _this.eventBus.dispatch(type, message);
339
343
  });
340
344
  (0, _defineProperty2["default"])(this, "closeSocketConnect", function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.159",
3
+ "version": "2.0.161",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "a845c5a44f523fc5d2609ace65cfea2ebfefbbb2"
74
+ "gitHead": "575324484ce755f3ac5ef6ac424d70103a4cc795"
75
75
  }