@opensumi/ide-connection 2.27.3-rc-1714367598.0 → 2.27.3-rc-1715052394.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.d.ts +4 -0
- package/lib/browser/ws-channel-handler.d.ts.map +1 -1
- package/lib/browser/ws-channel-handler.js +48 -37
- package/lib/browser/ws-channel-handler.js.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.d.ts +1 -0
- package/lib/common/connection/drivers/reconnecting-websocket.d.ts.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.js +13 -3
- package/lib/common/connection/drivers/reconnecting-websocket.js.map +1 -1
- package/lib/common/connection/drivers/stream.d.ts +1 -0
- package/lib/common/connection/drivers/stream.d.ts.map +1 -1
- package/lib/common/connection/drivers/stream.js +20 -10
- package/lib/common/connection/drivers/stream.js.map +1 -1
- package/lib/common/protocols/common.d.ts +54 -0
- package/lib/common/protocols/common.d.ts.map +1 -1
- package/lib/common/protocols/common.js +17 -1
- package/lib/common/protocols/common.js.map +1 -1
- package/lib/common/protocols/extensions/ext-host-documents.d.ts +6 -0
- package/lib/common/protocols/extensions/ext-host-documents.d.ts.map +1 -0
- package/lib/common/protocols/extensions/ext-host-documents.js +68 -0
- package/lib/common/protocols/extensions/ext-host-documents.js.map +1 -0
- package/lib/common/rpc/message-io.d.ts.map +1 -1
- package/lib/common/rpc/message-io.js +4 -1
- package/lib/common/rpc/message-io.js.map +1 -1
- package/lib/common/rpc/multiplexer.d.ts +12 -2
- package/lib/common/rpc/multiplexer.d.ts.map +1 -1
- package/lib/common/rpc/multiplexer.js +19 -1
- package/lib/common/rpc/multiplexer.js.map +1 -1
- package/lib/common/rpc-service/center.d.ts.map +1 -1
- package/lib/common/rpc-service/center.js +5 -6
- package/lib/common/rpc-service/center.js.map +1 -1
- package/lib/node/common-channel-handler.d.ts +6 -0
- package/lib/node/common-channel-handler.d.ts.map +1 -1
- package/lib/node/common-channel-handler.js +1 -1
- package/lib/node/common-channel-handler.js.map +1 -1
- package/lib/node/ws.d.ts.map +1 -1
- package/lib/node/ws.js +3 -2
- package/lib/node/ws.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/ws-channel-handler.ts +59 -40
- package/src/common/connection/drivers/reconnecting-websocket.ts +14 -4
- package/src/common/connection/drivers/stream.ts +22 -11
- package/src/common/protocols/common.ts +19 -0
- package/src/common/protocols/extensions/ext-host-documents.ts +69 -0
- package/src/common/rpc/message-io.ts +6 -1
- package/src/common/rpc/multiplexer.ts +33 -2
- package/src/common/rpc-service/center.ts +5 -7
- package/src/node/common-channel-handler.ts +8 -2
- package/src/node/ws.ts +4 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseConnection } from '../connection';
|
|
2
2
|
|
|
3
3
|
import { ISumiConnectionOptions, SumiConnection } from './connection';
|
|
4
|
+
import { TSumiProtocol } from './types';
|
|
4
5
|
|
|
5
6
|
export class ProxyIdentifier<T = any> {
|
|
6
7
|
public static count = 0;
|
|
@@ -17,6 +18,13 @@ export class ProxyIdentifier<T = any> {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
export interface ISumiMultiplexerConnectionOptions extends ISumiConnectionOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Known protocols that will be loaded automatically when a proxy is created.
|
|
24
|
+
*/
|
|
25
|
+
knownProtocols?: Record<string, TSumiProtocol>;
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
export const IRPCProtocol = Symbol('IRPCProtocol');
|
|
21
29
|
export interface IRPCProtocol {
|
|
22
30
|
getProxy<T>(proxyId: ProxyIdentifier<T>): T;
|
|
@@ -46,11 +54,13 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
46
54
|
|
|
47
55
|
protected readonly _locals: Map<string, any>;
|
|
48
56
|
protected readonly _proxies: Map<string, any>;
|
|
57
|
+
protected _knownProtocols: Record<string, TSumiProtocol>;
|
|
49
58
|
|
|
50
|
-
constructor(protected socket: BaseConnection<Uint8Array>, protected options:
|
|
59
|
+
constructor(protected socket: BaseConnection<Uint8Array>, protected options: ISumiMultiplexerConnectionOptions = {}) {
|
|
51
60
|
super(socket, options);
|
|
52
61
|
this._locals = new Map();
|
|
53
62
|
this._proxies = new Map();
|
|
63
|
+
this._knownProtocols = options.knownProtocols || {};
|
|
54
64
|
|
|
55
65
|
this.onRequestNotFound((rpcName: string, args: any[]) => this._doInvokeHandler(rpcName, args));
|
|
56
66
|
|
|
@@ -60,7 +70,13 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
public set<T>(identifier: ProxyIdentifier<T>, instance: any) {
|
|
63
|
-
|
|
73
|
+
const id = SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId);
|
|
74
|
+
this._locals.set(id, instance);
|
|
75
|
+
const protocol = this._knownProtocols[identifier.serviceId];
|
|
76
|
+
if (protocol) {
|
|
77
|
+
this.loadProtocol(id, protocol);
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
return instance;
|
|
65
81
|
}
|
|
66
82
|
|
|
@@ -68,10 +84,21 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
68
84
|
return this._locals.get(SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId));
|
|
69
85
|
}
|
|
70
86
|
|
|
87
|
+
protected loadProtocol(rpcId: string, protocol: TSumiProtocol) {
|
|
88
|
+
this.io.loadProtocol(protocol, {
|
|
89
|
+
nameConverter: (str: string) => SumiConnectionMultiplexer.getRPCName(rpcId, str),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
public getProxy<T>(proxyId: ProxyIdentifier<T>) {
|
|
72
94
|
const serviceId = SumiConnectionMultiplexer.normalizeServiceId(proxyId.serviceId);
|
|
73
95
|
|
|
74
96
|
if (!this._proxies.has(serviceId)) {
|
|
97
|
+
const protocol = this._knownProtocols[proxyId.serviceId];
|
|
98
|
+
if (protocol) {
|
|
99
|
+
this.loadProtocol(serviceId, protocol);
|
|
100
|
+
}
|
|
101
|
+
|
|
75
102
|
this._proxies.set(serviceId, this._createProxy(serviceId));
|
|
76
103
|
}
|
|
77
104
|
|
|
@@ -111,4 +138,8 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
111
138
|
|
|
112
139
|
return method.apply(actor, args);
|
|
113
140
|
}
|
|
141
|
+
|
|
142
|
+
getSocket() {
|
|
143
|
+
return this.socket;
|
|
144
|
+
}
|
|
114
145
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Deferred } from '@opensumi/ide-core-common';
|
|
2
|
+
import { addElement } from '@opensumi/ide-utils/lib/arrays';
|
|
2
3
|
|
|
3
4
|
import { METHOD_NOT_REGISTERED } from '../constants';
|
|
4
5
|
import { TSumiProtocol } from '../rpc';
|
|
@@ -54,15 +55,14 @@ export class RPCServiceCenter {
|
|
|
54
55
|
|
|
55
56
|
this.protocolRegistry.applyTo(connection.io);
|
|
56
57
|
|
|
57
|
-
const index = this.proxies.length - 1;
|
|
58
58
|
const proxy = new ProxySumi(this.serviceRegistry, this.logger);
|
|
59
59
|
proxy.listen(connection);
|
|
60
60
|
|
|
61
|
-
this.proxies
|
|
61
|
+
const remove = addElement(this.proxies, proxy);
|
|
62
62
|
|
|
63
63
|
return {
|
|
64
64
|
dispose: () => {
|
|
65
|
-
|
|
65
|
+
remove.dispose();
|
|
66
66
|
proxy.dispose();
|
|
67
67
|
},
|
|
68
68
|
};
|
|
@@ -73,16 +73,14 @@ export class RPCServiceCenter {
|
|
|
73
73
|
this.deferred.resolve();
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const index = this.proxies.length - 1;
|
|
77
|
-
|
|
78
76
|
const proxy = new ProxyJson(this.serviceRegistry, this.logger);
|
|
79
77
|
proxy.listen(connection);
|
|
80
78
|
|
|
81
|
-
this.proxies
|
|
79
|
+
const remove = addElement(this.proxies, proxy);
|
|
82
80
|
|
|
83
81
|
return {
|
|
84
82
|
dispose: () => {
|
|
85
|
-
|
|
83
|
+
remove.dispose();
|
|
86
84
|
proxy.dispose();
|
|
87
85
|
},
|
|
88
86
|
};
|
|
@@ -9,6 +9,12 @@ import { CommonChannelHandlerOptions, WebSocketHandler } from './ws';
|
|
|
9
9
|
|
|
10
10
|
export { commonChannelPathHandler };
|
|
11
11
|
|
|
12
|
+
export interface WebSocketConnection extends WebSocket {
|
|
13
|
+
routeParam: {
|
|
14
|
+
pathname: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* Channel Handler for nodejs
|
|
14
20
|
*/
|
|
@@ -27,7 +33,7 @@ export class CommonChannelHandler extends BaseCommonChannelHandler implements We
|
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
private initWSServer() {
|
|
30
|
-
this.logger.log('init
|
|
36
|
+
this.logger.log('init common channel handler');
|
|
31
37
|
this.wsServer = new WebSocket.Server({
|
|
32
38
|
noServer: true,
|
|
33
39
|
...this.options.wsServerOptions,
|
|
@@ -43,7 +49,7 @@ export class CommonChannelHandler extends BaseCommonChannelHandler implements We
|
|
|
43
49
|
|
|
44
50
|
if (routeResult) {
|
|
45
51
|
this.wsServer.handleUpgrade(request, socket, head, (connection) => {
|
|
46
|
-
(connection as
|
|
52
|
+
(connection as WebSocketConnection).routeParam = {
|
|
47
53
|
pathname,
|
|
48
54
|
};
|
|
49
55
|
|
package/src/node/ws.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import http from 'http';
|
|
3
|
-
import url from 'url';
|
|
4
3
|
|
|
5
4
|
import ws from 'ws';
|
|
6
5
|
|
|
@@ -90,7 +89,10 @@ export class WebSocketServerRoute {
|
|
|
90
89
|
|
|
91
90
|
server.on('upgrade', (request, socket, head) => {
|
|
92
91
|
assert(request.url, 'cannot parse url from http request');
|
|
93
|
-
|
|
92
|
+
|
|
93
|
+
// request.url: `/path?query=a#hash`
|
|
94
|
+
const url = new URL(request.url, 'wss://base');
|
|
95
|
+
const wsPathname: string = url.pathname;
|
|
94
96
|
|
|
95
97
|
let wsHandlerIndex = 0;
|
|
96
98
|
const wsHandlerLength = wsServerHandlerArr.length;
|