@opensumi/ide-connection 2.27.3-rc-1715227667.0 → 3.0.0
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/lib/browser/ws-channel-handler.js +1 -1
- package/lib/browser/ws-channel-handler.js.map +1 -1
- package/lib/common/fury-extends/any.d.ts +20 -10
- package/lib/common/fury-extends/any.d.ts.map +1 -1
- package/lib/common/fury-extends/any.js +91 -69
- package/lib/common/fury-extends/any.js.map +1 -1
- package/lib/common/rpc/connection.d.ts.map +1 -1
- package/lib/common/rpc/connection.js +6 -6
- package/lib/common/rpc/connection.js.map +1 -1
- package/lib/common/rpc/message-io.d.ts +12 -0
- package/lib/common/rpc/message-io.d.ts.map +1 -1
- package/lib/common/rpc/message-io.js +7 -3
- package/lib/common/rpc/message-io.js.map +1 -1
- package/lib/common/rpc/multiplexer.d.ts.map +1 -1
- package/lib/common/rpc/multiplexer.js +3 -0
- package/lib/common/rpc/multiplexer.js.map +1 -1
- package/lib/common/rpc-service/center.d.ts +4 -1
- package/lib/common/rpc-service/center.d.ts.map +1 -1
- package/lib/common/rpc-service/center.js +7 -4
- package/lib/common/rpc-service/center.js.map +1 -1
- package/lib/common/rpc-service/index.d.ts.map +1 -1
- package/lib/common/rpc-service/registry.d.ts +8 -4
- package/lib/common/rpc-service/registry.d.ts.map +1 -1
- package/lib/common/rpc-service/registry.js +14 -6
- package/lib/common/rpc-service/registry.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/ws-channel-handler.ts +1 -1
- package/src/common/fury-extends/any.ts +85 -57
- package/src/common/rpc/connection.ts +7 -6
- package/src/common/rpc/message-io.ts +10 -6
- package/src/common/rpc/multiplexer.ts +3 -0
- package/src/common/rpc-service/center.ts +10 -6
- package/src/common/rpc-service/index.ts +1 -1
- package/src/common/rpc-service/registry.ts +27 -15
|
@@ -7,15 +7,15 @@ const constants_1 = require("../constants");
|
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const proxy_1 = require("./proxy");
|
|
9
9
|
const registry_1 = require("./registry");
|
|
10
|
-
const safeProcess = typeof process === 'undefined' ? { pid: 'unknown' } : process;
|
|
11
10
|
class RPCServiceCenter {
|
|
12
11
|
constructor(bench, logger) {
|
|
13
12
|
this.bench = bench;
|
|
13
|
+
this._disposables = new ide_core_common_1.DisposableStore();
|
|
14
14
|
this.proxies = [];
|
|
15
|
-
this.serviceRegistry = new registry_1.ServiceRegistry();
|
|
16
|
-
this.protocolRegistry = new registry_1.ProtocolRegistry();
|
|
15
|
+
this.serviceRegistry = this._disposables.add(new registry_1.ServiceRegistry());
|
|
16
|
+
this.protocolRegistry = this._disposables.add(new registry_1.ProtocolRegistry());
|
|
17
17
|
this.deferred = new ide_core_common_1.Deferred();
|
|
18
|
-
this.uid =
|
|
18
|
+
this.uid = (0, ide_core_common_1.randomString)(6);
|
|
19
19
|
this.logger = logger || console;
|
|
20
20
|
}
|
|
21
21
|
registerService(serviceName, type) {
|
|
@@ -95,6 +95,9 @@ class RPCServiceCenter {
|
|
|
95
95
|
// or just return `undefined`.
|
|
96
96
|
return result.length === 1 ? result[0] : result;
|
|
97
97
|
}
|
|
98
|
+
dispose() {
|
|
99
|
+
this._disposables.dispose();
|
|
100
|
+
}
|
|
98
101
|
}
|
|
99
102
|
exports.RPCServiceCenter = RPCServiceCenter;
|
|
100
103
|
function getNotificationName(serviceName, name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"center.js","sourceRoot":"","sources":["../../../src/common/rpc-service/center.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"center.js","sourceRoot":"","sources":["../../../src/common/rpc-service/center.ts"],"names":[],"mappings":";;;AAAA,+DAAiG;AACjG,2DAA4D;AAE5D,4CAAqD;AAGrD,oCAA0E;AAE1E,mCAA+C;AAE/C,yCAA+D;AAI/D,MAAa,gBAAgB;IAa3B,YAAoB,KAAc,EAAE,MAAgB;QAAhC,UAAK,GAAL,KAAK,CAAS;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AAW,IAAI,IAAI,EAAE,CAAC;AACrC,CAAC;AAFD,kDAEC;AACD,SAAgB,cAAc,CAAC,WAAmB,EAAE,IAAY;IAC9D,OAAO,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC;AAClC,CAAC;AAFD,wCAEC;AAED,SAAgB,aAAa,CAAC,WAAmB,EAAE,IAAY;IAC7D,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC5G,CAAC;AAFD,sCAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AAEzB,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG;IACtC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC;IAC7B,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AAEzB,8BAAsB,UAAU,CAAC,CAAC,GAAG,GAAG;IACtC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC;IAC7B,IAAI,MAAM,IAAI,CAAC,GAAG,SAAS,CAE1B;CACF"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { Emitter } from '@opensumi/ide-core-common';
|
|
1
|
+
import { DisposableStore, Emitter, IDisposable } from '@opensumi/ide-core-common';
|
|
2
2
|
import { MessageIO, TSumiProtocol } from '../rpc';
|
|
3
3
|
import { RPCServiceMethod } from '../types';
|
|
4
4
|
export declare function getServiceMethods(service: any): string[];
|
|
5
5
|
/**
|
|
6
6
|
* Store all executable services, and provide a way to invoke them.
|
|
7
7
|
*/
|
|
8
|
-
export declare class ServiceRegistry {
|
|
8
|
+
export declare class ServiceRegistry implements IDisposable {
|
|
9
|
+
private _disposables;
|
|
9
10
|
protected emitter: Emitter<string[]>;
|
|
10
|
-
private serviceMethodMap;
|
|
11
11
|
onServicesUpdate: import("@opensumi/ide-core-common").Event<string[]>;
|
|
12
|
+
private serviceMethodMap;
|
|
12
13
|
register(name: string, methodFn: RPCServiceMethod): void;
|
|
13
14
|
registerService(service: any, options?: {
|
|
14
15
|
nameConverter?: (str: string) => string;
|
|
@@ -16,14 +17,17 @@ export declare class ServiceRegistry {
|
|
|
16
17
|
has(name: PropertyKey): boolean;
|
|
17
18
|
invoke(name: PropertyKey, ...args: any[]): any;
|
|
18
19
|
methods(): PropertyKey[];
|
|
20
|
+
dispose(): void;
|
|
19
21
|
}
|
|
20
22
|
export declare class ProtocolRegistry {
|
|
23
|
+
protected _disposables: DisposableStore;
|
|
21
24
|
protected emitter: Emitter<string[]>;
|
|
22
|
-
private protocolMap;
|
|
23
25
|
onProtocolUpdate: import("@opensumi/ide-core-common").Event<string[]>;
|
|
26
|
+
private protocolMap;
|
|
24
27
|
addProtocol(protocol: TSumiProtocol, options?: {
|
|
25
28
|
nameConverter?: (str: string) => string;
|
|
26
29
|
}): void;
|
|
27
30
|
applyTo(io: MessageIO): void;
|
|
31
|
+
dispose(): void;
|
|
28
32
|
}
|
|
29
33
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM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+27,10 @@ exports.getServiceMethods = getServiceMethods;
|
|
|
27
27
|
*/
|
|
28
28
|
class ServiceRegistry {
|
|
29
29
|
constructor() {
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
30
|
+
this._disposables = new ide_core_common_1.DisposableStore();
|
|
31
|
+
this.emitter = this._disposables.add(new ide_core_common_1.Emitter());
|
|
32
32
|
this.onServicesUpdate = this.emitter.event;
|
|
33
|
+
this.serviceMethodMap = new Map();
|
|
33
34
|
}
|
|
34
35
|
register(name, methodFn) {
|
|
35
36
|
this.serviceMethodMap.set(name, methodFn);
|
|
@@ -60,13 +61,17 @@ class ServiceRegistry {
|
|
|
60
61
|
methods() {
|
|
61
62
|
return Array.from(this.serviceMethodMap.keys());
|
|
62
63
|
}
|
|
64
|
+
dispose() {
|
|
65
|
+
this._disposables.dispose();
|
|
66
|
+
}
|
|
63
67
|
}
|
|
64
68
|
exports.ServiceRegistry = ServiceRegistry;
|
|
65
69
|
class ProtocolRegistry {
|
|
66
70
|
constructor() {
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
71
|
+
this._disposables = new ide_core_common_1.DisposableStore();
|
|
72
|
+
this.emitter = this._disposables.add(new ide_core_common_1.Emitter());
|
|
69
73
|
this.onProtocolUpdate = this.emitter.event;
|
|
74
|
+
this.protocolMap = new Map();
|
|
70
75
|
}
|
|
71
76
|
addProtocol(protocol, options) {
|
|
72
77
|
const serviceNames = [];
|
|
@@ -86,14 +91,17 @@ class ProtocolRegistry {
|
|
|
86
91
|
for (const protocol of this.protocolMap.values()) {
|
|
87
92
|
io.loadProtocolMethod(protocol);
|
|
88
93
|
}
|
|
89
|
-
this.onProtocolUpdate((methods) => {
|
|
94
|
+
this._disposables.add(this.onProtocolUpdate((methods) => {
|
|
90
95
|
for (const method of methods) {
|
|
91
96
|
const protocol = this.protocolMap.get(method);
|
|
92
97
|
if (protocol) {
|
|
93
98
|
io.loadProtocolMethod(protocol);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
|
-
});
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
dispose() {
|
|
104
|
+
this._disposables.dispose();
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
exports.ProtocolRegistry = ProtocolRegistry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":";;;AAAA,+DAAkF;AAKlF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAE7C,SAAgB,iBAAiB,CAAC,OAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,GAAG;QACD,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAEtD,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;YAChC,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACzB,SAAS;aACV;YAED,IAAI,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE;gBACvC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACjB;SACF;KACF,QAAQ,CAAC,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE;IAE7C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,EAAE,CAAC;IACb,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,8CAqBC;AAED;;GAEG;AACH,MAAa,eAAe;IAA5B;QACU,iBAAY,GAAG,IAAI,iCAAe,EAAE,CAAC;QAEnC,YAAO,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,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I,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,EAAE;YAChC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC9C,IAAI,QAAQ,EAAE;oBACZ,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;iBACjC;aACF;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CACF;AAtDD,4CAsDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-connection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@furyjs/fury": "0.5.9-beta",
|
|
21
21
|
"@opensumi/events": "^1.0.0",
|
|
22
|
-
"@opensumi/ide-core-common": "
|
|
22
|
+
"@opensumi/ide-core-common": "3.0.0",
|
|
23
23
|
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
|
|
24
24
|
"path-to-regexp": "^6.2.1",
|
|
25
25
|
"reconnecting-websocket": "^4.4.0",
|
|
26
26
|
"ws": "^8.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@opensumi/ide-components": "
|
|
30
|
-
"@opensumi/ide-dev-tool": "
|
|
29
|
+
"@opensumi/ide-components": "3.0.0",
|
|
30
|
+
"@opensumi/ide-dev-tool": "3.0.0",
|
|
31
31
|
"@opensumi/mock-socket": "^9.3.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "645e9b96cff0373b5ef36f15c7fd194432f53c92"
|
|
34
34
|
}
|
|
@@ -131,7 +131,7 @@ export class WSChannelHandler {
|
|
|
131
131
|
closeEvent: { code, reason },
|
|
132
132
|
connectInfo: (navigator as any).connection as ConnectionInfo,
|
|
133
133
|
});
|
|
134
|
-
this.logger.log(this.LOG_TAG,
|
|
134
|
+
this.logger.log(this.LOG_TAG, `channel close: code: ${code}, reason: ${reason}`);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const deferred = new Deferred<void>();
|
|
@@ -6,11 +6,9 @@ export enum ProtocolType {
|
|
|
6
6
|
String,
|
|
7
7
|
Buffer,
|
|
8
8
|
Number,
|
|
9
|
-
Int32,
|
|
10
9
|
JSONObject,
|
|
11
10
|
BigInt,
|
|
12
11
|
Array,
|
|
13
|
-
Union,
|
|
14
12
|
Object,
|
|
15
13
|
Undefined,
|
|
16
14
|
Null,
|
|
@@ -18,63 +16,66 @@ export enum ProtocolType {
|
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export class AnySerializer {
|
|
21
|
-
constructor(
|
|
19
|
+
constructor(
|
|
20
|
+
protected writer: BinaryWriter,
|
|
21
|
+
protected reader: BinaryReader,
|
|
22
|
+
protected objectTransfer?: IObjectTransfer,
|
|
23
|
+
) {}
|
|
22
24
|
|
|
23
25
|
write(data: any) {
|
|
24
26
|
const { writer } = this;
|
|
25
27
|
const type = typeof data;
|
|
26
28
|
writer.reserve(1);
|
|
27
29
|
|
|
28
|
-
switch (
|
|
29
|
-
case
|
|
30
|
-
writer.uint8(ProtocolType.
|
|
31
|
-
|
|
32
|
-
case 'string':
|
|
33
|
-
writer.uint8(ProtocolType.String);
|
|
34
|
-
writer.stringOfVarUInt32(data);
|
|
35
|
-
break;
|
|
36
|
-
case 'boolean':
|
|
37
|
-
writer.reserve(1);
|
|
38
|
-
writer.uint8(ProtocolType.Boolean);
|
|
39
|
-
writer.uint8(data ? 1 : 0);
|
|
40
|
-
break;
|
|
41
|
-
case 'number':
|
|
42
|
-
writer.reserve(8);
|
|
43
|
-
if ((data | 0) === data) {
|
|
44
|
-
writer.uint8(ProtocolType.Int32);
|
|
45
|
-
writer.int32(data);
|
|
46
|
-
} else {
|
|
47
|
-
writer.uint8(ProtocolType.Number);
|
|
48
|
-
writer.double(data);
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
case 'bigint':
|
|
52
|
-
writer.reserve(8);
|
|
53
|
-
writer.uint8(ProtocolType.BigInt);
|
|
54
|
-
writer.int64(data);
|
|
55
|
-
break;
|
|
56
|
-
case 'object':
|
|
57
|
-
if (data === null) {
|
|
58
|
-
writer.uint8(ProtocolType.Null);
|
|
59
|
-
} else if (Array.isArray(data)) {
|
|
60
|
-
writer.reserve(4);
|
|
61
|
-
writer.uint8(ProtocolType.Array);
|
|
62
|
-
writer.varUInt32(data.length);
|
|
63
|
-
for (const element of data) {
|
|
64
|
-
this.write(element);
|
|
65
|
-
}
|
|
66
|
-
} else if (isUint8Array(data)) {
|
|
67
|
-
writer.reserve(4);
|
|
68
|
-
writer.uint8(ProtocolType.Buffer);
|
|
69
|
-
writer.varUInt32(data.byteLength);
|
|
70
|
-
writer.buffer(data);
|
|
71
|
-
} else {
|
|
72
|
-
writer.uint8(ProtocolType.JSONObject);
|
|
73
|
-
writer.stringOfVarUInt32(JSON.stringify(data, ObjectTransfer.replacer));
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
30
|
+
switch (data) {
|
|
31
|
+
case null:
|
|
32
|
+
writer.uint8(ProtocolType.Null);
|
|
33
|
+
return;
|
|
76
34
|
default:
|
|
77
|
-
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'undefined':
|
|
37
|
+
writer.uint8(ProtocolType.Undefined);
|
|
38
|
+
break;
|
|
39
|
+
case 'string':
|
|
40
|
+
writer.uint8(ProtocolType.String);
|
|
41
|
+
writer.stringOfVarUInt32(data);
|
|
42
|
+
break;
|
|
43
|
+
case 'boolean':
|
|
44
|
+
writer.reserve(1);
|
|
45
|
+
writer.uint8(ProtocolType.Boolean);
|
|
46
|
+
writer.uint8(data ? 1 : 0);
|
|
47
|
+
break;
|
|
48
|
+
case 'number':
|
|
49
|
+
writer.reserve(8);
|
|
50
|
+
writer.uint8(ProtocolType.Number);
|
|
51
|
+
writer.double(data);
|
|
52
|
+
break;
|
|
53
|
+
case 'bigint':
|
|
54
|
+
writer.reserve(8);
|
|
55
|
+
writer.uint8(ProtocolType.BigInt);
|
|
56
|
+
writer.int64(data);
|
|
57
|
+
break;
|
|
58
|
+
case 'object':
|
|
59
|
+
if (Array.isArray(data)) {
|
|
60
|
+
writer.reserve(4);
|
|
61
|
+
writer.uint8(ProtocolType.Array);
|
|
62
|
+
writer.varUInt32(data.length);
|
|
63
|
+
for (const element of data) {
|
|
64
|
+
this.write(element);
|
|
65
|
+
}
|
|
66
|
+
} else if (isUint8Array(data)) {
|
|
67
|
+
writer.reserve(4);
|
|
68
|
+
writer.uint8(ProtocolType.Buffer);
|
|
69
|
+
writer.varUInt32(data.byteLength);
|
|
70
|
+
writer.buffer(data);
|
|
71
|
+
} else {
|
|
72
|
+
writer.uint8(ProtocolType.JSONObject);
|
|
73
|
+
writer.stringOfVarUInt32(JSON.stringify(data, this.objectTransfer?.replacer));
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unknown type ${type}`);
|
|
78
|
+
}
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -93,13 +94,11 @@ export class AnySerializer {
|
|
|
93
94
|
const length = reader.varUInt32();
|
|
94
95
|
return reader.buffer(length);
|
|
95
96
|
}
|
|
96
|
-
case ProtocolType.Int32:
|
|
97
|
-
return reader.int32();
|
|
98
97
|
case ProtocolType.Number:
|
|
99
98
|
return reader.double();
|
|
100
99
|
case ProtocolType.JSONObject: {
|
|
101
100
|
const json = reader.stringOfVarUInt32();
|
|
102
|
-
return JSON.parse(json,
|
|
101
|
+
return JSON.parse(json, this.objectTransfer?.reviver);
|
|
103
102
|
}
|
|
104
103
|
case ProtocolType.BigInt:
|
|
105
104
|
return reader.int64();
|
|
@@ -132,10 +131,19 @@ export class AnySerializer {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
enum EObjectTransferType {
|
|
135
|
-
CODE_URI = '
|
|
134
|
+
CODE_URI = 'CodeURI',
|
|
135
|
+
BUFFER = 'Buffer',
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
export interface IObjectTransfer {
|
|
139
|
+
replacer(key: string | undefined, value: any): any;
|
|
140
|
+
reviver(key: string | undefined, value: any): any;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* For transfering object between browser and extension
|
|
145
|
+
*/
|
|
146
|
+
export class ExtObjectTransfer {
|
|
139
147
|
static replacer(key: string | undefined, value: any) {
|
|
140
148
|
if (value) {
|
|
141
149
|
switch (value.$mid) {
|
|
@@ -148,6 +156,24 @@ class ObjectTransfer {
|
|
|
148
156
|
};
|
|
149
157
|
}
|
|
150
158
|
}
|
|
159
|
+
|
|
160
|
+
if (value instanceof Uint8Array || value instanceof Uint32Array || value instanceof Uint16Array) {
|
|
161
|
+
return {
|
|
162
|
+
$type: 'Buffer',
|
|
163
|
+
data: Array.from(value),
|
|
164
|
+
};
|
|
165
|
+
} else if (value instanceof ArrayBuffer) {
|
|
166
|
+
return {
|
|
167
|
+
$type: 'Buffer',
|
|
168
|
+
data: Array.from(new Uint8Array(value)),
|
|
169
|
+
};
|
|
170
|
+
} else if (value.type === 'Buffer') {
|
|
171
|
+
// https://nodejs.org/api/buffer.html#buftojson
|
|
172
|
+
return {
|
|
173
|
+
$type: 'Buffer',
|
|
174
|
+
data: value.data,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
151
177
|
}
|
|
152
178
|
|
|
153
179
|
return value;
|
|
@@ -157,6 +183,8 @@ class ObjectTransfer {
|
|
|
157
183
|
switch (value.$type) {
|
|
158
184
|
case EObjectTransferType.CODE_URI:
|
|
159
185
|
return Uri.parse(value.data);
|
|
186
|
+
case EObjectTransferType.BUFFER:
|
|
187
|
+
return Uint8Array.from(value.data);
|
|
160
188
|
}
|
|
161
189
|
}
|
|
162
190
|
return value;
|
|
@@ -40,6 +40,10 @@ export interface ISumiConnectionOptions {
|
|
|
40
40
|
name?: string;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const chunkedResponseHeaders: IResponseHeaders = {
|
|
44
|
+
chunked: true,
|
|
45
|
+
};
|
|
46
|
+
|
|
43
47
|
export class SumiConnection implements IDisposable {
|
|
44
48
|
protected disposable = new DisposableStore();
|
|
45
49
|
|
|
@@ -310,18 +314,15 @@ export class SumiConnection implements IDisposable {
|
|
|
310
314
|
this.capturer.captureOnRequestResult(requestId, method, result);
|
|
311
315
|
|
|
312
316
|
if (isReadableStream(result)) {
|
|
313
|
-
const responseHeaders: IResponseHeaders = {
|
|
314
|
-
chunked: true,
|
|
315
|
-
};
|
|
316
317
|
listenReadable(result, {
|
|
317
318
|
onData: (data) => {
|
|
318
|
-
this.socket.send(this.io.Response(requestId, method,
|
|
319
|
+
this.socket.send(this.io.Response(requestId, method, chunkedResponseHeaders, data));
|
|
319
320
|
},
|
|
320
321
|
onEnd: () => {
|
|
321
|
-
this.socket.send(this.io.Response(requestId, method,
|
|
322
|
+
this.socket.send(this.io.Response(requestId, method, chunkedResponseHeaders, null));
|
|
322
323
|
},
|
|
323
324
|
onError: (err) => {
|
|
324
|
-
this.socket.send(this.io.Error(requestId, method,
|
|
325
|
+
this.socket.send(this.io.Error(requestId, method, chunkedResponseHeaders, err));
|
|
325
326
|
},
|
|
326
327
|
});
|
|
327
328
|
} else {
|
|
@@ -4,7 +4,7 @@ import { BinaryReader, BinaryWriter } from '@furyjs/fury/dist/lib/type';
|
|
|
4
4
|
|
|
5
5
|
import { stringifyError } from '@opensumi/ide-core-common/lib/utils';
|
|
6
6
|
|
|
7
|
-
import { AnySerializer } from '../fury-extends/any';
|
|
7
|
+
import { AnySerializer, IObjectTransfer } from '../fury-extends/any';
|
|
8
8
|
import { furyFactory } from '../fury-extends/shared';
|
|
9
9
|
|
|
10
10
|
import {
|
|
@@ -84,11 +84,11 @@ class SumiProtocolSerializer implements IProtocolSerializer {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
class AnyProtocolSerializer implements IProtocolSerializer {
|
|
88
|
-
anySerializer: AnySerializer;
|
|
87
|
+
export class AnyProtocolSerializer implements IProtocolSerializer {
|
|
88
|
+
protected anySerializer: AnySerializer;
|
|
89
89
|
|
|
90
|
-
constructor(public writer: BinaryWriter, public reader: BinaryReader) {
|
|
91
|
-
this.anySerializer = new AnySerializer(this.writer, this.reader);
|
|
90
|
+
constructor(public writer: BinaryWriter, public reader: BinaryReader, objectTransfer?: IObjectTransfer) {
|
|
91
|
+
this.anySerializer = new AnySerializer(this.writer, this.reader, objectTransfer);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
writeRequest(args: any[]): void {
|
|
@@ -112,7 +112,7 @@ export class MessageIO {
|
|
|
112
112
|
|
|
113
113
|
private serializerMap = new Map<string, SumiProtocolSerializer>();
|
|
114
114
|
|
|
115
|
-
private anySerializer:
|
|
115
|
+
private anySerializer: IProtocolSerializer;
|
|
116
116
|
|
|
117
117
|
requestHeadersSerializer: Serializer<IRequestHeaders, IRequestHeaders>;
|
|
118
118
|
responseHeadersSerializer: Serializer<IResponseHeaders, IRequestHeaders>;
|
|
@@ -129,6 +129,10 @@ export class MessageIO {
|
|
|
129
129
|
this.anySerializer = new AnyProtocolSerializer(this.writer, this.reader);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
setAnySerializer(serializer: IProtocolSerializer) {
|
|
133
|
+
this.anySerializer = serializer;
|
|
134
|
+
}
|
|
135
|
+
|
|
132
136
|
has(name: string) {
|
|
133
137
|
return this.serializerMap.has(name);
|
|
134
138
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BaseConnection } from '../connection';
|
|
2
|
+
import { ExtObjectTransfer } from '../fury-extends/any';
|
|
2
3
|
|
|
3
4
|
import { ISumiConnectionOptions, SumiConnection } from './connection';
|
|
5
|
+
import { AnyProtocolSerializer } from './message-io';
|
|
4
6
|
import { TSumiProtocol } from './types';
|
|
5
7
|
|
|
6
8
|
export class ProxyIdentifier<T = any> {
|
|
@@ -61,6 +63,7 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
61
63
|
this._locals = new Map();
|
|
62
64
|
this._proxies = new Map();
|
|
63
65
|
this._knownProtocols = options.knownProtocols || {};
|
|
66
|
+
this.io.setAnySerializer(new AnyProtocolSerializer(this.io.writer, this.io.reader, ExtObjectTransfer));
|
|
64
67
|
|
|
65
68
|
this.onRequestNotFound((rpcName: string, args: any[]) => this._doInvokeHandler(rpcName, args));
|
|
66
69
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Deferred } from '@opensumi/ide-core-common';
|
|
1
|
+
import { Deferred, DisposableStore, IDisposable, randomString } from '@opensumi/ide-core-common';
|
|
2
2
|
import { addElement } from '@opensumi/ide-utils/lib/arrays';
|
|
3
3
|
|
|
4
4
|
import { METHOD_NOT_REGISTERED } from '../constants';
|
|
@@ -12,21 +12,21 @@ import { ProtocolRegistry, ServiceRegistry } from './registry';
|
|
|
12
12
|
|
|
13
13
|
import type { MessageConnection } from '@opensumi/vscode-jsonrpc';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
export class RPCServiceCenter implements IDisposable {
|
|
16
|
+
private _disposables = new DisposableStore();
|
|
16
17
|
|
|
17
|
-
export class RPCServiceCenter {
|
|
18
18
|
public uid: string;
|
|
19
19
|
|
|
20
20
|
private proxies: ProxyBase<any>[] = [];
|
|
21
21
|
|
|
22
|
-
private serviceRegistry = new ServiceRegistry();
|
|
23
|
-
private protocolRegistry = new ProtocolRegistry();
|
|
22
|
+
private serviceRegistry = this._disposables.add(new ServiceRegistry());
|
|
23
|
+
private protocolRegistry = this._disposables.add(new ProtocolRegistry());
|
|
24
24
|
|
|
25
25
|
private deferred = new Deferred<void>();
|
|
26
26
|
private logger: ILogger;
|
|
27
27
|
|
|
28
28
|
constructor(private bench?: IBench, logger?: ILogger) {
|
|
29
|
-
this.uid =
|
|
29
|
+
this.uid = randomString(6);
|
|
30
30
|
this.logger = logger || console;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -125,6 +125,10 @@ export class RPCServiceCenter {
|
|
|
125
125
|
// or just return `undefined`.
|
|
126
126
|
return result.length === 1 ? result[0] : result;
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
dispose(): void {
|
|
130
|
+
this._disposables.dispose();
|
|
131
|
+
}
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
export function getNotificationName(serviceName: string, name: string) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Emitter } from '@opensumi/ide-core-common';
|
|
1
|
+
import { DisposableStore, Emitter, IDisposable } from '@opensumi/ide-core-common';
|
|
2
2
|
|
|
3
3
|
import { MessageIO, TSumiProtocol, TSumiProtocolMethod } from '../rpc';
|
|
4
4
|
import { RPCServiceMethod } from '../types';
|
|
@@ -31,13 +31,14 @@ export function getServiceMethods(service: any): string[] {
|
|
|
31
31
|
/**
|
|
32
32
|
* Store all executable services, and provide a way to invoke them.
|
|
33
33
|
*/
|
|
34
|
-
export class ServiceRegistry {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private serviceMethodMap = new Map<PropertyKey, RPCServiceMethod>();
|
|
34
|
+
export class ServiceRegistry implements IDisposable {
|
|
35
|
+
private _disposables = new DisposableStore();
|
|
38
36
|
|
|
37
|
+
protected emitter = this._disposables.add(new Emitter<string[]>());
|
|
39
38
|
onServicesUpdate = this.emitter.event;
|
|
40
39
|
|
|
40
|
+
private serviceMethodMap = new Map<PropertyKey, RPCServiceMethod>();
|
|
41
|
+
|
|
41
42
|
register(name: string, methodFn: RPCServiceMethod) {
|
|
42
43
|
this.serviceMethodMap.set(name, methodFn);
|
|
43
44
|
this.emitter.fire([name]);
|
|
@@ -78,15 +79,20 @@ export class ServiceRegistry {
|
|
|
78
79
|
methods() {
|
|
79
80
|
return Array.from(this.serviceMethodMap.keys());
|
|
80
81
|
}
|
|
82
|
+
|
|
83
|
+
dispose() {
|
|
84
|
+
this._disposables.dispose();
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
export class ProtocolRegistry {
|
|
84
|
-
protected
|
|
85
|
-
|
|
86
|
-
private protocolMap = new Map<PropertyKey, TSumiProtocolMethod>();
|
|
89
|
+
protected _disposables = new DisposableStore();
|
|
87
90
|
|
|
91
|
+
protected emitter = this._disposables.add(new Emitter<string[]>());
|
|
88
92
|
onProtocolUpdate = this.emitter.event;
|
|
89
93
|
|
|
94
|
+
private protocolMap = new Map<PropertyKey, TSumiProtocolMethod>();
|
|
95
|
+
|
|
90
96
|
addProtocol(
|
|
91
97
|
protocol: TSumiProtocol,
|
|
92
98
|
options?: {
|
|
@@ -118,13 +124,19 @@ export class ProtocolRegistry {
|
|
|
118
124
|
io.loadProtocolMethod(protocol);
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
this._disposables.add(
|
|
128
|
+
this.onProtocolUpdate((methods) => {
|
|
129
|
+
for (const method of methods) {
|
|
130
|
+
const protocol = this.protocolMap.get(method);
|
|
131
|
+
if (protocol) {
|
|
132
|
+
io.loadProtocolMethod(protocol);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
dispose() {
|
|
140
|
+
this._disposables.dispose();
|
|
129
141
|
}
|
|
130
142
|
}
|