@opensumi/ide-connection 3.0.4 → 3.0.5-next-1717466130.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 +10 -1
- package/lib/browser/ws-channel-handler.d.ts.map +1 -1
- package/lib/browser/ws-channel-handler.js +11 -22
- package/lib/browser/ws-channel-handler.js.map +1 -1
- package/lib/common/channel/index.d.ts +2 -0
- package/lib/common/channel/index.d.ts.map +1 -0
- package/lib/common/channel/index.js +5 -0
- package/lib/common/channel/index.js.map +1 -0
- package/lib/common/channel/types.d.ts +66 -0
- package/lib/common/channel/types.d.ts.map +1 -0
- package/lib/common/channel/types.js +8 -0
- package/lib/common/channel/types.js.map +1 -0
- package/lib/common/connection/drivers/simple.d.ts +7 -7
- package/lib/common/connection/drivers/simple.d.ts.map +1 -1
- package/lib/common/connection/drivers/simple.js.map +1 -1
- package/lib/common/index.d.ts +4 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +4 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/rpc/connection.d.ts +5 -4
- package/lib/common/rpc/connection.d.ts.map +1 -1
- package/lib/common/rpc/connection.js +21 -37
- package/lib/common/rpc/connection.js.map +1 -1
- package/lib/common/rpc/message-io.d.ts +62 -11
- package/lib/common/rpc/message-io.d.ts.map +1 -1
- package/lib/common/rpc/message-io.js +111 -10
- package/lib/common/rpc/message-io.js.map +1 -1
- package/lib/common/rpc/multiplexer.d.ts +11 -11
- package/lib/common/rpc/multiplexer.d.ts.map +1 -1
- package/lib/common/rpc/multiplexer.js +18 -17
- package/lib/common/rpc/multiplexer.js.map +1 -1
- package/lib/common/rpc-service/index.d.ts +1 -0
- package/lib/common/rpc-service/index.d.ts.map +1 -1
- package/lib/common/rpc-service/index.js +1 -0
- package/lib/common/rpc-service/index.js.map +1 -1
- package/lib/common/rpc-service/proxy/json.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/json.js +2 -2
- package/lib/common/rpc-service/proxy/json.js.map +1 -1
- package/lib/common/rpc-service/proxy/sumi.d.ts.map +1 -1
- package/lib/common/rpc-service/proxy/sumi.js +2 -2
- package/lib/common/rpc-service/proxy/sumi.js.map +1 -1
- package/lib/common/rpc-service/registry.d.ts +2 -2
- package/lib/common/rpc-service/registry.d.ts.map +1 -1
- package/lib/common/rpc-service/registry.js +6 -0
- package/lib/common/rpc-service/registry.js.map +1 -1
- package/lib/common/serializer/fury.d.ts +122 -0
- package/lib/common/serializer/fury.d.ts.map +1 -0
- package/lib/common/serializer/fury.js +51 -0
- package/lib/common/serializer/fury.js.map +1 -0
- package/lib/common/serializer/index.d.ts +7 -0
- package/lib/common/serializer/index.d.ts.map +1 -0
- package/lib/common/serializer/index.js +22 -0
- package/lib/common/serializer/index.js.map +1 -0
- package/lib/common/serializer/raw.d.ts +4 -0
- package/lib/common/serializer/raw.d.ts.map +1 -0
- package/lib/common/serializer/raw.js +8 -0
- package/lib/common/serializer/raw.js.map +1 -0
- package/lib/common/serializer/types.d.ts +5 -0
- package/lib/common/serializer/types.d.ts.map +1 -0
- package/lib/common/serializer/types.js +3 -0
- package/lib/common/serializer/types.js.map +1 -0
- package/lib/common/server-handler.d.ts +7 -1
- package/lib/common/server-handler.d.ts.map +1 -1
- package/lib/common/server-handler.js +13 -11
- package/lib/common/server-handler.js.map +1 -1
- package/lib/common/ws-channel.d.ts +10 -202
- package/lib/common/ws-channel.d.ts.map +1 -1
- package/lib/common/ws-channel.js +40 -92
- package/lib/common/ws-channel.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/ws-channel-handler.ts +29 -26
- package/src/common/channel/index.ts +1 -0
- package/src/common/channel/types.ts +82 -0
- package/src/common/connection/drivers/simple.ts +5 -5
- package/src/common/index.ts +4 -0
- package/src/common/rpc/connection.ts +28 -44
- package/src/common/rpc/message-io.ts +172 -10
- package/src/common/rpc/multiplexer.ts +27 -29
- package/src/common/rpc-service/index.ts +1 -0
- package/src/common/rpc-service/proxy/json.ts +13 -11
- package/src/common/rpc-service/proxy/sumi.ts +5 -3
- package/src/common/rpc-service/registry.ts +10 -2
- package/src/common/serializer/fury.ts +61 -0
- package/src/common/serializer/index.ts +24 -0
- package/src/common/serializer/raw.ts +8 -0
- package/src/common/serializer/types.ts +4 -0
- package/src/common/server-handler.ts +24 -26
- package/src/common/ws-channel.ts +63 -225
|
@@ -1,45 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from '@opensumi/events';
|
|
3
3
|
import { DisposableStore, EventQueue, StateTracer } from '@opensumi/ide-core-common';
|
|
4
|
+
import { ChannelMessage } from './channel/types';
|
|
4
5
|
import { IConnectionShape } from './connection/types';
|
|
5
6
|
import { ISumiConnectionOptions, SumiConnection } from './rpc/connection';
|
|
6
7
|
import { ILogger } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* `ping` and `pong` are used to detect whether the connection is alive.
|
|
9
|
-
*/
|
|
10
|
-
export interface PingMessage {
|
|
11
|
-
kind: 'ping';
|
|
12
|
-
id: string;
|
|
13
|
-
clientId: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* when server receive a `ping` message, it should reply a `pong` message, vice versa.
|
|
17
|
-
*/
|
|
18
|
-
export interface PongMessage {
|
|
19
|
-
kind: 'pong';
|
|
20
|
-
id: string;
|
|
21
|
-
clientId: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* `data` message indicate that the channel has received some data.
|
|
25
|
-
* the `content` field is the data, it should be a string.
|
|
26
|
-
*/
|
|
27
|
-
export interface DataMessage {
|
|
28
|
-
kind: 'data';
|
|
29
|
-
id: string;
|
|
30
|
-
content: string;
|
|
31
|
-
}
|
|
32
|
-
export interface BinaryMessage {
|
|
33
|
-
kind: 'binary';
|
|
34
|
-
id: string;
|
|
35
|
-
binary: Uint8Array;
|
|
36
|
-
}
|
|
37
|
-
export interface CloseMessage {
|
|
38
|
-
kind: 'close';
|
|
39
|
-
id: string;
|
|
40
|
-
code: number;
|
|
41
|
-
reason: string;
|
|
42
|
-
}
|
|
43
8
|
export interface IWSChannelCreateOptions {
|
|
44
9
|
/**
|
|
45
10
|
* every channel's unique id, it only used in client to server architecture.
|
|
@@ -50,7 +15,7 @@ export interface IWSChannelCreateOptions {
|
|
|
50
15
|
ensureServerReady?: boolean;
|
|
51
16
|
}
|
|
52
17
|
export declare class WSChannel {
|
|
53
|
-
connection: IConnectionShape<
|
|
18
|
+
connection: IConnectionShape<ChannelMessage>;
|
|
54
19
|
protected _disposables: DisposableStore;
|
|
55
20
|
protected emitter: EventEmitter<{
|
|
56
21
|
message: [data: string];
|
|
@@ -60,15 +25,16 @@ export declare class WSChannel {
|
|
|
60
25
|
binary: [data: Uint8Array];
|
|
61
26
|
}>;
|
|
62
27
|
protected onBinaryQueue: EventQueue<Uint8Array>;
|
|
63
|
-
protected sendQueue:
|
|
28
|
+
protected sendQueue: ChannelMessage[];
|
|
64
29
|
protected _isServerReady: boolean;
|
|
65
30
|
protected _ensureServerReady: boolean | undefined;
|
|
66
31
|
id: string;
|
|
67
32
|
channelPath: string;
|
|
33
|
+
clientId: string;
|
|
34
|
+
protected LOG_TAG: string;
|
|
68
35
|
logger: ILogger;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
protected inqueue(data: Uint8Array): void;
|
|
36
|
+
constructor(connection: IConnectionShape<ChannelMessage>, options: IWSChannelCreateOptions);
|
|
37
|
+
protected inqueue(data: ChannelMessage): void;
|
|
72
38
|
onMessage(cb: (data: string) => any): import("@opensumi/events").IDisposable;
|
|
73
39
|
onBinary(cb: (data: Uint8Array) => any): import("@opensumi/ide-core-common").IDisposable;
|
|
74
40
|
onOpen(cb: (id: string) => void): import("@opensumi/events").IDisposable;
|
|
@@ -102,6 +68,7 @@ export declare class WSChannel {
|
|
|
102
68
|
};
|
|
103
69
|
createSumiConnection(options?: ISumiConnectionOptions): SumiConnection;
|
|
104
70
|
dispose(): void;
|
|
71
|
+
ping(): void;
|
|
105
72
|
}
|
|
106
73
|
interface IWSServerChannelCreateOptions extends IWSChannelCreateOptions {
|
|
107
74
|
clientId: string;
|
|
@@ -110,171 +77,12 @@ interface IWSServerChannelCreateOptions extends IWSChannelCreateOptions {
|
|
|
110
77
|
* The server side channel, it will send a `server-ready` message after it receive a `open` message.
|
|
111
78
|
*/
|
|
112
79
|
export declare class WSServerChannel extends WSChannel {
|
|
113
|
-
connection: IConnectionShape<
|
|
80
|
+
connection: IConnectionShape<ChannelMessage>;
|
|
114
81
|
messageQueue: ChannelMessage[];
|
|
115
82
|
clientId: string;
|
|
116
|
-
constructor(connection: IConnectionShape<
|
|
83
|
+
constructor(connection: IConnectionShape<ChannelMessage>, options: IWSServerChannelCreateOptions);
|
|
117
84
|
serverReady(token: string): void;
|
|
118
85
|
dispatch(msg: ChannelMessage): void;
|
|
119
86
|
}
|
|
120
|
-
export type ChannelMessage = PingMessage | PongMessage | OpenMessage | ServerReadyMessage | DataMessage | BinaryMessage | CloseMessage | ErrorMessage;
|
|
121
|
-
export declare const PingProtocol: {
|
|
122
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
123
|
-
options: {
|
|
124
|
-
tag: string;
|
|
125
|
-
props: {
|
|
126
|
-
clientId: {
|
|
127
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
128
|
-
};
|
|
129
|
-
id: {
|
|
130
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
131
|
-
};
|
|
132
|
-
} | undefined;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
export declare const PongProtocol: {
|
|
136
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
137
|
-
options: {
|
|
138
|
-
tag: string;
|
|
139
|
-
props: {
|
|
140
|
-
clientId: {
|
|
141
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
142
|
-
};
|
|
143
|
-
id: {
|
|
144
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
145
|
-
};
|
|
146
|
-
} | undefined;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* `open` message is used to open a new channel.
|
|
151
|
-
* `path` is used to identify which handler should be used to handle the channel.
|
|
152
|
-
* `clientId` is used to identify the client.
|
|
153
|
-
*/
|
|
154
|
-
export interface OpenMessage {
|
|
155
|
-
kind: 'open';
|
|
156
|
-
id: string;
|
|
157
|
-
path: string;
|
|
158
|
-
clientId: string;
|
|
159
|
-
connectionToken: string;
|
|
160
|
-
}
|
|
161
|
-
export declare const OpenProtocol: {
|
|
162
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
163
|
-
options: {
|
|
164
|
-
tag: string;
|
|
165
|
-
props: {
|
|
166
|
-
clientId: {
|
|
167
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
168
|
-
};
|
|
169
|
-
id: {
|
|
170
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
171
|
-
};
|
|
172
|
-
path: {
|
|
173
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
174
|
-
};
|
|
175
|
-
connectionToken: {
|
|
176
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
177
|
-
};
|
|
178
|
-
} | undefined;
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* when server receive a `open` message, it should reply a `server-ready` message.
|
|
183
|
-
* this is indicate that the channel is ready to use.
|
|
184
|
-
*/
|
|
185
|
-
export interface ServerReadyMessage {
|
|
186
|
-
kind: 'server-ready';
|
|
187
|
-
id: string;
|
|
188
|
-
token: string;
|
|
189
|
-
}
|
|
190
|
-
export declare const ServerReadyProtocol: {
|
|
191
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
192
|
-
options: {
|
|
193
|
-
tag: string;
|
|
194
|
-
props: {
|
|
195
|
-
id: {
|
|
196
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
197
|
-
};
|
|
198
|
-
token: {
|
|
199
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
200
|
-
};
|
|
201
|
-
} | undefined;
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
export declare enum ErrorMessageCode {
|
|
205
|
-
ChannelNotFound = 1
|
|
206
|
-
}
|
|
207
|
-
export interface ErrorMessage {
|
|
208
|
-
kind: 'error';
|
|
209
|
-
id: string;
|
|
210
|
-
code: ErrorMessageCode;
|
|
211
|
-
message: string;
|
|
212
|
-
}
|
|
213
|
-
export declare const ErrorProtocol: {
|
|
214
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
215
|
-
options: {
|
|
216
|
-
tag: string;
|
|
217
|
-
props: {
|
|
218
|
-
id: {
|
|
219
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
220
|
-
};
|
|
221
|
-
code: {
|
|
222
|
-
type: import("@furyjs/fury").InternalSerializerType.UINT16;
|
|
223
|
-
};
|
|
224
|
-
message: {
|
|
225
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
226
|
-
};
|
|
227
|
-
} | undefined;
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
export declare const DataProtocol: {
|
|
231
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
232
|
-
options: {
|
|
233
|
-
tag: string;
|
|
234
|
-
props: {
|
|
235
|
-
id: {
|
|
236
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
237
|
-
};
|
|
238
|
-
content: {
|
|
239
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
240
|
-
};
|
|
241
|
-
} | undefined;
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
export declare const BinaryProtocol: {
|
|
245
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
246
|
-
options: {
|
|
247
|
-
tag: string;
|
|
248
|
-
props: {
|
|
249
|
-
id: {
|
|
250
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
251
|
-
};
|
|
252
|
-
binary: {
|
|
253
|
-
type: import("@furyjs/fury").InternalSerializerType.BINARY;
|
|
254
|
-
};
|
|
255
|
-
} | undefined;
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
export declare const CloseProtocol: {
|
|
259
|
-
type: import("@furyjs/fury").InternalSerializerType.FURY_TYPE_TAG;
|
|
260
|
-
options: {
|
|
261
|
-
tag: string;
|
|
262
|
-
props: {
|
|
263
|
-
id: {
|
|
264
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
265
|
-
};
|
|
266
|
-
code: {
|
|
267
|
-
type: import("@furyjs/fury").InternalSerializerType.UINT32;
|
|
268
|
-
};
|
|
269
|
-
reason: {
|
|
270
|
-
type: import("@furyjs/fury").InternalSerializerType.STRING;
|
|
271
|
-
};
|
|
272
|
-
} | undefined;
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
export declare function stringify(obj: ChannelMessage): Uint8Array;
|
|
276
|
-
export declare function parse(input: Uint8Array): ChannelMessage;
|
|
277
|
-
export declare const pingMessage: Uint8Array;
|
|
278
|
-
export declare const pongMessage: Uint8Array;
|
|
279
87
|
export {};
|
|
280
88
|
//# sourceMappingURL=ws-channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-channel.d.ts","sourceRoot":"","sources":["../../src/common/ws-channel.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ws-channel.d.ts","sourceRoot":"","sources":["../../src/common/ws-channel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAgB,MAAM,2BAA2B,CAAC;AAEnG,OAAO,EAAE,cAAc,EAAoB,MAAM,iBAAiB,CAAC;AACn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MAAM,CAAC;gBACE,UAAU,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,6BAA6B;IAKvG,WAAW,CAAC,KAAK,EAAE,MAAM;IAQzB,QAAQ,CAAC,GAAG,EAAE,cAAc;CAgB7B"}
|
package/lib/common/ws-channel.js
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const fury_1 = require("@furyjs/fury");
|
|
3
|
+
exports.WSServerChannel = exports.WSChannel = void 0;
|
|
5
4
|
const events_1 = require("@opensumi/events");
|
|
6
5
|
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
7
|
-
const
|
|
6
|
+
const types_1 = require("./channel/types");
|
|
8
7
|
const connection_1 = require("./rpc/connection");
|
|
9
8
|
class WSChannel {
|
|
10
|
-
static forClient(connection, options) {
|
|
11
|
-
const disposable = new ide_core_common_1.DisposableCollection();
|
|
12
|
-
const channel = new WSChannel(connection, options);
|
|
13
|
-
disposable.push(connection.onMessage((data) => {
|
|
14
|
-
channel.dispatch(parse(data));
|
|
15
|
-
}));
|
|
16
|
-
connection.onceClose(() => {
|
|
17
|
-
disposable.dispose();
|
|
18
|
-
});
|
|
19
|
-
return channel;
|
|
20
|
-
}
|
|
21
9
|
constructor(connection, options) {
|
|
22
10
|
this.connection = connection;
|
|
23
11
|
this._disposables = new ide_core_common_1.DisposableStore();
|
|
@@ -25,10 +13,12 @@ class WSChannel {
|
|
|
25
13
|
this.onBinaryQueue = this._disposables.add(new ide_core_common_1.EventQueue());
|
|
26
14
|
this.sendQueue = [];
|
|
27
15
|
this._isServerReady = false;
|
|
16
|
+
this.LOG_TAG = '[WSChannel]';
|
|
28
17
|
this.logger = console;
|
|
29
18
|
this.stateTracer = this._disposables.add(new ide_core_common_1.StateTracer());
|
|
30
19
|
const { id, logger, ensureServerReady } = options;
|
|
31
20
|
this.id = id;
|
|
21
|
+
this.LOG_TAG = `[WSChannel id:${this.id}]`;
|
|
32
22
|
if (logger) {
|
|
33
23
|
this.logger = logger;
|
|
34
24
|
}
|
|
@@ -92,6 +82,20 @@ class WSChannel {
|
|
|
92
82
|
case 'binary':
|
|
93
83
|
this.emitter.emit('binary', msg.binary);
|
|
94
84
|
break;
|
|
85
|
+
case 'error':
|
|
86
|
+
this.logger.error(this.LOG_TAG, `receive error: id: ${msg.id}, code: ${msg.code}, error: ${msg.message}`);
|
|
87
|
+
switch (msg.code) {
|
|
88
|
+
case types_1.ErrorMessageCode.ChannelNotFound:
|
|
89
|
+
// 有 channelPath 说明该 channel 曾经被打开过
|
|
90
|
+
// 重新打开 channel
|
|
91
|
+
if (this.channelPath) {
|
|
92
|
+
// 暂停消息发送, 直到收到 server-ready
|
|
93
|
+
this.pause();
|
|
94
|
+
this.open(this.channelPath, this.clientId);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
@@ -99,18 +103,20 @@ class WSChannel {
|
|
|
99
103
|
*/
|
|
100
104
|
open(path, clientId, connectionToken = (0, ide_core_common_1.randomString)(16)) {
|
|
101
105
|
this.channelPath = path;
|
|
106
|
+
this.clientId = clientId;
|
|
107
|
+
this.LOG_TAG = `[WSChannel id=${this.id} path=${path}]`;
|
|
102
108
|
if (this.stateTracer.has(connectionToken)) {
|
|
103
109
|
this.logger.warn(`channel already opened or in progress, path: ${path}, clientId: ${clientId}, connectionToken: ${connectionToken}`);
|
|
104
110
|
return;
|
|
105
111
|
}
|
|
106
112
|
this.stateTracer.record(connectionToken);
|
|
107
|
-
this.connection.send(
|
|
113
|
+
this.connection.send({
|
|
108
114
|
kind: 'open',
|
|
109
115
|
id: this.id,
|
|
110
116
|
path,
|
|
111
117
|
clientId,
|
|
112
118
|
connectionToken,
|
|
113
|
-
})
|
|
119
|
+
});
|
|
114
120
|
if (this._ensureServerReady) {
|
|
115
121
|
this.ensureOpenSend(path, clientId, connectionToken);
|
|
116
122
|
}
|
|
@@ -132,18 +138,18 @@ class WSChannel {
|
|
|
132
138
|
}, 500);
|
|
133
139
|
}
|
|
134
140
|
send(content) {
|
|
135
|
-
this.inqueue(
|
|
141
|
+
this.inqueue({
|
|
136
142
|
kind: 'data',
|
|
137
143
|
id: this.id,
|
|
138
144
|
content,
|
|
139
|
-
})
|
|
145
|
+
});
|
|
140
146
|
}
|
|
141
147
|
sendBinary(data) {
|
|
142
|
-
this.inqueue(
|
|
148
|
+
this.inqueue({
|
|
143
149
|
kind: 'binary',
|
|
144
150
|
id: this.id,
|
|
145
151
|
binary: data,
|
|
146
|
-
})
|
|
152
|
+
});
|
|
147
153
|
}
|
|
148
154
|
onError() { }
|
|
149
155
|
close(code, reason) {
|
|
@@ -180,6 +186,12 @@ class WSChannel {
|
|
|
180
186
|
this.sendQueue = [];
|
|
181
187
|
this._disposables.dispose();
|
|
182
188
|
}
|
|
189
|
+
ping() {
|
|
190
|
+
this.connection.send({
|
|
191
|
+
kind: 'ping',
|
|
192
|
+
id: this.id,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
183
195
|
}
|
|
184
196
|
exports.WSChannel = WSChannel;
|
|
185
197
|
/**
|
|
@@ -193,11 +205,11 @@ class WSServerChannel extends WSChannel {
|
|
|
193
205
|
this.clientId = options.clientId;
|
|
194
206
|
}
|
|
195
207
|
serverReady(token) {
|
|
196
|
-
this.connection.send(
|
|
208
|
+
this.connection.send({
|
|
197
209
|
kind: 'server-ready',
|
|
198
210
|
id: this.id,
|
|
199
211
|
token,
|
|
200
|
-
})
|
|
212
|
+
});
|
|
201
213
|
}
|
|
202
214
|
dispatch(msg) {
|
|
203
215
|
switch (msg.kind) {
|
|
@@ -207,78 +219,14 @@ class WSServerChannel extends WSChannel {
|
|
|
207
219
|
case 'binary':
|
|
208
220
|
this.emitter.emit('binary', msg.binary);
|
|
209
221
|
break;
|
|
222
|
+
case 'ping':
|
|
223
|
+
this.connection.send({
|
|
224
|
+
kind: 'pong',
|
|
225
|
+
id: this.id,
|
|
226
|
+
});
|
|
227
|
+
break;
|
|
210
228
|
}
|
|
211
229
|
}
|
|
212
230
|
}
|
|
213
231
|
exports.WSServerChannel = WSServerChannel;
|
|
214
|
-
exports.PingProtocol = fury_1.Type.object('ping', {
|
|
215
|
-
clientId: fury_1.Type.string(),
|
|
216
|
-
id: fury_1.Type.string(),
|
|
217
|
-
});
|
|
218
|
-
exports.PongProtocol = fury_1.Type.object('pong', {
|
|
219
|
-
clientId: fury_1.Type.string(),
|
|
220
|
-
id: fury_1.Type.string(),
|
|
221
|
-
});
|
|
222
|
-
exports.OpenProtocol = fury_1.Type.object('open', {
|
|
223
|
-
clientId: fury_1.Type.string(),
|
|
224
|
-
id: fury_1.Type.string(),
|
|
225
|
-
path: fury_1.Type.string(),
|
|
226
|
-
connectionToken: fury_1.Type.string(),
|
|
227
|
-
});
|
|
228
|
-
exports.ServerReadyProtocol = fury_1.Type.object('server-ready', {
|
|
229
|
-
id: fury_1.Type.string(),
|
|
230
|
-
token: fury_1.Type.string(),
|
|
231
|
-
});
|
|
232
|
-
var ErrorMessageCode;
|
|
233
|
-
(function (ErrorMessageCode) {
|
|
234
|
-
ErrorMessageCode[ErrorMessageCode["ChannelNotFound"] = 1] = "ChannelNotFound";
|
|
235
|
-
})(ErrorMessageCode = exports.ErrorMessageCode || (exports.ErrorMessageCode = {}));
|
|
236
|
-
exports.ErrorProtocol = fury_1.Type.object('error', {
|
|
237
|
-
id: fury_1.Type.string(),
|
|
238
|
-
code: fury_1.Type.uint16(),
|
|
239
|
-
message: fury_1.Type.string(),
|
|
240
|
-
});
|
|
241
|
-
exports.DataProtocol = fury_1.Type.object('data', {
|
|
242
|
-
id: fury_1.Type.string(),
|
|
243
|
-
content: fury_1.Type.string(),
|
|
244
|
-
});
|
|
245
|
-
exports.BinaryProtocol = fury_1.Type.object('binary', {
|
|
246
|
-
id: fury_1.Type.string(),
|
|
247
|
-
binary: fury_1.Type.binary(),
|
|
248
|
-
});
|
|
249
|
-
exports.CloseProtocol = fury_1.Type.object('close', {
|
|
250
|
-
id: fury_1.Type.string(),
|
|
251
|
-
code: fury_1.Type.uint32(),
|
|
252
|
-
reason: fury_1.Type.string(),
|
|
253
|
-
});
|
|
254
|
-
const serializer = (0, one_of_1.oneOf)([
|
|
255
|
-
exports.PingProtocol,
|
|
256
|
-
exports.PongProtocol,
|
|
257
|
-
exports.OpenProtocol,
|
|
258
|
-
exports.ServerReadyProtocol,
|
|
259
|
-
exports.DataProtocol,
|
|
260
|
-
exports.BinaryProtocol,
|
|
261
|
-
exports.CloseProtocol,
|
|
262
|
-
exports.ErrorProtocol,
|
|
263
|
-
]);
|
|
264
|
-
function stringify(obj) {
|
|
265
|
-
return serializer.serialize(obj);
|
|
266
|
-
}
|
|
267
|
-
exports.stringify = stringify;
|
|
268
|
-
function parse(input) {
|
|
269
|
-
return serializer.deserialize(input);
|
|
270
|
-
}
|
|
271
|
-
exports.parse = parse;
|
|
272
|
-
const _pingMessage = {
|
|
273
|
-
kind: 'ping',
|
|
274
|
-
id: '',
|
|
275
|
-
clientId: '',
|
|
276
|
-
};
|
|
277
|
-
const _pongMessage = {
|
|
278
|
-
kind: 'pong',
|
|
279
|
-
id: '',
|
|
280
|
-
clientId: '',
|
|
281
|
-
};
|
|
282
|
-
exports.pingMessage = stringify(_pingMessage);
|
|
283
|
-
exports.pongMessage = stringify(_pongMessage);
|
|
284
232
|
//# sourceMappingURL=ws-channel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-channel.js","sourceRoot":"","sources":["../../src/common/ws-channel.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ws-channel.js","sourceRoot":"","sources":["../../src/common/ws-channel.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAChD,+DAAmG;AAEnG,2CAAmE;AAEnE,iDAA0E;AAc1E,MAAa,SAAS;IA2BpB,YAA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ection",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5-next-1717466130.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": "3.0.
|
|
22
|
+
"@opensumi/ide-core-common": "3.0.5-next-1717466130.0",
|
|
23
23
|
"@opensumi/reconnecting-websocket": "^4.4.0",
|
|
24
24
|
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
|
|
25
25
|
"path-to-regexp": "^6.2.1",
|
|
26
26
|
"ws": "^8.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@opensumi/ide-components": "3.0.
|
|
30
|
-
"@opensumi/ide-dev-tool": "3.0.
|
|
29
|
+
"@opensumi/ide-components": "3.0.5-next-1717466130.0",
|
|
30
|
+
"@opensumi/ide-dev-tool": "3.0.5-next-1717466130.0",
|
|
31
31
|
"@opensumi/mock-socket": "^9.3.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "1c4375de22013b4ae70e94a9722885edd0b385cd"
|
|
34
34
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { EventEmitter } from '@opensumi/events';
|
|
2
2
|
import { Barrier, Deferred, DisposableStore, IReporterService, MultiMap, REPORT_NAME } from '@opensumi/ide-core-common';
|
|
3
3
|
|
|
4
|
+
import { ChannelMessage } from '../common/channel/types';
|
|
4
5
|
import { IRuntimeSocketConnection } from '../common/connection';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { IConnectionShape } from '../common/connection/types';
|
|
7
|
+
import { ISerializer, furySerializer, wrapSerializer } from '../common/serializer';
|
|
8
|
+
import { ConnectionInfo, ILogger, WSCloseInfo } from '../common/types';
|
|
9
|
+
import { WSChannel } from '../common/ws-channel';
|
|
10
|
+
|
|
11
|
+
export interface WSChannelHandlerOptions {
|
|
12
|
+
logger?: ILogger;
|
|
13
|
+
serializer?: ISerializer<ChannelMessage, any>;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Channel Handler in browser
|
|
@@ -12,13 +20,15 @@ export class WSChannelHandler {
|
|
|
12
20
|
private _disposables = new DisposableStore();
|
|
13
21
|
|
|
14
22
|
private _onChannelCreatedEmitter = this._disposables.add(new EventEmitter<Record<string, [WSChannel]>>());
|
|
23
|
+
|
|
24
|
+
wrappedConnection: IConnectionShape<ChannelMessage>;
|
|
15
25
|
public onChannelCreated(path: string, listener: (channel: WSChannel) => void) {
|
|
16
26
|
return this._onChannelCreatedEmitter.on(path, listener);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
private channelMap: Map<string, WSChannel> = new Map();
|
|
20
30
|
private channelCloseEventMap = new MultiMap<string, WSCloseInfo>();
|
|
21
|
-
private logger = console;
|
|
31
|
+
private logger: ILogger = console;
|
|
22
32
|
public clientId: string;
|
|
23
33
|
private heartbeatMessageTimer: NodeJS.Timeout | null;
|
|
24
34
|
private reporterService: IReporterService;
|
|
@@ -30,10 +40,16 @@ export class WSChannelHandler {
|
|
|
30
40
|
|
|
31
41
|
LOG_TAG: string;
|
|
32
42
|
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
43
|
+
constructor(
|
|
44
|
+
public connection: IRuntimeSocketConnection<Uint8Array>,
|
|
45
|
+
clientId: string,
|
|
46
|
+
options: WSChannelHandlerOptions = {},
|
|
47
|
+
) {
|
|
48
|
+
this.logger = options.logger || this.logger;
|
|
35
49
|
this.clientId = clientId;
|
|
36
50
|
this.LOG_TAG = `[WSChannelHandler] [client-id:${this.clientId}]`;
|
|
51
|
+
const serializer = options.serializer || furySerializer;
|
|
52
|
+
this.wrappedConnection = wrapSerializer(this.connection, serializer);
|
|
37
53
|
}
|
|
38
54
|
// 为解决建立连接之后,替换成可落盘的 logger
|
|
39
55
|
replaceLogger(logger: any) {
|
|
@@ -49,37 +65,24 @@ export class WSChannelHandler {
|
|
|
49
65
|
clearTimeout(this.heartbeatMessageTimer);
|
|
50
66
|
}
|
|
51
67
|
this.heartbeatMessageTimer = global.setTimeout(() => {
|
|
52
|
-
this.
|
|
68
|
+
this.channelMap.forEach((channel) => {
|
|
69
|
+
channel.ping();
|
|
70
|
+
});
|
|
71
|
+
|
|
53
72
|
this.heartbeatMessage();
|
|
54
73
|
}, 10 * 1000);
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
public async initHandler() {
|
|
58
|
-
this.
|
|
77
|
+
this.wrappedConnection.onMessage((msg) => {
|
|
59
78
|
// 一个心跳周期内如果有收到消息,则不需要再发送心跳
|
|
60
79
|
this.heartbeatMessage();
|
|
61
80
|
|
|
62
|
-
const msg = parse(message);
|
|
63
|
-
|
|
64
81
|
switch (msg.kind) {
|
|
65
82
|
case 'pong':
|
|
66
|
-
// pong
|
|
67
|
-
break;
|
|
68
|
-
case 'error':
|
|
69
|
-
this.logger.error(this.LOG_TAG, `receive error: id: ${msg.id}, code: ${msg.code}, error: ${msg.message}`);
|
|
70
|
-
switch (msg.code) {
|
|
71
|
-
case ErrorMessageCode.ChannelNotFound:
|
|
72
|
-
if (this.channelMap.has(msg.id)) {
|
|
73
|
-
// 如果远程报错 channel 不存在但是本机存在,则重新打开
|
|
74
|
-
const channel = this.channelMap.get(msg.id)!;
|
|
75
|
-
if (channel.channelPath) {
|
|
76
|
-
channel.pause();
|
|
77
|
-
channel.open(channel.channelPath, this.clientId);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
83
|
+
// pong 不需要分发, 不处理
|
|
82
84
|
break;
|
|
85
|
+
|
|
83
86
|
default: {
|
|
84
87
|
const channel = this.channelMap.get(msg.id);
|
|
85
88
|
if (channel) {
|
|
@@ -138,7 +141,7 @@ export class WSChannelHandler {
|
|
|
138
141
|
this.logger.log(this.LOG_TAG, `channel ${key} already exists, dispose it`);
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
const channel = new WSChannel(this.
|
|
144
|
+
const channel = new WSChannel(this.wrappedConnection, {
|
|
142
145
|
id: key,
|
|
143
146
|
logger: this.logger,
|
|
144
147
|
ensureServerReady: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|