@opensumi/ide-connection 2.27.3-rc-1708399099.0 → 2.27.3-rc-1710489030.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/README.md +1 -1
- package/lib/browser/ws-channel-handler.d.ts +1 -1
- package/lib/browser/ws-channel-handler.d.ts.map +1 -1
- package/lib/browser/ws-channel-handler.js +23 -33
- package/lib/browser/ws-channel-handler.js.map +1 -1
- package/lib/common/buffers/buffers.d.ts +1 -0
- package/lib/common/buffers/buffers.d.ts.map +1 -1
- package/lib/common/buffers/buffers.js +3 -3
- package/lib/common/buffers/buffers.js.map +1 -1
- package/lib/common/{utils.d.ts → capturer.d.ts} +1 -19
- package/lib/common/capturer.d.ts.map +1 -0
- package/lib/common/capturer.js +26 -0
- package/lib/common/capturer.js.map +1 -0
- package/lib/common/connection/drivers/frame-decoder.d.ts +40 -1
- package/lib/common/connection/drivers/frame-decoder.d.ts.map +1 -1
- package/lib/common/connection/drivers/frame-decoder.js +9 -10
- package/lib/common/connection/drivers/frame-decoder.js.map +1 -1
- package/lib/common/connection/drivers/index.d.ts +0 -1
- package/lib/common/connection/drivers/index.d.ts.map +1 -1
- package/lib/common/connection/drivers/index.js +0 -1
- package/lib/common/connection/drivers/index.js.map +1 -1
- package/lib/common/connection/drivers/message-port.d.ts.map +1 -1
- package/lib/common/connection/drivers/message-port.js +1 -4
- package/lib/common/connection/drivers/message-port.js.map +1 -1
- package/lib/common/connection/drivers/node-message-port.d.ts +1 -1
- package/lib/common/connection/drivers/node-message-port.d.ts.map +1 -1
- package/lib/common/connection/drivers/node-message-port.js.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.d.ts.map +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.js +1 -1
- package/lib/common/connection/drivers/reconnecting-websocket.js.map +1 -1
- package/lib/common/connection/drivers/socket.d.ts +3 -10
- package/lib/common/connection/drivers/socket.d.ts.map +1 -1
- package/lib/common/connection/drivers/socket.js +3 -36
- package/lib/common/connection/drivers/socket.js.map +1 -1
- package/lib/common/connection/drivers/stream.d.ts +17 -0
- package/lib/common/connection/drivers/stream.d.ts.map +1 -0
- package/lib/common/connection/drivers/stream.js +70 -0
- package/lib/common/connection/drivers/stream.js.map +1 -0
- package/lib/common/connection/drivers/ws-websocket.d.ts +1 -1
- package/lib/common/connection/drivers/ws-websocket.d.ts.map +1 -1
- package/lib/common/connection/drivers/ws-websocket.js.map +1 -1
- package/lib/common/fury-extends/any.d.ts +10 -7
- package/lib/common/fury-extends/any.d.ts.map +1 -1
- package/lib/common/fury-extends/any.js +126 -105
- package/lib/common/fury-extends/any.js.map +1 -1
- package/lib/common/fury-extends/one-of.d.ts +10 -5
- package/lib/common/fury-extends/one-of.d.ts.map +1 -1
- package/lib/common/fury-extends/one-of.js +65 -30
- package/lib/common/fury-extends/one-of.js.map +1 -1
- package/lib/common/fury-extends/shared.d.ts +2 -0
- package/lib/common/fury-extends/shared.d.ts.map +1 -1
- package/lib/common/fury-extends/shared.js.map +1 -1
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -2
- package/lib/common/index.js.map +1 -1
- package/lib/common/message.d.ts +1 -1
- package/lib/common/message.d.ts.map +1 -1
- package/lib/common/rpc/connection.d.ts +31 -15
- package/lib/common/rpc/connection.d.ts.map +1 -1
- package/lib/common/rpc/connection.js +206 -138
- package/lib/common/rpc/connection.js.map +1 -1
- package/lib/common/rpc/index.d.ts +1 -1
- package/lib/common/rpc/index.d.ts.map +1 -1
- package/lib/common/rpc/index.js +1 -1
- package/lib/common/rpc/index.js.map +1 -1
- package/lib/common/rpc/message-io.d.ts +61 -0
- package/lib/common/rpc/message-io.d.ts.map +1 -0
- package/lib/common/rpc/message-io.js +159 -0
- package/lib/common/rpc/message-io.js.map +1 -0
- package/lib/common/rpc/multiplexer.d.ts +3 -0
- 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/types.d.ts +26 -5
- package/lib/common/rpc/types.d.ts.map +1 -1
- package/lib/common/rpc-service/center.d.ts +6 -3
- package/lib/common/rpc-service/center.d.ts.map +1 -1
- package/lib/common/rpc-service/center.js +39 -31
- package/lib/common/rpc-service/center.js.map +1 -1
- package/lib/common/rpc-service/proxy/base.d.ts +5 -3
- package/lib/common/rpc-service/proxy/base.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/base.js +56 -17
- package/lib/common/rpc-service/proxy/base.js.map +1 -1
- package/lib/common/rpc-service/proxy/index.d.ts +1 -3
- package/lib/common/rpc-service/proxy/index.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/index.js +1 -3
- package/lib/common/rpc-service/proxy/index.js.map +1 -1
- package/lib/common/rpc-service/proxy/{legacy.d.ts → json.d.ts} +5 -5
- package/lib/common/rpc-service/proxy/json.d.ts.map +1 -0
- package/lib/common/rpc-service/proxy/{legacy.js → json.js} +46 -56
- package/lib/common/rpc-service/proxy/json.js.map +1 -0
- package/lib/common/rpc-service/proxy/sumi.d.ts +1 -1
- package/lib/common/rpc-service/proxy/sumi.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/sumi.js +25 -37
- package/lib/common/rpc-service/proxy/sumi.js.map +1 -1
- package/lib/common/rpc-service/{proxy/registry.d.ts → registry.d.ts} +12 -1
- package/lib/common/rpc-service/registry.d.ts.map +1 -0
- package/lib/common/rpc-service/registry.js +99 -0
- package/lib/common/rpc-service/registry.js.map +1 -0
- package/lib/common/rpc-service/stub.js +4 -6
- package/lib/common/rpc-service/stub.js.map +1 -1
- package/lib/common/{ext-rpc-protocol.d.ts → rpcProtocol.d.ts} +2 -2
- package/lib/common/rpcProtocol.d.ts.map +1 -0
- package/lib/common/{ext-rpc-protocol.js → rpcProtocol.js} +5 -6
- package/lib/common/rpcProtocol.js.map +1 -0
- package/lib/common/server-handler.d.ts +35 -0
- package/lib/common/server-handler.d.ts.map +1 -0
- package/lib/common/server-handler.js +165 -0
- package/lib/common/server-handler.js.map +1 -0
- package/lib/common/types.d.ts +14 -0
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/ws-channel.d.ts +6 -10
- package/lib/common/ws-channel.d.ts.map +1 -1
- package/lib/common/ws-channel.js +16 -15
- package/lib/common/ws-channel.js.map +1 -1
- package/lib/electron/channel-handler.d.ts +14 -0
- package/lib/electron/channel-handler.d.ts.map +1 -0
- package/lib/electron/channel-handler.js +26 -0
- package/lib/electron/channel-handler.js.map +1 -0
- package/lib/electron/index.d.ts +2 -0
- package/lib/electron/index.d.ts.map +1 -0
- package/lib/electron/index.js +5 -0
- package/lib/electron/index.js.map +1 -0
- package/lib/node/common-channel-handler.d.ts +6 -25
- package/lib/node/common-channel-handler.d.ts.map +1 -1
- package/lib/node/common-channel-handler.js +9 -151
- package/lib/node/common-channel-handler.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/ws-channel-handler.ts +26 -40
- package/src/common/buffers/buffers.ts +1 -1
- package/src/common/capturer.ts +36 -0
- package/src/common/connection/drivers/frame-decoder.ts +11 -11
- package/src/common/connection/drivers/index.ts +0 -1
- package/src/common/connection/drivers/message-port.ts +1 -4
- package/src/common/connection/drivers/node-message-port.ts +2 -2
- package/src/common/connection/drivers/reconnecting-websocket.ts +3 -2
- package/src/common/connection/drivers/socket.ts +4 -42
- package/src/common/connection/drivers/stream.ts +76 -0
- package/src/common/connection/drivers/ws-websocket.ts +2 -2
- package/src/common/fury-extends/any.ts +122 -102
- package/src/common/fury-extends/one-of.ts +79 -31
- package/src/common/fury-extends/shared.ts +3 -0
- package/src/common/index.ts +2 -2
- package/src/common/message.ts +1 -1
- package/src/common/rpc/connection.ts +228 -166
- package/src/common/rpc/index.ts +1 -1
- package/src/common/rpc/message-io.ts +223 -0
- package/src/common/rpc/multiplexer.ts +3 -0
- package/src/common/rpc/types.ts +30 -5
- package/src/common/rpc-service/center.ts +37 -31
- package/src/common/rpc-service/proxy/base.ts +59 -12
- package/src/common/rpc-service/proxy/index.ts +1 -3
- package/src/common/rpc-service/proxy/{legacy.ts → json.ts} +47 -57
- package/src/common/rpc-service/proxy/sumi.ts +23 -35
- package/src/common/rpc-service/registry.ts +125 -0
- package/src/common/rpc-service/stub.ts +6 -6
- package/src/common/{ext-rpc-protocol.ts → rpcProtocol.ts} +2 -2
- package/src/common/server-handler.ts +183 -0
- package/src/common/types.ts +13 -0
- package/src/common/ws-channel.ts +21 -23
- package/src/electron/channel-handler.ts +26 -0
- package/src/electron/index.ts +1 -0
- package/src/node/common-channel-handler.ts +10 -165
- package/lib/common/connection/drivers/utils.d.ts +0 -12
- package/lib/common/connection/drivers/utils.d.ts.map +0 -1
- package/lib/common/connection/drivers/utils.js +0 -49
- package/lib/common/connection/drivers/utils.js.map +0 -1
- package/lib/common/ext-rpc-protocol.d.ts.map +0 -1
- package/lib/common/ext-rpc-protocol.js.map +0 -1
- package/lib/common/rpc/packet.d.ts +0 -65
- package/lib/common/rpc/packet.d.ts.map +0 -1
- package/lib/common/rpc/packet.js +0 -82
- package/lib/common/rpc/packet.js.map +0 -1
- package/lib/common/rpc/protocol-repository.d.ts +0 -32
- package/lib/common/rpc/protocol-repository.d.ts.map +0 -1
- package/lib/common/rpc/protocol-repository.js +0 -118
- package/lib/common/rpc/protocol-repository.js.map +0 -1
- package/lib/common/rpc/utils.d.ts +0 -2
- package/lib/common/rpc/utils.d.ts.map +0 -1
- package/lib/common/rpc/utils.js +0 -10
- package/lib/common/rpc/utils.js.map +0 -1
- package/lib/common/rpc-service/proxy/invoker.d.ts +0 -14
- package/lib/common/rpc-service/proxy/invoker.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/invoker.js +0 -34
- package/lib/common/rpc-service/proxy/invoker.js.map +0 -1
- package/lib/common/rpc-service/proxy/legacy.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/legacy.js.map +0 -1
- package/lib/common/rpc-service/proxy/registry.d.ts.map +0 -1
- package/lib/common/rpc-service/proxy/registry.js +0 -46
- package/lib/common/rpc-service/proxy/registry.js.map +0 -1
- package/lib/common/utils.d.ts.map +0 -1
- package/lib/common/utils.js +0 -57
- package/lib/common/utils.js.map +0 -1
- package/src/common/connection/drivers/utils.ts +0 -52
- package/src/common/rpc/packet.ts +0 -104
- package/src/common/rpc/protocol-repository.ts +0 -180
- package/src/common/rpc/utils.ts +0 -5
- package/src/common/rpc-service/proxy/invoker.ts +0 -45
- package/src/common/rpc-service/proxy/registry.ts +0 -56
- package/src/common/utils.ts +0 -80
|
@@ -1,173 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommonChannelHandler = exports.commonChannelPathHandler =
|
|
3
|
+
exports.CommonChannelHandler = exports.commonChannelPathHandler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_to_regexp_1 = require("path-to-regexp");
|
|
6
6
|
const ws_1 = tslib_1.__importDefault(require("ws"));
|
|
7
7
|
const connection_1 = require("../common/connection");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
class CommonChannelPathHandler {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.handlerMap = new Map();
|
|
13
|
-
this.paramsKey = new Map();
|
|
14
|
-
}
|
|
15
|
-
register(channelPath, handler) {
|
|
16
|
-
const paramsIndex = channelPath.indexOf('/:');
|
|
17
|
-
const hasParams = paramsIndex >= 0;
|
|
18
|
-
let channelToken = channelPath;
|
|
19
|
-
if (hasParams) {
|
|
20
|
-
channelToken = channelPath.slice(0, paramsIndex);
|
|
21
|
-
this.paramsKey.set(channelToken, channelPath.slice(paramsIndex + 2));
|
|
22
|
-
}
|
|
23
|
-
if (!this.handlerMap.has(channelToken)) {
|
|
24
|
-
this.handlerMap.set(channelToken, []);
|
|
25
|
-
}
|
|
26
|
-
const handlerArr = this.handlerMap.get(channelToken);
|
|
27
|
-
const handlerFn = handler.handler.bind(handler);
|
|
28
|
-
const setHandler = (channel, clientId, params) => {
|
|
29
|
-
handler.connection = channel;
|
|
30
|
-
handlerFn(channel, clientId, params);
|
|
31
|
-
};
|
|
32
|
-
handler.handler = setHandler;
|
|
33
|
-
handlerArr.push(handler);
|
|
34
|
-
this.handlerMap.set(channelToken, handlerArr);
|
|
35
|
-
}
|
|
36
|
-
getParams(channelPath, value) {
|
|
37
|
-
const params = {};
|
|
38
|
-
if (this.paramsKey.has(channelPath)) {
|
|
39
|
-
const key = this.paramsKey.get(channelPath);
|
|
40
|
-
if (key) {
|
|
41
|
-
params[key] = value;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return params;
|
|
45
|
-
}
|
|
46
|
-
removeHandler(channelPath, handler) {
|
|
47
|
-
const paramsIndex = channelPath.indexOf(':');
|
|
48
|
-
const hasParams = paramsIndex >= 0;
|
|
49
|
-
let channelToken = channelPath;
|
|
50
|
-
if (hasParams) {
|
|
51
|
-
channelToken = channelPath.slice(0, paramsIndex);
|
|
52
|
-
}
|
|
53
|
-
const handlerArr = this.handlerMap.get(channelToken) || [];
|
|
54
|
-
const removeIndex = handlerArr.indexOf(handler);
|
|
55
|
-
if (removeIndex !== -1) {
|
|
56
|
-
handlerArr.splice(removeIndex, 1);
|
|
57
|
-
}
|
|
58
|
-
this.handlerMap.set(channelPath, handlerArr);
|
|
59
|
-
}
|
|
60
|
-
get(channelPath) {
|
|
61
|
-
return this.handlerMap.get(channelPath);
|
|
62
|
-
}
|
|
63
|
-
disposeConnectionClientId(connection, clientId) {
|
|
64
|
-
this.handlerMap.forEach((handlerArr) => {
|
|
65
|
-
handlerArr.forEach((handler) => {
|
|
66
|
-
handler.dispose(connection, clientId);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
getAll() {
|
|
71
|
-
return Array.from(this.handlerMap.values());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.CommonChannelPathHandler = CommonChannelPathHandler;
|
|
75
|
-
exports.commonChannelPathHandler = new CommonChannelPathHandler();
|
|
8
|
+
const server_handler_1 = require("../common/server-handler");
|
|
9
|
+
Object.defineProperty(exports, "commonChannelPathHandler", { enumerable: true, get: function () { return server_handler_1.commonChannelPathHandler; } });
|
|
76
10
|
/**
|
|
77
11
|
* Channel Handler for nodejs
|
|
78
12
|
*/
|
|
79
|
-
class CommonChannelHandler extends
|
|
13
|
+
class CommonChannelHandler extends server_handler_1.BaseCommonChannelHandler {
|
|
80
14
|
constructor(routePath, logger = console, options = {}) {
|
|
81
|
-
super();
|
|
82
|
-
this.logger = logger;
|
|
15
|
+
super('node-channel-handler', logger);
|
|
83
16
|
this.options = options;
|
|
84
|
-
this.handlerId = 'common-channel';
|
|
85
|
-
this.channelMap = new Map();
|
|
86
|
-
this.heartbeatMap = new Map();
|
|
87
17
|
this.handlerRoute = (0, path_to_regexp_1.match)(routePath, options.pathMatchOptions);
|
|
88
18
|
this.initWSServer();
|
|
89
19
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
connection.ping();
|
|
93
|
-
this.heartbeat(connectionId, connection);
|
|
94
|
-
}, 5000);
|
|
95
|
-
this.heartbeatMap.set(connectionId, timer);
|
|
20
|
+
doHeartbeat(connection) {
|
|
21
|
+
connection.socket.ping();
|
|
96
22
|
}
|
|
97
23
|
initWSServer() {
|
|
98
24
|
this.logger.log('init Common Channel Handler');
|
|
99
25
|
this.wsServer = new ws_1.default.Server(Object.assign({ noServer: true }, this.options.wsServerOptions));
|
|
100
26
|
this.wsServer.on('connection', (connection) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
let msgObj;
|
|
104
|
-
try {
|
|
105
|
-
msgObj = (0, ws_channel_1.parse)(msg);
|
|
106
|
-
if (msgObj.kind === 'ping') {
|
|
107
|
-
connection.send((0, ws_channel_1.stringify)({
|
|
108
|
-
kind: 'pong',
|
|
109
|
-
id: msgObj.id,
|
|
110
|
-
clientId,
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
else if (msgObj.kind === 'open') {
|
|
114
|
-
const { id, path } = msgObj;
|
|
115
|
-
clientId = msgObj.clientId;
|
|
116
|
-
this.logger.log(`open a new connection channel ${clientId} with path ${path}`);
|
|
117
|
-
this.heartbeat(id, connection);
|
|
118
|
-
const channel = new ws_channel_1.WSChannel(new connection_1.WSWebSocketConnection(connection), { id });
|
|
119
|
-
this.channelMap.set(id, channel);
|
|
120
|
-
// 根据 path 拿到注册的 handler
|
|
121
|
-
let handlerArr = exports.commonChannelPathHandler.get(path);
|
|
122
|
-
let params;
|
|
123
|
-
// 尝试通过父路径查找处理函数,如server/:id方式注册的handler
|
|
124
|
-
if (!handlerArr) {
|
|
125
|
-
const slashIndex = path.indexOf('/');
|
|
126
|
-
const hasSlash = slashIndex >= 0;
|
|
127
|
-
if (hasSlash) {
|
|
128
|
-
handlerArr = exports.commonChannelPathHandler.get(path.slice(0, slashIndex));
|
|
129
|
-
params = exports.commonChannelPathHandler.getParams(path.slice(0, slashIndex), path.slice(slashIndex + 1));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (handlerArr) {
|
|
133
|
-
for (let i = 0, len = handlerArr.length; i < len; i++) {
|
|
134
|
-
const handler = handlerArr[i];
|
|
135
|
-
handler.handler(channel, clientId, params);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
channel.serverReady();
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const { id } = msgObj;
|
|
142
|
-
const channel = this.channelMap.get(id);
|
|
143
|
-
if (channel) {
|
|
144
|
-
channel.dispatchChannelMessage(msgObj);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
this.logger.warn(`The channel(${id}) was not found`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
this.logger.error('handle connection message error', e);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
connection.once('close', () => {
|
|
156
|
-
exports.commonChannelPathHandler.disposeConnectionClientId(connection, clientId);
|
|
157
|
-
if (this.heartbeatMap.has(clientId)) {
|
|
158
|
-
clearTimeout(this.heartbeatMap.get(clientId));
|
|
159
|
-
this.heartbeatMap.delete(clientId);
|
|
160
|
-
this.logger.log(`Clear heartbeat from channel ${clientId}`);
|
|
161
|
-
}
|
|
162
|
-
Array.from(this.channelMap.values())
|
|
163
|
-
.filter((channel) => channel.id.toString().indexOf(clientId) !== -1)
|
|
164
|
-
.forEach((channel) => {
|
|
165
|
-
channel.close(1, 'close');
|
|
166
|
-
channel.dispose();
|
|
167
|
-
this.channelMap.delete(channel.id);
|
|
168
|
-
this.logger.log(`Remove connection channel ${channel.id}`);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
27
|
+
const wsConnection = new connection_1.WSWebSocketConnection(connection);
|
|
28
|
+
this.receiveConnection(wsConnection);
|
|
171
29
|
});
|
|
172
30
|
}
|
|
173
31
|
handleUpgrade(pathname, request, socket, head) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-channel-handler.js","sourceRoot":"","sources":["../../src/node/common-channel-handler.ts"],"names":[],"mappings":";;;;AAAA,mDAAsD;AACtD,oDAA2B;AAG3B,qDAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"common-channel-handler.js","sourceRoot":"","sources":["../../src/node/common-channel-handler.ts"],"names":[],"mappings":";;;;AAAA,mDAAsD;AACtD,oDAA2B;AAG3B,qDAA6D;AAC7D,6DAA8F;AAIrF,yGAJ0B,yCAAwB,OAI1B;AAEjC;;GAEG;AACH,MAAa,oBAAqB,SAAQ,yCAAwB;IAIhE,YAAY,SAAiB,EAAE,SAAkB,OAAO,EAAU,UAAuC,EAAE;QACzG,KAAK,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;QAD0B,YAAO,GAAP,OAAO,CAAkC;QAEzG,IAAI,CAAC,YAAY,GAAG,IAAA,sBAAK,EAAC,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,WAAW,CAAC,UAAiC;QAC3C,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAS,CAAC,MAAM,iBAClC,QAAQ,EAAE,IAAI,IACX,IAAI,CAAC,OAAO,CAAC,eAAe,EAC/B,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,UAAqB,EAAE,EAAE;YACvD,MAAM,YAAY,GAAG,IAAI,kCAAqB,CAAC,UAAU,CAAC,CAAC;YAC3D,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,aAAa,CAAC,QAAgB,EAAE,OAAY,EAAE,MAAW,EAAE,IAAS;QACzE,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAEhD,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE;gBAC/D,UAAkB,CAAC,UAAU,GAAG;oBAC/B,QAAQ;iBACT,CAAC;gBAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1CD,oDA0CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-connection",
|
|
3
|
-
"version": "2.27.3-rc-
|
|
3
|
+
"version": "2.27.3-rc-1710489030.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"url": "git@github.com:opensumi/core.git"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@furyjs/fury": "0.5.
|
|
20
|
+
"@furyjs/fury": "0.5.9-beta",
|
|
21
21
|
"@opensumi/events": "^1.0.0",
|
|
22
|
-
"@opensumi/ide-core-common": "2.27.3-rc-
|
|
22
|
+
"@opensumi/ide-core-common": "2.27.3-rc-1710489030.0",
|
|
23
23
|
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
|
|
24
24
|
"path-match": "^1.2.4",
|
|
25
25
|
"reconnecting-websocket": "^4.4.0",
|
|
26
26
|
"ws": "^8.15.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@opensumi/ide-components": "2.27.3-rc-
|
|
29
|
+
"@opensumi/ide-components": "2.27.3-rc-1710489030.0",
|
|
30
30
|
"@opensumi/ide-dev-tool": "1.3.1",
|
|
31
31
|
"@opensumi/mock-socket": "^9.3.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "8631990a482816fc26583e5811a87d083d93620b"
|
|
34
34
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { uuid } from '@opensumi/ide-core-common';
|
|
2
1
|
import { IReporterService, REPORT_NAME } from '@opensumi/ide-core-common';
|
|
3
2
|
|
|
4
3
|
import { NetSocketConnection } from '../common/connection';
|
|
5
4
|
import { ReconnectingWebSocketConnection } from '../common/connection/drivers/reconnecting-websocket';
|
|
6
|
-
import {
|
|
7
|
-
import { WSChannel,
|
|
5
|
+
import { ConnectionInfo, WSCloseInfo } from '../common/types';
|
|
6
|
+
import { WSChannel, parse, pingMessage } from '../common/ws-channel';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Channel Handler in browser
|
|
@@ -17,15 +16,11 @@ export class WSChannelHandler {
|
|
|
17
16
|
private heartbeatMessageTimer: NodeJS.Timeout | null;
|
|
18
17
|
private reporterService: IReporterService;
|
|
19
18
|
|
|
20
|
-
LOG_TAG
|
|
19
|
+
LOG_TAG: string;
|
|
21
20
|
|
|
22
|
-
constructor(
|
|
23
|
-
public connection: ReconnectingWebSocketConnection | NetSocketConnection,
|
|
24
|
-
logger: any,
|
|
25
|
-
clientId?: string,
|
|
26
|
-
) {
|
|
21
|
+
constructor(public connection: ReconnectingWebSocketConnection | NetSocketConnection, logger: any, clientId: string) {
|
|
27
22
|
this.logger = logger || this.logger;
|
|
28
|
-
this.clientId = clientId
|
|
23
|
+
this.clientId = clientId;
|
|
29
24
|
this.LOG_TAG = `[WSChannelHandler] [client-id:${this.clientId}]`;
|
|
30
25
|
}
|
|
31
26
|
// 为解决建立连接之后,替换成可落盘的 logger
|
|
@@ -42,12 +37,7 @@ export class WSChannelHandler {
|
|
|
42
37
|
clearTimeout(this.heartbeatMessageTimer);
|
|
43
38
|
}
|
|
44
39
|
this.heartbeatMessageTimer = global.setTimeout(() => {
|
|
45
|
-
|
|
46
|
-
kind: 'ping',
|
|
47
|
-
clientId: this.clientId,
|
|
48
|
-
id: this.clientId,
|
|
49
|
-
});
|
|
50
|
-
this.connection.send(msg);
|
|
40
|
+
this.connection.send(pingMessage);
|
|
51
41
|
this.heartbeatMessage();
|
|
52
42
|
}, 5000);
|
|
53
43
|
}
|
|
@@ -59,22 +49,17 @@ export class WSChannelHandler {
|
|
|
59
49
|
|
|
60
50
|
const msg = parse(message);
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const channel = this.channelMap.get(msg.id);
|
|
74
|
-
if (channel) {
|
|
75
|
-
channel.dispatchChannelMessage(msg);
|
|
76
|
-
} else {
|
|
77
|
-
this.logger.warn(this.LOG_TAG, `channel ${msg.id} not found`);
|
|
52
|
+
switch (msg.kind) {
|
|
53
|
+
case 'pong':
|
|
54
|
+
break;
|
|
55
|
+
default: {
|
|
56
|
+
const channel = this.channelMap.get(msg.id);
|
|
57
|
+
if (channel) {
|
|
58
|
+
channel.dispatchChannelMessage(msg);
|
|
59
|
+
} else {
|
|
60
|
+
this.logger.warn(this.LOG_TAG, `channel ${msg.id} not found`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
78
63
|
}
|
|
79
64
|
});
|
|
80
65
|
|
|
@@ -94,6 +79,7 @@ export class WSChannelHandler {
|
|
|
94
79
|
});
|
|
95
80
|
}
|
|
96
81
|
};
|
|
82
|
+
|
|
97
83
|
await new Promise<void>((resolve) => {
|
|
98
84
|
if (this.connection.isOpen()) {
|
|
99
85
|
this.heartbeatMessage();
|
|
@@ -106,14 +92,14 @@ export class WSChannelHandler {
|
|
|
106
92
|
reopenExistsChannel();
|
|
107
93
|
});
|
|
108
94
|
}
|
|
95
|
+
});
|
|
109
96
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
97
|
+
this.connection.onceClose((code, reason) => {
|
|
98
|
+
if (this.channelMap.size) {
|
|
99
|
+
this.channelMap.forEach((channel) => {
|
|
100
|
+
channel.close(code ?? 1000, reason ?? '');
|
|
101
|
+
});
|
|
102
|
+
}
|
|
117
103
|
});
|
|
118
104
|
}
|
|
119
105
|
public async openChannel(channelPath: string) {
|
|
@@ -135,7 +121,7 @@ export class WSChannelHandler {
|
|
|
135
121
|
closeEvent: { code, reason },
|
|
136
122
|
connectInfo: (navigator as any).connection as ConnectionInfo,
|
|
137
123
|
});
|
|
138
|
-
this.logger.log(this.LOG_TAG, 'channel close: ', code, reason);
|
|
124
|
+
this.logger.log(this.LOG_TAG, 'channel close: ', `code: ${code}, reason: ${reason}`);
|
|
139
125
|
});
|
|
140
126
|
channel.open(channelPath, this.clientId);
|
|
141
127
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__: any;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum MessageType {
|
|
8
|
+
SendNotification = 'sendNotification',
|
|
9
|
+
SendRequest = 'sendRequest',
|
|
10
|
+
RequestResult = 'requestResult',
|
|
11
|
+
OnNotification = 'onNotification',
|
|
12
|
+
OnRequest = 'onRequest',
|
|
13
|
+
OnRequestResult = 'onRequestResult',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum ResponseStatus {
|
|
17
|
+
Success = 'success',
|
|
18
|
+
Fail = 'fail',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ICapturedMessage {
|
|
22
|
+
type: MessageType;
|
|
23
|
+
serviceMethod: string;
|
|
24
|
+
arguments?: any;
|
|
25
|
+
requestId?: string;
|
|
26
|
+
status?: ResponseStatus;
|
|
27
|
+
data?: any;
|
|
28
|
+
error?: any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getCapturer() {
|
|
32
|
+
if (typeof window !== 'undefined' && window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__?.captureRPC) {
|
|
33
|
+
return window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.captureRPC;
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { BinaryWriter } from '@furyjs/fury/dist/lib/writer';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Emitter, readUInt32LE } from '@opensumi/ide-core-common';
|
|
4
4
|
|
|
5
5
|
import { Buffers } from '../../buffers/buffers';
|
|
6
6
|
|
|
7
|
-
const writer = BinaryWriter({});
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* You can use `Buffer.from('\r\n\r\n')` to get this indicator.
|
|
11
9
|
*/
|
|
@@ -15,14 +13,6 @@ export const indicator = new Uint8Array([0x0d, 0x0a, 0x0d, 0x0a]);
|
|
|
15
13
|
* sticky packet unpacking problems are generally problems at the transport layer.
|
|
16
14
|
* we use a length field to represent the length of the data, and then read the data according to the length
|
|
17
15
|
*/
|
|
18
|
-
export function prependLengthField(content: Uint8Array) {
|
|
19
|
-
writer.reset();
|
|
20
|
-
writer.buffer(indicator);
|
|
21
|
-
writer.uint32(content.byteLength);
|
|
22
|
-
writer.buffer(content);
|
|
23
|
-
return writer.dump();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
export class LengthFieldBasedFrameDecoder {
|
|
27
17
|
protected dataEmitter = new Emitter<Uint8Array>();
|
|
28
18
|
onData = this.dataEmitter.event;
|
|
@@ -167,4 +157,14 @@ export class LengthFieldBasedFrameDecoder {
|
|
|
167
157
|
this.dataEmitter.dispose();
|
|
168
158
|
this.buffers.dispose();
|
|
169
159
|
}
|
|
160
|
+
|
|
161
|
+
static writer = BinaryWriter({});
|
|
162
|
+
|
|
163
|
+
static construct(content: Uint8Array) {
|
|
164
|
+
LengthFieldBasedFrameDecoder.writer.reset();
|
|
165
|
+
LengthFieldBasedFrameDecoder.writer.buffer(indicator);
|
|
166
|
+
LengthFieldBasedFrameDecoder.writer.uint32(content.byteLength);
|
|
167
|
+
LengthFieldBasedFrameDecoder.writer.buffer(content);
|
|
168
|
+
return LengthFieldBasedFrameDecoder.writer.dump();
|
|
169
|
+
}
|
|
170
170
|
}
|
|
@@ -5,10 +5,7 @@ import { BaseConnection } from './base';
|
|
|
5
5
|
export class MessagePortConnection extends BaseConnection<Uint8Array> {
|
|
6
6
|
constructor(public port: MessagePort) {
|
|
7
7
|
super();
|
|
8
|
-
|
|
9
|
-
// compatible with nodejs in unittest, nodejs does not have start method
|
|
10
|
-
port.start();
|
|
11
|
-
}
|
|
8
|
+
port.start();
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
send(data: Uint8Array): void {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { MessagePort } from 'worker_threads';
|
|
2
|
-
|
|
3
1
|
import { IDisposable } from '@opensumi/ide-core-common';
|
|
4
2
|
|
|
5
3
|
import { BaseConnection } from './base';
|
|
6
4
|
|
|
5
|
+
import type { MessagePort } from 'worker_threads';
|
|
6
|
+
|
|
7
7
|
export class NodeMessagePortConnection extends BaseConnection<Uint8Array> {
|
|
8
8
|
constructor(private port: MessagePort) {
|
|
9
9
|
super();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import ReconnectingWebSocket, { Options as ReconnectingWebSocketOptions, UrlProvider } from 'reconnecting-websocket';
|
|
2
|
-
import type { ErrorEvent } from 'reconnecting-websocket';
|
|
3
2
|
|
|
4
3
|
import { IDisposable } from '@opensumi/ide-core-common';
|
|
5
4
|
|
|
6
5
|
import { BaseConnection } from './base';
|
|
7
6
|
|
|
7
|
+
import type { ErrorEvent } from 'reconnecting-websocket';
|
|
8
|
+
|
|
8
9
|
export class ReconnectingWebSocketConnection extends BaseConnection<Uint8Array> {
|
|
9
10
|
constructor(private socket: ReconnectingWebSocket) {
|
|
10
11
|
super();
|
|
@@ -40,7 +41,7 @@ export class ReconnectingWebSocketConnection extends BaseConnection<Uint8Array>
|
|
|
40
41
|
} else {
|
|
41
42
|
throw new Error('unknown message type, expect Blob or ArrayBuffer, received: ' + typeof e.data);
|
|
42
43
|
}
|
|
43
|
-
buffer.then((v) => cb(new Uint8Array(v)));
|
|
44
|
+
buffer.then((v) => cb(new Uint8Array(v, 0, v.byteLength)));
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
this.socket.addEventListener('message', handler);
|
|
@@ -1,44 +1,18 @@
|
|
|
1
|
-
import type net from 'net';
|
|
2
|
-
|
|
3
1
|
import { IDisposable } from '@opensumi/ide-core-common';
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
import { LengthFieldBasedFrameDecoder, prependLengthField } from './frame-decoder';
|
|
3
|
+
import { StreamConnection } from './stream';
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
protected decoder = new LengthFieldBasedFrameDecoder();
|
|
5
|
+
import type net from 'net';
|
|
10
6
|
|
|
7
|
+
export class NetSocketConnection extends StreamConnection {
|
|
11
8
|
constructor(private socket: net.Socket) {
|
|
12
|
-
super();
|
|
13
|
-
this.socket.on('data', (chunk) => {
|
|
14
|
-
this.decoder.push(chunk);
|
|
15
|
-
});
|
|
16
|
-
this.socket.once('close', () => {
|
|
17
|
-
this.decoder.dispose();
|
|
18
|
-
});
|
|
9
|
+
super(socket, socket);
|
|
19
10
|
}
|
|
20
11
|
|
|
21
12
|
isOpen(): boolean {
|
|
22
13
|
return this.socket.readyState === 'open';
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
send(data: Uint8Array): void {
|
|
26
|
-
this.socket.write(prependLengthField(data));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onMessage(cb: (data: Uint8Array) => void): IDisposable {
|
|
30
|
-
return this.decoder.onData(cb);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
onceClose(cb: () => void): IDisposable {
|
|
34
|
-
this.socket.once('close', cb);
|
|
35
|
-
return {
|
|
36
|
-
dispose: () => {
|
|
37
|
-
this.socket.off('close', cb);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
16
|
onOpen(cb: () => void): IDisposable {
|
|
43
17
|
this.socket.on('connect', cb);
|
|
44
18
|
return {
|
|
@@ -48,18 +22,6 @@ export class NetSocketConnection extends BaseConnection<Uint8Array> {
|
|
|
48
22
|
};
|
|
49
23
|
}
|
|
50
24
|
|
|
51
|
-
onError(cb: (err: Error) => void): IDisposable {
|
|
52
|
-
this.socket.on('error', cb);
|
|
53
|
-
return {
|
|
54
|
-
dispose: () => {
|
|
55
|
-
this.socket.off('error', cb);
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
dispose(): void {
|
|
60
|
-
this.decoder.dispose();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
25
|
destroy(): void {
|
|
64
26
|
this.socket.destroy();
|
|
65
27
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IDisposable } from '@opensumi/ide-core-common';
|
|
2
|
+
|
|
3
|
+
import { BaseConnection } from './base';
|
|
4
|
+
import { LengthFieldBasedFrameDecoder } from './frame-decoder';
|
|
5
|
+
|
|
6
|
+
import type { Readable, Writable } from 'stream';
|
|
7
|
+
|
|
8
|
+
export class StreamConnection extends BaseConnection<Uint8Array> {
|
|
9
|
+
protected decoder = new LengthFieldBasedFrameDecoder();
|
|
10
|
+
|
|
11
|
+
constructor(public readable: Readable, public writable: Writable) {
|
|
12
|
+
super();
|
|
13
|
+
const decode = (chunk: Uint8Array) => {
|
|
14
|
+
this.decoder.push(chunk);
|
|
15
|
+
};
|
|
16
|
+
this.readable.on('data', decode);
|
|
17
|
+
this.readable.once('close', () => {
|
|
18
|
+
this.decoder.dispose();
|
|
19
|
+
this.readable.off('data', decode);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
send(data: Uint8Array): void {
|
|
24
|
+
const result = LengthFieldBasedFrameDecoder.construct(data);
|
|
25
|
+
this.writable.write(result, () => {
|
|
26
|
+
// TODO: logger error
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onMessage(cb: (data: Uint8Array) => void): IDisposable {
|
|
31
|
+
return this.decoder.onData(cb);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onceClose(cb: (code?: number, reason?: string) => void): IDisposable {
|
|
35
|
+
const wrapper = (hadError: boolean) => {
|
|
36
|
+
const code: number = hadError ? 1 : 0;
|
|
37
|
+
const reason: string = hadError ? 'had error' : '';
|
|
38
|
+
cb(code, reason);
|
|
39
|
+
dispose();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const dispose = () => {
|
|
43
|
+
this.readable.off('close', wrapper);
|
|
44
|
+
if ((this.writable as any) !== (this.readable as any)) {
|
|
45
|
+
this.writable.off('close', wrapper);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.readable.once('close', wrapper);
|
|
50
|
+
if ((this.writable as any) !== (this.readable as any)) {
|
|
51
|
+
this.writable.once('close', wrapper);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
dispose,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onError(cb: (err: Error) => void): IDisposable {
|
|
60
|
+
this.readable.on('error', cb);
|
|
61
|
+
if ((this.writable as any) !== (this.readable as any)) {
|
|
62
|
+
this.writable.on('error', cb);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
dispose: () => {
|
|
66
|
+
this.readable.off('error', cb);
|
|
67
|
+
if ((this.writable as any) !== (this.readable as any)) {
|
|
68
|
+
this.writable.off('error', cb);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
dispose(): void {
|
|
74
|
+
this.decoder.dispose();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type WebSocket from 'ws';
|
|
2
|
-
|
|
3
1
|
import { IDisposable } from '@opensumi/ide-core-common';
|
|
4
2
|
|
|
5
3
|
import { BaseConnection } from './base';
|
|
6
4
|
|
|
5
|
+
import type WebSocket from 'ws';
|
|
6
|
+
|
|
7
7
|
export class WSWebSocketConnection extends BaseConnection<Uint8Array> {
|
|
8
8
|
constructor(public socket: WebSocket) {
|
|
9
9
|
super();
|