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