@opensumi/ide-connection 3.1.2-next-1718960862.0 → 3.1.2
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/common/channel/types.d.ts +16 -15
- package/lib/common/channel/types.d.ts.map +1 -1
- package/lib/common/rpc/message-io.d.ts +5 -0
- package/lib/common/rpc/message-io.d.ts.map +1 -1
- package/lib/common/rpc/message-io.js +5 -0
- package/lib/common/rpc/message-io.js.map +1 -1
- package/lib/common/rpc-service/center.d.ts.map +1 -1
- package/lib/common/rpc-service/center.js +0 -2
- package/lib/common/rpc-service/center.js.map +1 -1
- package/lib/common/serializer/fury.d.ts +16 -16
- package/lib/common/serializer/fury.d.ts.map +1 -1
- package/lib/common/serializer/fury.js +34 -13
- package/lib/common/serializer/fury.js.map +1 -1
- package/lib/common/server-handler.d.ts.map +1 -1
- package/lib/common/server-handler.js +12 -15
- package/lib/common/server-handler.js.map +1 -1
- package/lib/common/ws-channel.d.ts +12 -32
- package/lib/common/ws-channel.d.ts.map +1 -1
- package/lib/common/ws-channel.js +38 -93
- package/lib/common/ws-channel.js.map +1 -1
- package/package.json +5 -5
- package/src/common/channel/types.ts +16 -16
- package/src/common/rpc/message-io.ts +5 -0
- package/src/common/rpc-service/center.ts +0 -2
- package/src/common/serializer/fury.ts +10 -16
- package/src/common/server-handler.ts +13 -17
- package/src/common/ws-channel.ts +48 -119
package/lib/common/ws-channel.js
CHANGED
|
@@ -5,62 +5,6 @@ const events_1 = require("@opensumi/events");
|
|
|
5
5
|
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
6
6
|
const types_1 = require("./channel/types");
|
|
7
7
|
const connection_1 = require("./rpc/connection");
|
|
8
|
-
var MessageDeliveryState;
|
|
9
|
-
(function (MessageDeliveryState) {
|
|
10
|
-
MessageDeliveryState[MessageDeliveryState["ReSend"] = 0] = "ReSend";
|
|
11
|
-
MessageDeliveryState[MessageDeliveryState["Sended"] = 1] = "Sended";
|
|
12
|
-
MessageDeliveryState[MessageDeliveryState["Success"] = 2] = "Success";
|
|
13
|
-
MessageDeliveryState[MessageDeliveryState["Failed"] = 3] = "Failed";
|
|
14
|
-
})(MessageDeliveryState || (MessageDeliveryState = {}));
|
|
15
|
-
class StateTracer {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.map = new Map();
|
|
18
|
-
this.deliveryTimeout = 500;
|
|
19
|
-
this.timerMap = new Map();
|
|
20
|
-
}
|
|
21
|
-
setDeliveryTimeout(timeout) {
|
|
22
|
-
this.deliveryTimeout = timeout;
|
|
23
|
-
}
|
|
24
|
-
set(traceId, state) {
|
|
25
|
-
this.map.set(traceId, state);
|
|
26
|
-
}
|
|
27
|
-
get(traceId) {
|
|
28
|
-
return this.map.get(traceId);
|
|
29
|
-
}
|
|
30
|
-
success(traceId) {
|
|
31
|
-
this.map.set(traceId, MessageDeliveryState.Success);
|
|
32
|
-
const timer = this.timerMap.get(traceId);
|
|
33
|
-
if (timer) {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
dispose() {
|
|
38
|
-
this.timerMap.forEach((timer) => {
|
|
39
|
-
clearTimeout(timer);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
stop(traceId) {
|
|
43
|
-
const timer = this.timerMap.get(traceId);
|
|
44
|
-
if (timer) {
|
|
45
|
-
clearTimeout(timer);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
send(traceId, options) {
|
|
49
|
-
this.set(traceId, MessageDeliveryState.Sended);
|
|
50
|
-
this.guard(traceId, options);
|
|
51
|
-
}
|
|
52
|
-
guard(traceId, options) {
|
|
53
|
-
const timer = this.timerMap.get(traceId);
|
|
54
|
-
if (timer) {
|
|
55
|
-
clearTimeout(timer);
|
|
56
|
-
}
|
|
57
|
-
const newTimer = setTimeout(() => {
|
|
58
|
-
this.set(traceId, MessageDeliveryState.ReSend);
|
|
59
|
-
options.whenRetry();
|
|
60
|
-
}, this.deliveryTimeout);
|
|
61
|
-
this.timerMap.set(traceId, newTimer);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
8
|
class WSChannel {
|
|
65
9
|
constructor(connection, options) {
|
|
66
10
|
this.connection = connection;
|
|
@@ -69,9 +13,9 @@ class WSChannel {
|
|
|
69
13
|
this.onBinaryQueue = this._disposables.add(new ide_core_common_1.EventQueue());
|
|
70
14
|
this.sendQueue = [];
|
|
71
15
|
this._isServerReady = false;
|
|
72
|
-
this.stateTracer = new StateTracer();
|
|
73
16
|
this.LOG_TAG = '[WSChannel]';
|
|
74
17
|
this.logger = console;
|
|
18
|
+
this.stateTracer = this._disposables.add(new ide_core_common_1.StateTracer());
|
|
75
19
|
const { id, logger, ensureServerReady } = options;
|
|
76
20
|
this.id = id;
|
|
77
21
|
this.LOG_TAG = `[WSChannel id:${this.id}]`;
|
|
@@ -79,9 +23,6 @@ class WSChannel {
|
|
|
79
23
|
this.logger = logger;
|
|
80
24
|
}
|
|
81
25
|
this._ensureServerReady = Boolean(ensureServerReady);
|
|
82
|
-
if (options.deliveryTimeout) {
|
|
83
|
-
this.stateTracer.setDeliveryTimeout(options.deliveryTimeout);
|
|
84
|
-
}
|
|
85
26
|
this._disposables.add(this.emitter.on('binary', (data) => this.onBinaryQueue.push(data)));
|
|
86
27
|
}
|
|
87
28
|
inqueue(data) {
|
|
@@ -94,27 +35,6 @@ class WSChannel {
|
|
|
94
35
|
}
|
|
95
36
|
this.connection.send(data);
|
|
96
37
|
}
|
|
97
|
-
/**
|
|
98
|
-
* @param traceId 一个 connection token 用于在全链路中追踪一个消息的生命周期,防止消息未发送或者重复发送
|
|
99
|
-
*/
|
|
100
|
-
ensureMessageDeliveried(data, traceId = (0, ide_core_common_1.randomString)(16)) {
|
|
101
|
-
const state = this.stateTracer.get(traceId);
|
|
102
|
-
if (state && state >= MessageDeliveryState.Sended) {
|
|
103
|
-
this.logger.error(`message already send already success or in progress, traceId: ${traceId}, state: ${state}`);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
data.traceId = traceId;
|
|
107
|
-
this.connection.send(data);
|
|
108
|
-
this.stateTracer.send(traceId, {
|
|
109
|
-
whenRetry: () => {
|
|
110
|
-
if (this._isServerReady) {
|
|
111
|
-
this.stateTracer.stop(traceId);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.ensureMessageDeliveried(data, traceId);
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
38
|
onMessage(cb) {
|
|
119
39
|
return this.emitter.on('message', cb);
|
|
120
40
|
}
|
|
@@ -149,10 +69,11 @@ class WSChannel {
|
|
|
149
69
|
dispatch(msg) {
|
|
150
70
|
switch (msg.kind) {
|
|
151
71
|
case 'server-ready':
|
|
152
|
-
|
|
153
|
-
this.stateTracer.success(msg.traceId);
|
|
154
|
-
}
|
|
72
|
+
this.stateTracer.fulfill(msg.token);
|
|
155
73
|
this.resume();
|
|
74
|
+
if (this.timer) {
|
|
75
|
+
clearTimeout(this.timer);
|
|
76
|
+
}
|
|
156
77
|
this.emitter.emit('open', msg.id);
|
|
157
78
|
break;
|
|
158
79
|
case 'data':
|
|
@@ -177,22 +98,44 @@ class WSChannel {
|
|
|
177
98
|
break;
|
|
178
99
|
}
|
|
179
100
|
}
|
|
180
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @param connectionToken 一个 connection token 用于在全链路中追踪一个 channel 的生命周期,防止 channel 被重复打开
|
|
103
|
+
*/
|
|
104
|
+
open(path, clientId, connectionToken = (0, ide_core_common_1.randomString)(16)) {
|
|
181
105
|
this.channelPath = path;
|
|
182
106
|
this.clientId = clientId;
|
|
183
107
|
this.LOG_TAG = `[WSChannel id=${this.id} path=${path}]`;
|
|
184
|
-
|
|
108
|
+
if (this.stateTracer.has(connectionToken)) {
|
|
109
|
+
this.logger.warn(`channel already opened or in progress, path: ${path}, clientId: ${clientId}, connectionToken: ${connectionToken}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.stateTracer.record(connectionToken);
|
|
113
|
+
this.connection.send({
|
|
185
114
|
kind: 'open',
|
|
186
115
|
id: this.id,
|
|
187
116
|
path,
|
|
188
117
|
clientId,
|
|
189
|
-
|
|
118
|
+
connectionToken,
|
|
119
|
+
});
|
|
190
120
|
if (this._ensureServerReady) {
|
|
191
|
-
this.
|
|
121
|
+
this.ensureOpenSend(path, clientId, connectionToken);
|
|
192
122
|
}
|
|
193
|
-
|
|
194
|
-
|
|
123
|
+
return connectionToken;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 启动定时器,确保 server-ready 消息在一定时间内到达
|
|
127
|
+
*/
|
|
128
|
+
ensureOpenSend(path, clientId, connectionToken) {
|
|
129
|
+
if (this.timer) {
|
|
130
|
+
clearTimeout(this.timer);
|
|
195
131
|
}
|
|
132
|
+
this.timer = setTimeout(() => {
|
|
133
|
+
if (this._isServerReady) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.stateTracer.delete(connectionToken);
|
|
137
|
+
this.open(path, clientId, connectionToken);
|
|
138
|
+
}, 500);
|
|
196
139
|
}
|
|
197
140
|
send(content) {
|
|
198
141
|
this.inqueue({
|
|
@@ -237,7 +180,9 @@ class WSChannel {
|
|
|
237
180
|
return conn;
|
|
238
181
|
}
|
|
239
182
|
dispose() {
|
|
240
|
-
this.
|
|
183
|
+
if (this.timer) {
|
|
184
|
+
clearTimeout(this.timer);
|
|
185
|
+
}
|
|
241
186
|
this.sendQueue = [];
|
|
242
187
|
this._disposables.dispose();
|
|
243
188
|
}
|
|
@@ -259,11 +204,11 @@ class WSServerChannel extends WSChannel {
|
|
|
259
204
|
this.messageQueue = [];
|
|
260
205
|
this.clientId = options.clientId;
|
|
261
206
|
}
|
|
262
|
-
serverReady(
|
|
207
|
+
serverReady(token) {
|
|
263
208
|
this.connection.send({
|
|
264
209
|
kind: 'server-ready',
|
|
265
210
|
id: this.id,
|
|
266
|
-
|
|
211
|
+
token,
|
|
267
212
|
});
|
|
268
213
|
}
|
|
269
214
|
dispatch(msg) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-channel.js","sourceRoot":"","sources":["../../src/common/ws-channel.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAChD,+
|
|
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,YAAmB,UAA4C,EAAE,OAAgC;QAA9E,eAAU,GAAV,UAAU,CAAkC;QA1BrD,iBAAY,GAAG,IAAI,iCAAe,EAAE,CAAC;QACrC,YAAO,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CACvC,IAAI,qBAAY,EAMZ,CACL,CAAC;QAEQ,kBAAa,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,4BAAU,EAAc,CAAC,CAAC;QAEpE,cAAS,GAAqB,EAAE,CAAC;QACjC,mBAAc,GAAG,KAAK,CAAC;QAQvB,YAAO,GAAG,aAAa,CAAC;QAElC,WAAM,GAAY,OAAO,CAAC;QA8F1B,gBAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,6BAAW,EAAE,CAAC,CAAC;QA3FrD,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;QAClD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,GAAG,iBAAiB,IAAI,CAAC,EAAE,GAAG,CAAC;QAC3C,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;QAED,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAErD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAA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AAI,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,MAAM;gBACT,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;oBACnB,IAAI,EAAE,MAAM;oBACZ,EAAE,EAAE,IAAI,CAAC,EAAE;iBACZ,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC;CACF;AAjCD,0CAiCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-connection",
|
|
3
|
-
"version": "3.1.2
|
|
3
|
+
"version": "3.1.2",
|
|
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.1.2
|
|
22
|
+
"@opensumi/ide-core-common": "3.1.2",
|
|
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.1.2
|
|
30
|
-
"@opensumi/ide-dev-tool": "3.1.2
|
|
29
|
+
"@opensumi/ide-components": "3.1.2",
|
|
30
|
+
"@opensumi/ide-dev-tool": "3.1.2",
|
|
31
31
|
"@opensumi/mock-socket": "^9.3.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "43ba89b95907f75c9f62880064bd0edb1d09ad7d"
|
|
34
34
|
}
|
|
@@ -8,42 +8,41 @@ export type ChannelMessage =
|
|
|
8
8
|
| CloseMessage
|
|
9
9
|
| ErrorMessage;
|
|
10
10
|
|
|
11
|
-
export interface BaseMessage {
|
|
12
|
-
kind: string;
|
|
13
|
-
id: string;
|
|
14
|
-
traceId?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
/**
|
|
18
12
|
* `ping` and `pong` are used to detect whether the connection is alive.
|
|
19
13
|
*/
|
|
20
|
-
export interface PingMessage
|
|
14
|
+
export interface PingMessage {
|
|
21
15
|
kind: 'ping';
|
|
16
|
+
id: string;
|
|
22
17
|
}
|
|
23
18
|
|
|
24
19
|
/**
|
|
25
20
|
* when server receive a `ping` message, it should reply a `pong` message, vice versa.
|
|
26
21
|
*/
|
|
27
|
-
export interface PongMessage
|
|
22
|
+
export interface PongMessage {
|
|
28
23
|
kind: 'pong';
|
|
24
|
+
id: string;
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
28
|
* `data` message indicate that the channel has received some data.
|
|
33
29
|
* the `content` field is the data, it should be a string.
|
|
34
30
|
*/
|
|
35
|
-
export interface DataMessage
|
|
31
|
+
export interface DataMessage {
|
|
36
32
|
kind: 'data';
|
|
33
|
+
id: string;
|
|
37
34
|
content: string;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
export interface BinaryMessage
|
|
37
|
+
export interface BinaryMessage {
|
|
41
38
|
kind: 'binary';
|
|
39
|
+
id: string;
|
|
42
40
|
binary: Uint8Array;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
export interface CloseMessage
|
|
43
|
+
export interface CloseMessage {
|
|
46
44
|
kind: 'close';
|
|
45
|
+
id: string;
|
|
47
46
|
code: number;
|
|
48
47
|
reason: string;
|
|
49
48
|
}
|
|
@@ -53,18 +52,19 @@ export interface CloseMessage extends BaseMessage {
|
|
|
53
52
|
* `path` is used to identify which handler should be used to handle the channel.
|
|
54
53
|
* `clientId` is used to identify the client.
|
|
55
54
|
*/
|
|
56
|
-
export interface OpenMessage
|
|
55
|
+
export interface OpenMessage {
|
|
57
56
|
kind: 'open';
|
|
57
|
+
id: string;
|
|
58
58
|
path: string;
|
|
59
59
|
clientId: string;
|
|
60
|
-
|
|
60
|
+
connectionToken: string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export enum ErrorMessageCode {
|
|
64
64
|
ChannelNotFound = 1,
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export interface ErrorMessage
|
|
67
|
+
export interface ErrorMessage {
|
|
68
68
|
kind: 'error';
|
|
69
69
|
id: string;
|
|
70
70
|
code: ErrorMessageCode;
|
|
@@ -75,8 +75,8 @@ export interface ErrorMessage extends BaseMessage {
|
|
|
75
75
|
* when server receive a `open` message, it should reply a `server-ready` message.
|
|
76
76
|
* this is indicate that the channel is ready to use.
|
|
77
77
|
*/
|
|
78
|
-
export interface ServerReadyMessage
|
|
78
|
+
export interface ServerReadyMessage {
|
|
79
79
|
kind: 'server-ready';
|
|
80
80
|
id: string;
|
|
81
|
-
|
|
81
|
+
token: string;
|
|
82
82
|
}
|
|
@@ -351,6 +351,11 @@ export class MessageIO extends IMessageIO<PlatformBuffer> {
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/**
|
|
355
|
+
* 请不要使用 RawMessageIO 作为与 Worker-Host 之间的通信协议
|
|
356
|
+
* 因为与插件层的通信需要正确的反序列化和序列化 Uri/URI/vscode-uri 这三种 uri
|
|
357
|
+
* TODO: 兼容 Uri/URI/vscode-uri 的序列化和反序列化
|
|
358
|
+
*/
|
|
354
359
|
export class RawMessageIO implements IMessageIO<RPCMessage> {
|
|
355
360
|
Request(requestId: number, method: string, headers: IRequestHeaders, args: any[]): RPCRequestMessage {
|
|
356
361
|
return {
|
|
@@ -5,50 +5,44 @@ import { oneOf } from '../fury-extends/one-of';
|
|
|
5
5
|
|
|
6
6
|
import { ISerializer } from './types';
|
|
7
7
|
|
|
8
|
-
function baseFields() {
|
|
9
|
-
return {
|
|
10
|
-
id: Type.string(),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
export const PingProtocol = Type.object('ping', {
|
|
15
|
-
|
|
9
|
+
id: Type.string(),
|
|
16
10
|
});
|
|
17
11
|
|
|
18
12
|
export const PongProtocol = Type.object('pong', {
|
|
19
|
-
|
|
13
|
+
id: Type.string(),
|
|
20
14
|
});
|
|
21
15
|
|
|
22
16
|
export const OpenProtocol = Type.object('open', {
|
|
23
|
-
...baseFields(),
|
|
24
17
|
clientId: Type.string(),
|
|
18
|
+
id: Type.string(),
|
|
25
19
|
path: Type.string(),
|
|
26
|
-
|
|
20
|
+
connectionToken: Type.string(),
|
|
27
21
|
});
|
|
28
22
|
|
|
29
23
|
export const ServerReadyProtocol = Type.object('server-ready', {
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
id: Type.string(),
|
|
25
|
+
token: Type.string(),
|
|
32
26
|
});
|
|
33
27
|
|
|
34
28
|
export const ErrorProtocol = Type.object('error', {
|
|
35
|
-
|
|
29
|
+
id: Type.string(),
|
|
36
30
|
code: Type.uint16(),
|
|
37
31
|
message: Type.string(),
|
|
38
32
|
});
|
|
39
33
|
|
|
40
34
|
export const DataProtocol = Type.object('data', {
|
|
41
|
-
|
|
35
|
+
id: Type.string(),
|
|
42
36
|
content: Type.string(),
|
|
43
37
|
});
|
|
44
38
|
|
|
45
39
|
export const BinaryProtocol = Type.object('binary', {
|
|
46
|
-
|
|
40
|
+
id: Type.string(),
|
|
47
41
|
binary: Type.binary(),
|
|
48
42
|
});
|
|
49
43
|
|
|
50
44
|
export const CloseProtocol = Type.object('close', {
|
|
51
|
-
|
|
45
|
+
id: Type.string(),
|
|
52
46
|
code: Type.uint32(),
|
|
53
47
|
reason: Type.string(),
|
|
54
48
|
});
|
|
@@ -104,11 +104,6 @@ export interface ChannelHandlerOptions {
|
|
|
104
104
|
serializer?: ISerializer<ChannelMessage, any>;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
enum ServerChannelCloseCode {
|
|
108
|
-
ConnectionClosed = 1,
|
|
109
|
-
NewChannelOpened = 2,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
107
|
export abstract class BaseCommonChannelHandler {
|
|
113
108
|
protected channelMap: Map<string, WSServerChannel> = new Map();
|
|
114
109
|
|
|
@@ -140,24 +135,25 @@ export abstract class BaseCommonChannelHandler {
|
|
|
140
135
|
|
|
141
136
|
const wrappedConnection = wrapSerializer(connection, this.serializer);
|
|
142
137
|
|
|
138
|
+
const getOrCreateChannel = (id: string, clientId: string) => {
|
|
139
|
+
let channel = this.channelMap.get(id);
|
|
140
|
+
if (!channel) {
|
|
141
|
+
channel = new WSServerChannel(wrappedConnection, { id, clientId, logger: this.logger });
|
|
142
|
+
this.channelMap.set(id, channel);
|
|
143
|
+
}
|
|
144
|
+
return channel;
|
|
145
|
+
};
|
|
146
|
+
|
|
143
147
|
wrappedConnection.onMessage((msg: ChannelMessage) => {
|
|
144
148
|
try {
|
|
145
149
|
switch (msg.kind) {
|
|
146
150
|
case 'open': {
|
|
147
|
-
const { id, path,
|
|
151
|
+
const { id, path, connectionToken } = msg;
|
|
148
152
|
clientId = msg.clientId;
|
|
149
|
-
|
|
150
153
|
this.logger.log(`open a new connection channel ${clientId} with path ${path}`);
|
|
151
|
-
|
|
152
|
-
if (channel) {
|
|
153
|
-
channel.close(ServerChannelCloseCode.NewChannelOpened, 'new channel opened for the same channel id');
|
|
154
|
-
channel.dispose();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
channel = new WSServerChannel(wrappedConnection, { id, clientId, logger: this.logger });
|
|
158
|
-
this.channelMap.set(id, channel);
|
|
154
|
+
const channel = getOrCreateChannel(id, clientId);
|
|
159
155
|
commonChannelPathHandler.openChannel(path, channel, clientId);
|
|
160
|
-
channel.serverReady(
|
|
156
|
+
channel.serverReady(connectionToken);
|
|
161
157
|
break;
|
|
162
158
|
}
|
|
163
159
|
default: {
|
|
@@ -190,7 +186,7 @@ export abstract class BaseCommonChannelHandler {
|
|
|
190
186
|
Array.from(this.channelMap.values())
|
|
191
187
|
.filter((channel) => channel.clientId === clientId)
|
|
192
188
|
.forEach((channel) => {
|
|
193
|
-
channel.close(
|
|
189
|
+
channel.close(1, 'close');
|
|
194
190
|
channel.dispose();
|
|
195
191
|
this.channelMap.delete(channel.id);
|
|
196
192
|
this.logger.log(`Remove connection channel ${channel.id}`);
|