@univerjs/rpc 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +20 -0
- package/lib/cjs/index.js +1057 -0
- package/lib/esm/index.js +1057 -0
- package/lib/types/controllers/data-sync/data-sync-primary.controller.d.ts +15 -0
- package/lib/types/controllers/data-sync/data-sync-primary.controller.d.ts.map +1 -0
- package/lib/types/controllers/data-sync/data-sync-replica.controller.d.ts +14 -0
- package/lib/types/controllers/data-sync/data-sync-replica.controller.d.ts.map +1 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/plugin.d.ts +30 -0
- package/lib/types/plugin.d.ts.map +1 -0
- package/lib/types/services/implementations/web-worker-rpc.service.d.ts +12 -0
- package/lib/types/services/implementations/web-worker-rpc.service.d.ts.map +1 -0
- package/lib/types/services/remote-instance/remote-instance.service.d.ts +63 -0
- package/lib/types/services/remote-instance/remote-instance.service.d.ts.map +1 -0
- package/lib/types/services/rpc/__tests__/rpc.service.spec.d.ts +2 -0
- package/lib/types/services/rpc/__tests__/rpc.service.spec.d.ts.map +1 -0
- package/lib/types/services/rpc/rpc.service.d.ts +79 -0
- package/lib/types/services/rpc/rpc.service.d.ts.map +1 -0
- package/package.json +48 -0
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,1057 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _assert_this_initialized(self) {
|
|
3
|
+
if (self === void 0) {
|
|
4
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
5
|
+
}
|
|
6
|
+
return self;
|
|
7
|
+
}
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
9
|
+
try {
|
|
10
|
+
var info = gen[key](arg);
|
|
11
|
+
var value = info.value;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
reject(error);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (info.done) {
|
|
17
|
+
resolve(value);
|
|
18
|
+
} else {
|
|
19
|
+
Promise.resolve(value).then(_next, _throw);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function _async_to_generator(fn) {
|
|
23
|
+
return function() {
|
|
24
|
+
var self = this, args = arguments;
|
|
25
|
+
return new Promise(function(resolve, reject) {
|
|
26
|
+
var gen = fn.apply(self, args);
|
|
27
|
+
function _next(value) {
|
|
28
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
29
|
+
}
|
|
30
|
+
function _throw(err) {
|
|
31
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
32
|
+
}
|
|
33
|
+
_next(undefined);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function _class_call_check(instance, Constructor) {
|
|
38
|
+
if (!(instance instanceof Constructor)) {
|
|
39
|
+
throw new TypeError("Cannot call a class as a function");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function _defineProperties(target, props) {
|
|
43
|
+
for(var i = 0; i < props.length; i++){
|
|
44
|
+
var descriptor = props[i];
|
|
45
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
46
|
+
descriptor.configurable = true;
|
|
47
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
48
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
52
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
53
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
54
|
+
return Constructor;
|
|
55
|
+
}
|
|
56
|
+
function _define_property(obj, key, value) {
|
|
57
|
+
if (key in obj) {
|
|
58
|
+
Object.defineProperty(obj, key, {
|
|
59
|
+
value: value,
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
obj[key] = value;
|
|
66
|
+
}
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
function _get_prototype_of(o) {
|
|
70
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
71
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
72
|
+
};
|
|
73
|
+
return _get_prototype_of(o);
|
|
74
|
+
}
|
|
75
|
+
function _inherits(subClass, superClass) {
|
|
76
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
77
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
78
|
+
}
|
|
79
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
80
|
+
constructor: {
|
|
81
|
+
value: subClass,
|
|
82
|
+
writable: true,
|
|
83
|
+
configurable: true
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
87
|
+
}
|
|
88
|
+
function _instanceof(left, right) {
|
|
89
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
90
|
+
return !!right[Symbol.hasInstance](left);
|
|
91
|
+
} else {
|
|
92
|
+
return left instanceof right;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function _possible_constructor_return(self, call) {
|
|
96
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
97
|
+
return call;
|
|
98
|
+
}
|
|
99
|
+
return _assert_this_initialized(self);
|
|
100
|
+
}
|
|
101
|
+
function _set_prototype_of(o, p) {
|
|
102
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
103
|
+
o.__proto__ = p;
|
|
104
|
+
return o;
|
|
105
|
+
};
|
|
106
|
+
return _set_prototype_of(o, p);
|
|
107
|
+
}
|
|
108
|
+
function _type_of(obj) {
|
|
109
|
+
"@swc/helpers - typeof";
|
|
110
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
111
|
+
}
|
|
112
|
+
function _is_native_reflect_construct() {
|
|
113
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
114
|
+
if (Reflect.construct.sham) return false;
|
|
115
|
+
if (typeof Proxy === "function") return true;
|
|
116
|
+
try {
|
|
117
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
118
|
+
return true;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function _create_super(Derived) {
|
|
124
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
125
|
+
return function _createSuperInternal() {
|
|
126
|
+
var Super = _get_prototype_of(Derived), result;
|
|
127
|
+
if (hasNativeReflectConstruct) {
|
|
128
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
129
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
130
|
+
} else {
|
|
131
|
+
result = Super.apply(this, arguments);
|
|
132
|
+
}
|
|
133
|
+
return _possible_constructor_return(this, result);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function _ts_generator(thisArg, body) {
|
|
137
|
+
var f, y, t, g, _ = {
|
|
138
|
+
label: 0,
|
|
139
|
+
sent: function() {
|
|
140
|
+
if (t[0] & 1) throw t[1];
|
|
141
|
+
return t[1];
|
|
142
|
+
},
|
|
143
|
+
trys: [],
|
|
144
|
+
ops: []
|
|
145
|
+
};
|
|
146
|
+
return g = {
|
|
147
|
+
next: verb(0),
|
|
148
|
+
"throw": verb(1),
|
|
149
|
+
"return": verb(2)
|
|
150
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
151
|
+
return this;
|
|
152
|
+
}), g;
|
|
153
|
+
function verb(n) {
|
|
154
|
+
return function(v) {
|
|
155
|
+
return step([
|
|
156
|
+
n,
|
|
157
|
+
v
|
|
158
|
+
]);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function step(op) {
|
|
162
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
163
|
+
while(_)try {
|
|
164
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
165
|
+
if (y = 0, t) op = [
|
|
166
|
+
op[0] & 2,
|
|
167
|
+
t.value
|
|
168
|
+
];
|
|
169
|
+
switch(op[0]){
|
|
170
|
+
case 0:
|
|
171
|
+
case 1:
|
|
172
|
+
t = op;
|
|
173
|
+
break;
|
|
174
|
+
case 4:
|
|
175
|
+
_.label++;
|
|
176
|
+
return {
|
|
177
|
+
value: op[1],
|
|
178
|
+
done: false
|
|
179
|
+
};
|
|
180
|
+
case 5:
|
|
181
|
+
_.label++;
|
|
182
|
+
y = op[1];
|
|
183
|
+
op = [
|
|
184
|
+
0
|
|
185
|
+
];
|
|
186
|
+
continue;
|
|
187
|
+
case 7:
|
|
188
|
+
op = _.ops.pop();
|
|
189
|
+
_.trys.pop();
|
|
190
|
+
continue;
|
|
191
|
+
default:
|
|
192
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
193
|
+
_ = 0;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
197
|
+
_.label = op[1];
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
201
|
+
_.label = t[1];
|
|
202
|
+
t = op;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
if (t && _.label < t[2]) {
|
|
206
|
+
_.label = t[2];
|
|
207
|
+
_.ops.push(op);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
if (t[2]) _.ops.pop();
|
|
211
|
+
_.trys.pop();
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
op = body.call(thisArg, _);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
op = [
|
|
217
|
+
6,
|
|
218
|
+
e
|
|
219
|
+
];
|
|
220
|
+
y = 0;
|
|
221
|
+
} finally{
|
|
222
|
+
f = t = 0;
|
|
223
|
+
}
|
|
224
|
+
if (op[0] & 5) throw op[1];
|
|
225
|
+
return {
|
|
226
|
+
value: op[0] ? op[1] : void 0,
|
|
227
|
+
done: true
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
var _import_core5_Plugin, _class, _import_core5_Plugin1, _class1;
|
|
232
|
+
var __defProp = Object.defineProperty;
|
|
233
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
234
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
235
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
236
|
+
var __export = function(target, all) {
|
|
237
|
+
for(var name in all)__defProp(target, name, {
|
|
238
|
+
get: all[name],
|
|
239
|
+
enumerable: true
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
var __copyProps = function(to, from, except, desc) {
|
|
243
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
244
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
245
|
+
try {
|
|
246
|
+
var _loop = function() {
|
|
247
|
+
var key = _step.value;
|
|
248
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
249
|
+
get: function() {
|
|
250
|
+
return from[key];
|
|
251
|
+
},
|
|
252
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
256
|
+
} catch (err) {
|
|
257
|
+
_didIteratorError = true;
|
|
258
|
+
_iteratorError = err;
|
|
259
|
+
} finally{
|
|
260
|
+
try {
|
|
261
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
262
|
+
_iterator.return();
|
|
263
|
+
}
|
|
264
|
+
} finally{
|
|
265
|
+
if (_didIteratorError) {
|
|
266
|
+
throw _iteratorError;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return to;
|
|
272
|
+
};
|
|
273
|
+
var __toCommonJS = function(mod) {
|
|
274
|
+
return __copyProps(__defProp({}, "__esModule", {
|
|
275
|
+
value: true
|
|
276
|
+
}), mod);
|
|
277
|
+
};
|
|
278
|
+
var __decorateClass = function(decorators, target, key, kind) {
|
|
279
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
280
|
+
for(var i = decorators.length - 1, decorator; i >= 0; i--)if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
281
|
+
if (kind && result) __defProp(target, key, result);
|
|
282
|
+
return result;
|
|
283
|
+
};
|
|
284
|
+
var __decorateParam = function(index, decorator) {
|
|
285
|
+
return function(target, key) {
|
|
286
|
+
return decorator(target, key, index);
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
// src/index.ts
|
|
290
|
+
var src_exports = {};
|
|
291
|
+
__export(src_exports, {
|
|
292
|
+
UniverRPCMainThreadPlugin: function() {
|
|
293
|
+
return UniverRPCMainThreadPlugin;
|
|
294
|
+
},
|
|
295
|
+
UniverRPCWorkerThreadPlugin: function() {
|
|
296
|
+
return UniverRPCWorkerThreadPlugin;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
module.exports = __toCommonJS(src_exports);
|
|
300
|
+
// src/plugin.ts
|
|
301
|
+
var import_core5 = require("@univerjs/core");
|
|
302
|
+
var import_redi3 = require("@wendellhu/redi");
|
|
303
|
+
// src/controllers/data-sync/data-sync-primary.controller.ts
|
|
304
|
+
var import_core2 = require("@univerjs/core");
|
|
305
|
+
var import_operators = require("rxjs/operators");
|
|
306
|
+
// src/services/remote-instance/remote-instance.service.ts
|
|
307
|
+
var import_core = require("@univerjs/core");
|
|
308
|
+
var import_redi = require("@wendellhu/redi");
|
|
309
|
+
var RemoteSyncServiceName = "univer.remote-sync-service";
|
|
310
|
+
var IRemoteSyncService = (0, import_redi.createIdentifier)(RemoteSyncServiceName);
|
|
311
|
+
var RemoteSyncPrimaryService = /*#__PURE__*/ function() {
|
|
312
|
+
function RemoteSyncPrimaryService(_commandService) {
|
|
313
|
+
_class_call_check(this, RemoteSyncPrimaryService);
|
|
314
|
+
this._commandService = _commandService;
|
|
315
|
+
}
|
|
316
|
+
_create_class(RemoteSyncPrimaryService, [
|
|
317
|
+
{
|
|
318
|
+
key: "syncMutation",
|
|
319
|
+
value: function syncMutation(params) {
|
|
320
|
+
var _this = this;
|
|
321
|
+
return _async_to_generator(function() {
|
|
322
|
+
return _ts_generator(this, function(_state) {
|
|
323
|
+
return [
|
|
324
|
+
2,
|
|
325
|
+
_this._commandService.syncExecuteCommand(params.mutationInfo.id, params.mutationInfo.params, {
|
|
326
|
+
local: true,
|
|
327
|
+
fromSync: true
|
|
328
|
+
})
|
|
329
|
+
];
|
|
330
|
+
});
|
|
331
|
+
})();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
]);
|
|
335
|
+
return RemoteSyncPrimaryService;
|
|
336
|
+
}();
|
|
337
|
+
RemoteSyncPrimaryService = __decorateClass([
|
|
338
|
+
__decorateParam(0, import_core.ICommandService)
|
|
339
|
+
], RemoteSyncPrimaryService);
|
|
340
|
+
var RemoteInstanceServiceName = "univer.remote-instance-service";
|
|
341
|
+
var IRemoteInstanceService = (0, import_redi.createIdentifier)(RemoteInstanceServiceName);
|
|
342
|
+
var RemoteInstanceReplicaService = /*#__PURE__*/ function() {
|
|
343
|
+
function RemoteInstanceReplicaService(_univerInstanceService, _commandService) {
|
|
344
|
+
_class_call_check(this, RemoteInstanceReplicaService);
|
|
345
|
+
this._univerInstanceService = _univerInstanceService;
|
|
346
|
+
this._commandService = _commandService;
|
|
347
|
+
}
|
|
348
|
+
_create_class(RemoteInstanceReplicaService, [
|
|
349
|
+
{
|
|
350
|
+
key: "syncMutation",
|
|
351
|
+
value: function syncMutation(params) {
|
|
352
|
+
var _this = this;
|
|
353
|
+
return _async_to_generator(function() {
|
|
354
|
+
return _ts_generator(this, function(_state) {
|
|
355
|
+
return [
|
|
356
|
+
2,
|
|
357
|
+
_this._commandService.syncExecuteCommand(params.mutationInfo.id, params.mutationInfo.params, {
|
|
358
|
+
local: true,
|
|
359
|
+
fromSync: true
|
|
360
|
+
})
|
|
361
|
+
];
|
|
362
|
+
});
|
|
363
|
+
})();
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
key: "createInstance",
|
|
368
|
+
value: function createInstance(params) {
|
|
369
|
+
var _this = this;
|
|
370
|
+
return _async_to_generator(function() {
|
|
371
|
+
var type, snapshot;
|
|
372
|
+
return _ts_generator(this, function(_state) {
|
|
373
|
+
type = params.type, snapshot = params.snapshot;
|
|
374
|
+
try {
|
|
375
|
+
switch(type){
|
|
376
|
+
case import_core.DocumentType.SHEET:
|
|
377
|
+
return [
|
|
378
|
+
2,
|
|
379
|
+
!!_this._univerInstanceService.createSheet(snapshot)
|
|
380
|
+
];
|
|
381
|
+
default:
|
|
382
|
+
throw new Error("[RemoteInstanceReplicaService]: cannot create replica for document type: ".concat(type, "."));
|
|
383
|
+
}
|
|
384
|
+
} catch (err) {
|
|
385
|
+
if (_instanceof(err, Error)) {
|
|
386
|
+
throw err;
|
|
387
|
+
} else {
|
|
388
|
+
throw new Error("".concat(err));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return [
|
|
392
|
+
2
|
|
393
|
+
];
|
|
394
|
+
});
|
|
395
|
+
})();
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
key: "disposeInstance",
|
|
400
|
+
value: function disposeInstance(params) {
|
|
401
|
+
var _this = this;
|
|
402
|
+
return _async_to_generator(function() {
|
|
403
|
+
return _ts_generator(this, function(_state) {
|
|
404
|
+
return [
|
|
405
|
+
2,
|
|
406
|
+
_this._univerInstanceService.disposeDocument(params.unitID)
|
|
407
|
+
];
|
|
408
|
+
});
|
|
409
|
+
})();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
]);
|
|
413
|
+
return RemoteInstanceReplicaService;
|
|
414
|
+
}();
|
|
415
|
+
RemoteInstanceReplicaService = __decorateClass([
|
|
416
|
+
__decorateParam(0, import_core.IUniverInstanceService),
|
|
417
|
+
__decorateParam(1, import_core.ICommandService)
|
|
418
|
+
], RemoteInstanceReplicaService);
|
|
419
|
+
// src/controllers/data-sync/data-sync-primary.controller.ts
|
|
420
|
+
var DataSyncPrimaryController = /*#__PURE__*/ function(_import_core2_RxDisposable) {
|
|
421
|
+
_inherits(DataSyncPrimaryController, _import_core2_RxDisposable);
|
|
422
|
+
var _super = _create_super(DataSyncPrimaryController);
|
|
423
|
+
function DataSyncPrimaryController(_unsyncMutations, _univerInstanceService, _remoteInstanceService, _commandService) {
|
|
424
|
+
_class_call_check(this, DataSyncPrimaryController);
|
|
425
|
+
var _this;
|
|
426
|
+
_this = _super.call(this);
|
|
427
|
+
_this._unsyncMutations = _unsyncMutations;
|
|
428
|
+
_this._univerInstanceService = _univerInstanceService;
|
|
429
|
+
_this._remoteInstanceService = _remoteInstanceService;
|
|
430
|
+
_this._commandService = _commandService;
|
|
431
|
+
_this._init();
|
|
432
|
+
return _this;
|
|
433
|
+
}
|
|
434
|
+
_create_class(DataSyncPrimaryController, [
|
|
435
|
+
{
|
|
436
|
+
key: "_init",
|
|
437
|
+
value: function _init() {
|
|
438
|
+
var _this = this;
|
|
439
|
+
this._univerInstanceService.sheetAdded$.pipe((0, import_operators.takeUntil)(this.dispose$)).subscribe(function(sheet) {
|
|
440
|
+
_this._remoteInstanceService.createInstance({
|
|
441
|
+
unitID: sheet.getUnitId(),
|
|
442
|
+
type: import_core2.DocumentType.SHEET,
|
|
443
|
+
snapshot: sheet.getSnapshot()
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
this._univerInstanceService.sheetDisposed$.pipe((0, import_operators.takeUntil)(this.dispose$)).subscribe(function(workbook) {
|
|
447
|
+
_this._remoteInstanceService.disposeInstance({
|
|
448
|
+
unitID: workbook.getUnitId()
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
this.disposeWithMe(// Mutations executed on the main thread should be synced to the worker thread.
|
|
452
|
+
this._commandService.onCommandExecuted(function(commandInfo, options) {
|
|
453
|
+
if (commandInfo.type === import_core2.CommandType.MUTATION && !(options === null || options === void 0 ? void 0 : options.fromSync) && !_this._unsyncMutations.has(commandInfo.id)) {
|
|
454
|
+
_this._remoteInstanceService.syncMutation({
|
|
455
|
+
mutationInfo: commandInfo
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
]);
|
|
462
|
+
return DataSyncPrimaryController;
|
|
463
|
+
}(import_core2.RxDisposable);
|
|
464
|
+
DataSyncPrimaryController = __decorateClass([
|
|
465
|
+
(0, import_core2.OnLifecycle)(import_core2.LifecycleStages.Starting, DataSyncPrimaryController),
|
|
466
|
+
__decorateParam(1, import_core2.IUniverInstanceService),
|
|
467
|
+
__decorateParam(2, IRemoteInstanceService),
|
|
468
|
+
__decorateParam(3, import_core2.ICommandService)
|
|
469
|
+
], DataSyncPrimaryController);
|
|
470
|
+
// src/controllers/data-sync/data-sync-replica.controller.ts
|
|
471
|
+
var import_core3 = require("@univerjs/core");
|
|
472
|
+
var DataSyncReplicaController = /*#__PURE__*/ function(_import_core3_Disposable) {
|
|
473
|
+
_inherits(DataSyncReplicaController, _import_core3_Disposable);
|
|
474
|
+
var _super = _create_super(DataSyncReplicaController);
|
|
475
|
+
function DataSyncReplicaController(_commandService, _remoteInstanceService, _univerInstanceService) {
|
|
476
|
+
_class_call_check(this, DataSyncReplicaController);
|
|
477
|
+
var _this;
|
|
478
|
+
_this = _super.call(this);
|
|
479
|
+
_this._commandService = _commandService;
|
|
480
|
+
_this._remoteInstanceService = _remoteInstanceService;
|
|
481
|
+
_this._univerInstanceService = _univerInstanceService;
|
|
482
|
+
_this._init();
|
|
483
|
+
return _this;
|
|
484
|
+
}
|
|
485
|
+
_create_class(DataSyncReplicaController, [
|
|
486
|
+
{
|
|
487
|
+
key: "_init",
|
|
488
|
+
value: function _init() {
|
|
489
|
+
var _this = this;
|
|
490
|
+
this.disposeWithMe(// Mutations executed on the main thread should be synced to the worker thread.
|
|
491
|
+
this._commandService.onCommandExecuted(function(commandInfo, options) {
|
|
492
|
+
if (commandInfo.type === import_core3.CommandType.MUTATION && !(options === null || options === void 0 ? void 0 : options.fromSync)) {
|
|
493
|
+
_this._remoteInstanceService.syncMutation({
|
|
494
|
+
mutationInfo: commandInfo
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
]);
|
|
501
|
+
return DataSyncReplicaController;
|
|
502
|
+
}(import_core3.Disposable);
|
|
503
|
+
DataSyncReplicaController = __decorateClass([
|
|
504
|
+
(0, import_core3.OnLifecycle)(import_core3.LifecycleStages.Starting, DataSyncReplicaController),
|
|
505
|
+
__decorateParam(0, import_core3.ICommandService),
|
|
506
|
+
__decorateParam(1, IRemoteSyncService),
|
|
507
|
+
__decorateParam(2, import_core3.IUniverInstanceService)
|
|
508
|
+
], DataSyncReplicaController);
|
|
509
|
+
// src/services/implementations/web-worker-rpc.service.ts
|
|
510
|
+
var import_rxjs = require("rxjs");
|
|
511
|
+
function createWebWorkerMessagePortOnWorker() {
|
|
512
|
+
return {
|
|
513
|
+
send: function send(message) {
|
|
514
|
+
postMessage(message);
|
|
515
|
+
},
|
|
516
|
+
onMessage: new import_rxjs.Observable(function(subscriber) {
|
|
517
|
+
var handler = function(event) {
|
|
518
|
+
subscriber.next(event.data);
|
|
519
|
+
};
|
|
520
|
+
addEventListener("message", handler);
|
|
521
|
+
return function() {
|
|
522
|
+
return removeEventListener("message", handler);
|
|
523
|
+
};
|
|
524
|
+
}).pipe((0, import_rxjs.shareReplay)(1))
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function createWebWorkerMessagePortOnMain(worker) {
|
|
528
|
+
return {
|
|
529
|
+
send: function send(message) {
|
|
530
|
+
worker.postMessage(message);
|
|
531
|
+
},
|
|
532
|
+
onMessage: new import_rxjs.Observable(function(subscriber) {
|
|
533
|
+
var handler = function(event) {
|
|
534
|
+
subscriber.next(event.data);
|
|
535
|
+
};
|
|
536
|
+
worker.addEventListener("message", handler);
|
|
537
|
+
return function() {
|
|
538
|
+
return worker.removeEventListener("message", handler);
|
|
539
|
+
};
|
|
540
|
+
}).pipe((0, import_rxjs.shareReplay)(1))
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
// src/services/rpc/rpc.service.ts
|
|
544
|
+
var import_core4 = require("@univerjs/core");
|
|
545
|
+
var import_redi2 = require("@wendellhu/redi");
|
|
546
|
+
var import_rxjs2 = require("rxjs");
|
|
547
|
+
var import_operators2 = require("rxjs/operators");
|
|
548
|
+
function fromModule(module2) {
|
|
549
|
+
var handler = module2;
|
|
550
|
+
return new /*#__PURE__*/ (function() {
|
|
551
|
+
function _class() {
|
|
552
|
+
_class_call_check(this, _class);
|
|
553
|
+
}
|
|
554
|
+
_create_class(_class, [
|
|
555
|
+
{
|
|
556
|
+
key: "call",
|
|
557
|
+
value: function call(method, args) {
|
|
558
|
+
var target = handler[method];
|
|
559
|
+
if (typeof target === "function") {
|
|
560
|
+
var res = target.apply(handler, [
|
|
561
|
+
args
|
|
562
|
+
]);
|
|
563
|
+
if (!_instanceof(res, Promise)) {
|
|
564
|
+
res = Promise.resolve(res);
|
|
565
|
+
}
|
|
566
|
+
return res;
|
|
567
|
+
}
|
|
568
|
+
throw new Error("[RPC]: method not found for ".concat(method, "!"));
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
key: "subscribe",
|
|
573
|
+
value: function subscribe(eventMethod, args) {
|
|
574
|
+
var target = handler[eventMethod];
|
|
575
|
+
if (typeof target === "function") {
|
|
576
|
+
var res = target.apply(handler, args);
|
|
577
|
+
if (!(0, import_rxjs2.isObservable)(res)) {
|
|
578
|
+
return (0, import_rxjs2.of)(res);
|
|
579
|
+
}
|
|
580
|
+
return res;
|
|
581
|
+
}
|
|
582
|
+
throw new Error("[RPC]: observable method not found for ".concat(eventMethod, "!"));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
]);
|
|
586
|
+
return _class;
|
|
587
|
+
}())();
|
|
588
|
+
}
|
|
589
|
+
function toModule(channel) {
|
|
590
|
+
return new Proxy({}, {
|
|
591
|
+
get: function get(_, propKey) {
|
|
592
|
+
return function() {
|
|
593
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
594
|
+
args[_key] = arguments[_key];
|
|
595
|
+
}
|
|
596
|
+
var isObservable2 = propertyIsEventSource(propKey);
|
|
597
|
+
if (isObservable2) {
|
|
598
|
+
var observable = channel.subscribe(propKey, args[0]);
|
|
599
|
+
return observable;
|
|
600
|
+
}
|
|
601
|
+
return channel.call(propKey, args[0]);
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function propertyIsEventSource(name) {
|
|
607
|
+
return name.endsWith("$");
|
|
608
|
+
}
|
|
609
|
+
var ChannelClient = /*#__PURE__*/ function(_import_core4_RxDisposable) {
|
|
610
|
+
_inherits(ChannelClient, _import_core4_RxDisposable);
|
|
611
|
+
var _super = _create_super(ChannelClient);
|
|
612
|
+
function ChannelClient(_protocol) {
|
|
613
|
+
_class_call_check(this, ChannelClient);
|
|
614
|
+
var _this;
|
|
615
|
+
_this = _super.call(this);
|
|
616
|
+
_define_property(_assert_this_initialized(_this), "_initialized", new import_rxjs2.BehaviorSubject(false));
|
|
617
|
+
_define_property(_assert_this_initialized(_this), "_lastRequestCounter", 0);
|
|
618
|
+
_define_property(_assert_this_initialized(_this), "_pendingRequests", /* @__PURE__ */ new Map());
|
|
619
|
+
_define_property(_assert_this_initialized(_this), "_pendingSubscriptions", /* @__PURE__ */ new Map());
|
|
620
|
+
_this._protocol = _protocol;
|
|
621
|
+
_this._protocol.onMessage.pipe((0, import_operators2.takeUntil)(_this.dispose$)).subscribe(function(message) {
|
|
622
|
+
return _this._onResponse(message);
|
|
623
|
+
});
|
|
624
|
+
return _this;
|
|
625
|
+
}
|
|
626
|
+
_create_class(ChannelClient, [
|
|
627
|
+
{
|
|
628
|
+
key: "getChannel",
|
|
629
|
+
value: function getChannel(channelName) {
|
|
630
|
+
var self = this;
|
|
631
|
+
return {
|
|
632
|
+
call: function call(method, args) {
|
|
633
|
+
if (self._disposed) {
|
|
634
|
+
return Promise.reject();
|
|
635
|
+
}
|
|
636
|
+
return self._remoteCall(channelName, method, args);
|
|
637
|
+
},
|
|
638
|
+
subscribe: function subscribe(eventMethod, args) {
|
|
639
|
+
if (self._disposed) {
|
|
640
|
+
throw new Error("[ChannelClient]: client is disposed!");
|
|
641
|
+
}
|
|
642
|
+
return self._remoteSubscribe(channelName, eventMethod, args);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
key: "_whenReady",
|
|
649
|
+
value: function _whenReady() {
|
|
650
|
+
return (0, import_rxjs2.firstValueFrom)(this._initialized.pipe((0, import_operators2.filter)(function(v) {
|
|
651
|
+
return v;
|
|
652
|
+
}), (0, import_operators2.take)(1)));
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
key: "_remoteCall",
|
|
657
|
+
value: function _remoteCall(channelName, method, args) {
|
|
658
|
+
var _this = this;
|
|
659
|
+
return _async_to_generator(function() {
|
|
660
|
+
var sequence, type, request, client;
|
|
661
|
+
return _ts_generator(this, function(_state) {
|
|
662
|
+
switch(_state.label){
|
|
663
|
+
case 0:
|
|
664
|
+
return [
|
|
665
|
+
4,
|
|
666
|
+
_this._whenReady()
|
|
667
|
+
];
|
|
668
|
+
case 1:
|
|
669
|
+
_state.sent();
|
|
670
|
+
sequence = ++_this._lastRequestCounter;
|
|
671
|
+
type = 100 /* CALL */ ;
|
|
672
|
+
request = {
|
|
673
|
+
seq: sequence,
|
|
674
|
+
type: type,
|
|
675
|
+
channelName: channelName,
|
|
676
|
+
method: method,
|
|
677
|
+
args: args
|
|
678
|
+
};
|
|
679
|
+
client = _this;
|
|
680
|
+
return [
|
|
681
|
+
2,
|
|
682
|
+
new Promise(function(resolve, reject) {
|
|
683
|
+
var responseHandler = {
|
|
684
|
+
handle: function handle(response) {
|
|
685
|
+
switch(response.type){
|
|
686
|
+
case 100 /* CALL_SUCCESS */ :
|
|
687
|
+
client._pendingRequests.delete(sequence);
|
|
688
|
+
resolve(response.data);
|
|
689
|
+
break;
|
|
690
|
+
case 101 /* CALL_FAILURE */ :
|
|
691
|
+
client._pendingRequests.delete(sequence);
|
|
692
|
+
reject(response.data);
|
|
693
|
+
break;
|
|
694
|
+
default:
|
|
695
|
+
throw new Error("[ChannelClient]: unknown response type!");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
_this._pendingRequests.set(sequence, responseHandler);
|
|
700
|
+
_this._sendRequest(request);
|
|
701
|
+
})
|
|
702
|
+
];
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
})();
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
key: "_remoteSubscribe",
|
|
710
|
+
value: function _remoteSubscribe(channelName, method, args) {
|
|
711
|
+
var _this = this;
|
|
712
|
+
return new import_rxjs2.Observable(function(subscriber) {
|
|
713
|
+
var sequence = -1;
|
|
714
|
+
_this._whenReady().then(function() {
|
|
715
|
+
sequence = ++_this._lastRequestCounter;
|
|
716
|
+
var type = 101 /* SUBSCRIBE */ ;
|
|
717
|
+
var request = {
|
|
718
|
+
seq: sequence,
|
|
719
|
+
type: type,
|
|
720
|
+
channelName: channelName,
|
|
721
|
+
method: method,
|
|
722
|
+
args: args
|
|
723
|
+
};
|
|
724
|
+
var responseHandler = {
|
|
725
|
+
handle: function handle(response) {
|
|
726
|
+
switch(response.type){
|
|
727
|
+
case 200 /* SUBSCRIBE_NEXT */ :
|
|
728
|
+
subscriber.next(response.data);
|
|
729
|
+
break;
|
|
730
|
+
case 201 /* SUBSCRIBE_ERROR */ :
|
|
731
|
+
subscriber.error(response.data);
|
|
732
|
+
break;
|
|
733
|
+
case 202 /* SUBSCRIBE_COMPLETE */ :
|
|
734
|
+
subscriber.complete();
|
|
735
|
+
break;
|
|
736
|
+
default:
|
|
737
|
+
throw new Error("[ChannelClient]: unknown response type!");
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
_this._pendingRequests.set(sequence, responseHandler);
|
|
742
|
+
_this._sendRequest(request);
|
|
743
|
+
});
|
|
744
|
+
return function() {
|
|
745
|
+
if (sequence === -1) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
var cancelSubscriptionRequest = {
|
|
749
|
+
type: 102 /* UNSUBSCRIBE */ ,
|
|
750
|
+
seq: sequence,
|
|
751
|
+
channelName: channelName,
|
|
752
|
+
method: method
|
|
753
|
+
};
|
|
754
|
+
_this._sendRequest(cancelSubscriptionRequest);
|
|
755
|
+
};
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
key: "_sendRequest",
|
|
761
|
+
value: function _sendRequest(request) {
|
|
762
|
+
this._protocol.send(request);
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
key: "_onResponse",
|
|
767
|
+
value: function _onResponse(response) {
|
|
768
|
+
switch(response.type){
|
|
769
|
+
case 0 /* INITIALIZE */ :
|
|
770
|
+
this._initialized.next(true);
|
|
771
|
+
break;
|
|
772
|
+
case 100 /* CALL_SUCCESS */ :
|
|
773
|
+
case 101 /* CALL_FAILURE */ :
|
|
774
|
+
case 200 /* SUBSCRIBE_NEXT */ :
|
|
775
|
+
case 202 /* SUBSCRIBE_COMPLETE */ :
|
|
776
|
+
case 201 /* SUBSCRIBE_ERROR */ :
|
|
777
|
+
var _this__pendingRequests_get;
|
|
778
|
+
(_this__pendingRequests_get = this._pendingRequests.get(response.seq)) === null || _this__pendingRequests_get === void 0 ? void 0 : _this__pendingRequests_get.handle(response);
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
]);
|
|
784
|
+
return ChannelClient;
|
|
785
|
+
}(import_core4.RxDisposable);
|
|
786
|
+
var ChannelServer = /*#__PURE__*/ function(_import_core4_RxDisposable) {
|
|
787
|
+
_inherits(ChannelServer, _import_core4_RxDisposable);
|
|
788
|
+
var _super = _create_super(ChannelServer);
|
|
789
|
+
function ChannelServer(_protocol) {
|
|
790
|
+
_class_call_check(this, ChannelServer);
|
|
791
|
+
var _this;
|
|
792
|
+
_this = _super.call(this);
|
|
793
|
+
_define_property(_assert_this_initialized(_this), "_channels", /* @__PURE__ */ new Map());
|
|
794
|
+
_define_property(_assert_this_initialized(_this), "_subscriptions", /* @__PURE__ */ new Map());
|
|
795
|
+
_this._protocol = _protocol;
|
|
796
|
+
_this._protocol.onMessage.pipe((0, import_operators2.takeUntil)(_this.dispose$)).subscribe(function(message) {
|
|
797
|
+
return _this._onRequest(message);
|
|
798
|
+
});
|
|
799
|
+
_this._sendResponse({
|
|
800
|
+
seq: -1,
|
|
801
|
+
type: 0 /* INITIALIZE */
|
|
802
|
+
});
|
|
803
|
+
return _this;
|
|
804
|
+
}
|
|
805
|
+
_create_class(ChannelServer, [
|
|
806
|
+
{
|
|
807
|
+
key: "registerChannel",
|
|
808
|
+
value: function registerChannel(channelName, channel) {
|
|
809
|
+
this._channels.set(channelName, channel);
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
key: "_onRequest",
|
|
814
|
+
value: function _onRequest(request) {
|
|
815
|
+
switch(request.type){
|
|
816
|
+
case 100 /* CALL */ :
|
|
817
|
+
this._onMethodCall(request);
|
|
818
|
+
break;
|
|
819
|
+
case 101 /* SUBSCRIBE */ :
|
|
820
|
+
this._onSubscribe(request);
|
|
821
|
+
break;
|
|
822
|
+
case 102 /* UNSUBSCRIBE */ :
|
|
823
|
+
this._onUnsubscribe(request);
|
|
824
|
+
break;
|
|
825
|
+
default:
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
key: "_onMethodCall",
|
|
832
|
+
value: function _onMethodCall(request) {
|
|
833
|
+
var _this = this;
|
|
834
|
+
var channel = this._channels.get(request.channelName);
|
|
835
|
+
var promise;
|
|
836
|
+
try {
|
|
837
|
+
if (!channel) {
|
|
838
|
+
throw new Error("[ChannelServer]: Channel not found!");
|
|
839
|
+
}
|
|
840
|
+
promise = channel.call(request.method, request.args);
|
|
841
|
+
} catch (err) {
|
|
842
|
+
promise = Promise.reject(err);
|
|
843
|
+
}
|
|
844
|
+
promise.then(function(data) {
|
|
845
|
+
_this._sendResponse({
|
|
846
|
+
seq: request.seq,
|
|
847
|
+
type: 100 /* CALL_SUCCESS */ ,
|
|
848
|
+
data: data
|
|
849
|
+
});
|
|
850
|
+
}).catch(function(err) {
|
|
851
|
+
if (_instanceof(err, Error)) {
|
|
852
|
+
_this._sendResponse({
|
|
853
|
+
seq: request.seq,
|
|
854
|
+
type: 101 /* CALL_FAILURE */ ,
|
|
855
|
+
data: err.message
|
|
856
|
+
});
|
|
857
|
+
} else {
|
|
858
|
+
_this._sendResponse({
|
|
859
|
+
seq: request.seq,
|
|
860
|
+
type: 101 /* CALL_FAILURE */ ,
|
|
861
|
+
data: String(err)
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
key: "_onSubscribe",
|
|
869
|
+
value: function _onSubscribe(request) {
|
|
870
|
+
var _this = this;
|
|
871
|
+
var channel = this._channels.get(request.channelName);
|
|
872
|
+
try {
|
|
873
|
+
if (!channel) {
|
|
874
|
+
throw new Error("[ChannelServer]: Channel not found!");
|
|
875
|
+
}
|
|
876
|
+
var observable = channel.subscribe(request.method, request.args);
|
|
877
|
+
var subscription = observable.subscribe({
|
|
878
|
+
next: function(data) {
|
|
879
|
+
_this._sendResponse({
|
|
880
|
+
seq: request.seq,
|
|
881
|
+
type: 200 /* SUBSCRIBE_NEXT */ ,
|
|
882
|
+
data: data
|
|
883
|
+
});
|
|
884
|
+
},
|
|
885
|
+
error: function(err) {
|
|
886
|
+
_this._sendResponse({
|
|
887
|
+
seq: request.seq,
|
|
888
|
+
type: 201 /* SUBSCRIBE_ERROR */ ,
|
|
889
|
+
data: err.message
|
|
890
|
+
});
|
|
891
|
+
_this._sendResponse({
|
|
892
|
+
seq: request.seq,
|
|
893
|
+
type: 202 /* SUBSCRIBE_COMPLETE */
|
|
894
|
+
});
|
|
895
|
+
},
|
|
896
|
+
complete: function() {
|
|
897
|
+
_this._sendResponse({
|
|
898
|
+
seq: request.seq,
|
|
899
|
+
type: 202 /* SUBSCRIBE_COMPLETE */
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
this._subscriptions.set(request.seq, subscription);
|
|
904
|
+
} catch (err) {
|
|
905
|
+
if (_instanceof(err, Error)) {
|
|
906
|
+
this._sendResponse({
|
|
907
|
+
seq: request.seq,
|
|
908
|
+
type: 201 /* SUBSCRIBE_ERROR */ ,
|
|
909
|
+
data: err.message
|
|
910
|
+
});
|
|
911
|
+
} else {
|
|
912
|
+
this._sendResponse({
|
|
913
|
+
seq: request.seq,
|
|
914
|
+
type: 201 /* SUBSCRIBE_ERROR */ ,
|
|
915
|
+
data: String(err)
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
key: "_onUnsubscribe",
|
|
923
|
+
value: function _onUnsubscribe(request) {
|
|
924
|
+
var subscription = this._subscriptions.get(request.seq);
|
|
925
|
+
if (subscription) {
|
|
926
|
+
subscription.unsubscribe();
|
|
927
|
+
this._subscriptions.delete(request.seq);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
key: "_sendResponse",
|
|
933
|
+
value: function _sendResponse(response) {
|
|
934
|
+
this._protocol.send(response);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
]);
|
|
938
|
+
return ChannelServer;
|
|
939
|
+
}(import_core4.RxDisposable);
|
|
940
|
+
var IRPCService = (0, import_redi2.createIdentifier)("IRPCService");
|
|
941
|
+
// src/plugin.ts
|
|
942
|
+
var ITestService = (0, import_redi3.createIdentifier)("ITestService");
|
|
943
|
+
var UniverRPCMainThreadPlugin = (_class = /*#__PURE__*/ function(_superClass) {
|
|
944
|
+
_inherits(_class, _superClass);
|
|
945
|
+
var _super = _create_super(_class);
|
|
946
|
+
function _class(_config, _injector) {
|
|
947
|
+
_class_call_check(this, _class);
|
|
948
|
+
var _this;
|
|
949
|
+
_this = _super.call(this, "UNIVER_RPC_MAIN_THREAD_PLUGIN");
|
|
950
|
+
_this._config = _config;
|
|
951
|
+
_this._injector = _injector;
|
|
952
|
+
return _this;
|
|
953
|
+
}
|
|
954
|
+
_create_class(_class, [
|
|
955
|
+
{
|
|
956
|
+
key: "onStarting",
|
|
957
|
+
value: function onStarting(injector) {
|
|
958
|
+
var _this = this;
|
|
959
|
+
return _async_to_generator(function() {
|
|
960
|
+
var worker, messageProtocol, client, server, dependencies;
|
|
961
|
+
return _ts_generator(this, function(_state) {
|
|
962
|
+
worker = new Worker(_this._config.workerURL);
|
|
963
|
+
messageProtocol = createWebWorkerMessagePortOnMain(worker);
|
|
964
|
+
client = new ChannelClient(messageProtocol);
|
|
965
|
+
server = new ChannelServer(messageProtocol);
|
|
966
|
+
dependencies = [
|
|
967
|
+
[
|
|
968
|
+
DataSyncPrimaryController,
|
|
969
|
+
{
|
|
970
|
+
useFactory: function() {
|
|
971
|
+
var _this__config;
|
|
972
|
+
var _this__config_unsyncMutations;
|
|
973
|
+
return injector.createInstance(DataSyncPrimaryController, (_this__config_unsyncMutations = (_this__config = _this._config) === null || _this__config === void 0 ? void 0 : _this__config.unsyncMutations) !== null && _this__config_unsyncMutations !== void 0 ? _this__config_unsyncMutations : /* @__PURE__ */ new Set());
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
],
|
|
977
|
+
[
|
|
978
|
+
IRemoteInstanceService,
|
|
979
|
+
{
|
|
980
|
+
useFactory: function() {
|
|
981
|
+
return toModule(client.getChannel(RemoteInstanceServiceName));
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
],
|
|
985
|
+
[
|
|
986
|
+
IRemoteSyncService,
|
|
987
|
+
{
|
|
988
|
+
useClass: RemoteSyncPrimaryService
|
|
989
|
+
}
|
|
990
|
+
]
|
|
991
|
+
];
|
|
992
|
+
dependencies.forEach(function(dependency) {
|
|
993
|
+
return injector.add(dependency);
|
|
994
|
+
});
|
|
995
|
+
server.registerChannel(RemoteSyncServiceName, fromModule(injector.get(IRemoteSyncService)));
|
|
996
|
+
return [
|
|
997
|
+
2
|
|
998
|
+
];
|
|
999
|
+
});
|
|
1000
|
+
})();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
]);
|
|
1004
|
+
return _class;
|
|
1005
|
+
}(_import_core5_Plugin = import_core5.Plugin), _define_property(_class, "type", import_core5.PluginType.Univer), _class);
|
|
1006
|
+
UniverRPCMainThreadPlugin = __decorateClass([
|
|
1007
|
+
__decorateParam(1, (0, import_redi3.Inject)(import_redi3.Injector))
|
|
1008
|
+
], UniverRPCMainThreadPlugin);
|
|
1009
|
+
var UniverRPCWorkerThreadPlugin = (_class1 = /*#__PURE__*/ function(_superClass) {
|
|
1010
|
+
_inherits(_class, _superClass);
|
|
1011
|
+
var _super = _create_super(_class);
|
|
1012
|
+
function _class(_config, _injector) {
|
|
1013
|
+
_class_call_check(this, _class);
|
|
1014
|
+
var _this;
|
|
1015
|
+
_this = _super.call(this, "UNIVER_RPC_WORKER_THREAD_PLUGIN");
|
|
1016
|
+
_this._config = _config;
|
|
1017
|
+
_this._injector = _injector;
|
|
1018
|
+
return _this;
|
|
1019
|
+
}
|
|
1020
|
+
_create_class(_class, [
|
|
1021
|
+
{
|
|
1022
|
+
key: "onStarting",
|
|
1023
|
+
value: function onStarting(injector) {
|
|
1024
|
+
var messageProtocol = createWebWorkerMessagePortOnWorker();
|
|
1025
|
+
var client = new ChannelClient(messageProtocol);
|
|
1026
|
+
var server = new ChannelServer(messageProtocol);
|
|
1027
|
+
var dependencies = [
|
|
1028
|
+
[
|
|
1029
|
+
DataSyncReplicaController
|
|
1030
|
+
],
|
|
1031
|
+
[
|
|
1032
|
+
IRemoteSyncService,
|
|
1033
|
+
{
|
|
1034
|
+
useFactory: function() {
|
|
1035
|
+
return toModule(client.getChannel(RemoteSyncServiceName));
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
],
|
|
1039
|
+
[
|
|
1040
|
+
IRemoteInstanceService,
|
|
1041
|
+
{
|
|
1042
|
+
useClass: RemoteInstanceReplicaService
|
|
1043
|
+
}
|
|
1044
|
+
]
|
|
1045
|
+
];
|
|
1046
|
+
dependencies.forEach(function(dependency) {
|
|
1047
|
+
return injector.add(dependency);
|
|
1048
|
+
});
|
|
1049
|
+
server.registerChannel(RemoteInstanceServiceName, fromModule(injector.get(IRemoteInstanceService)));
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
]);
|
|
1053
|
+
return _class;
|
|
1054
|
+
}(_import_core5_Plugin1 = import_core5.Plugin), _define_property(_class1, "type", import_core5.PluginType.Univer), _class1);
|
|
1055
|
+
UniverRPCWorkerThreadPlugin = __decorateClass([
|
|
1056
|
+
__decorateParam(1, (0, import_redi3.Inject)(import_redi3.Injector))
|
|
1057
|
+
], UniverRPCWorkerThreadPlugin);
|