@hydranium/client-theia 1.0.0-next.19 → 1.0.0-next.192
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 +39 -6
- package/lib/browser/browser-capture.js.map +1 -1
- package/lib/browser/channel-logger.d.ts +4 -3
- package/lib/browser/channel-logger.d.ts.map +1 -1
- package/lib/browser/channel-logger.js +9 -4
- package/lib/browser/channel-logger.js.map +1 -1
- package/lib/browser/connection-diagnostics-contribution.d.ts +69 -0
- package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
- package/lib/browser/connection-diagnostics-contribution.js +153 -0
- package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
- package/lib/browser/connection-reporter.d.ts +57 -0
- package/lib/browser/connection-reporter.d.ts.map +1 -0
- package/lib/browser/connection-reporter.js +104 -0
- package/lib/browser/connection-reporter.js.map +1 -0
- package/lib/browser/editor-disk-sync.d.ts +133 -0
- package/lib/browser/editor-disk-sync.d.ts.map +1 -0
- package/lib/browser/editor-disk-sync.js +232 -0
- package/lib/browser/editor-disk-sync.js.map +1 -0
- package/lib/browser/hydranium-file-service.d.ts +44 -0
- package/lib/browser/hydranium-file-service.d.ts.map +1 -0
- package/lib/browser/hydranium-file-service.js +61 -0
- package/lib/browser/hydranium-file-service.js.map +1 -0
- package/lib/browser/index.d.ts +5 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +5 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/log-level-preference.d.ts.map +1 -1
- package/lib/browser/log-level-preference.js +11 -0
- package/lib/browser/log-level-preference.js.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.d.ts +40 -4
- package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.js +161 -31
- package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
- package/lib/browser/session-aware-connection-source.d.ts +101 -0
- package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
- package/lib/browser/session-aware-connection-source.js +184 -0
- package/lib/browser/session-aware-connection-source.js.map +1 -0
- package/lib/common/clock.d.ts +19 -0
- package/lib/common/clock.d.ts.map +1 -0
- package/lib/common/clock.js +13 -0
- package/lib/common/clock.js.map +1 -0
- package/lib/common/connection-resilience-options.d.ts +30 -0
- package/lib/common/connection-resilience-options.d.ts.map +1 -0
- package/lib/common/connection-resilience-options.js +11 -0
- package/lib/common/connection-resilience-options.js.map +1 -0
- package/lib/common/framed-socket-write-buffer.d.ts +173 -0
- package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
- package/lib/common/framed-socket-write-buffer.js +293 -0
- package/lib/common/framed-socket-write-buffer.js.map +1 -0
- package/lib/common/inbound-message-sequence.d.ts +56 -0
- package/lib/common/inbound-message-sequence.d.ts.map +1 -0
- package/lib/common/inbound-message-sequence.js +98 -0
- package/lib/common/inbound-message-sequence.js.map +1 -0
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +32 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +12 -8
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
- package/lib/node/abstract-socket-forwarding-connection-handler.js +70 -13
- package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/session-bound-frontend-connection-service.d.ts +118 -0
- package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
- package/lib/node/session-bound-frontend-connection-service.js +224 -0
- package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
- package/lib/node/socket-channel-forwarder.d.ts +54 -0
- package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
- package/lib/node/socket-channel-forwarder.js +93 -0
- package/lib/node/socket-channel-forwarder.js.map +1 -0
- package/lib/testing/stub-inversify-context.js.map +1 -1
- package/lib/testing/stub-output-channel.js.map +1 -1
- package/package.json +35 -20
- package/src/browser/channel-logger.ts +9 -4
- package/src/browser/connection-diagnostics-contribution.ts +142 -0
- package/src/browser/connection-reporter.ts +121 -0
- package/src/browser/editor-disk-sync.ts +236 -0
- package/src/browser/hydranium-file-service.ts +56 -0
- package/src/browser/index.ts +5 -0
- package/src/browser/log-level-preference.ts +11 -0
- package/src/browser/memory-diagnostics-contribution.ts +268 -45
- package/src/browser/session-aware-connection-source.ts +196 -0
- package/src/common/clock.ts +20 -0
- package/src/common/connection-resilience-options.ts +30 -0
- package/src/common/framed-socket-write-buffer.ts +345 -0
- package/src/common/inbound-message-sequence.ts +102 -0
- package/src/common/index.ts +16 -0
- package/src/node/abstract-socket-forwarding-connection-handler.ts +61 -15
- package/src/node/index.ts +2 -0
- package/src/node/session-bound-frontend-connection-service.ts +260 -0
- package/src/node/socket-channel-forwarder.ts +99 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.InboundMessageSequence = exports.ACKNOWLEDGEMENT_EVENT = void 0;
|
|
12
|
+
const framed_socket_write_buffer_1 = require("./framed-socket-write-buffer");
|
|
13
|
+
/** The socket.io event that carries the highest message number a side has accepted. */
|
|
14
|
+
exports.ACKNOWLEDGEMENT_EVENT = 'hydranium:ack';
|
|
15
|
+
/**
|
|
16
|
+
* What one side has received on a session: drops a message it already accepted
|
|
17
|
+
* and acknowledges the rest.
|
|
18
|
+
*
|
|
19
|
+
* The peer resends everything unacknowledged when a session resumes, because it
|
|
20
|
+
* cannot tell which of its messages died with the old socket, so every resumed
|
|
21
|
+
* session can repeat messages already delivered. Delivering one twice corrupts
|
|
22
|
+
* anything applied by position, just as losing one does.
|
|
23
|
+
*
|
|
24
|
+
* Acknowledges once enough has arrived, and otherwise after a short delay. A
|
|
25
|
+
* timer alone is not enough: a background tab throttles timers, and the peer
|
|
26
|
+
* holds every unacknowledged message until the acknowledgement arrives. The
|
|
27
|
+
* first message of a session is acknowledged at once, because the peer resends
|
|
28
|
+
* nothing until an acknowledgement shows it may.
|
|
29
|
+
*
|
|
30
|
+
* Belongs to one session. A new session numbers from the start again, so it
|
|
31
|
+
* needs a new instance.
|
|
32
|
+
*/
|
|
33
|
+
class InboundMessageSequence {
|
|
34
|
+
sendAcknowledgement;
|
|
35
|
+
static ACKNOWLEDGE_AFTER_MESSAGES = 64;
|
|
36
|
+
static ACKNOWLEDGE_AFTER_BYTES = 32 * 1024;
|
|
37
|
+
static ACKNOWLEDGE_DELAY_MS = 100;
|
|
38
|
+
lastAccepted = 0;
|
|
39
|
+
messagesSinceAcknowledgement = 0;
|
|
40
|
+
bytesSinceAcknowledgement = 0;
|
|
41
|
+
acknowledgementTimer;
|
|
42
|
+
constructor(sendAcknowledgement) {
|
|
43
|
+
this.sendAcknowledgement = sendAcknowledgement;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether to deliver a message that arrived with `sequence`.
|
|
47
|
+
*
|
|
48
|
+
* A message without a number comes from a peer that does not number them,
|
|
49
|
+
* and is delivered as it is. A duplicate is still acknowledged: the peer
|
|
50
|
+
* resent it because an earlier acknowledgement was lost, and keeps it until
|
|
51
|
+
* one arrives.
|
|
52
|
+
*
|
|
53
|
+
* A skipped number is delivered past, with a warning: the skipped messages
|
|
54
|
+
* are lost, and this is the one place that can tell.
|
|
55
|
+
*/
|
|
56
|
+
accept(sequence, bytes) {
|
|
57
|
+
if (typeof sequence !== 'number') {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
const isFirst = this.lastAccepted === 0;
|
|
61
|
+
const isNew = sequence > this.lastAccepted;
|
|
62
|
+
if (isNew) {
|
|
63
|
+
if (sequence > this.lastAccepted + 1) {
|
|
64
|
+
const missing = sequence - this.lastAccepted - 1;
|
|
65
|
+
console.warn(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} lost ${missing} message(s), numbered ${this.lastAccepted + 1} to ${sequence - 1}; ` +
|
|
66
|
+
'they never arrived and nothing will resend them');
|
|
67
|
+
}
|
|
68
|
+
this.lastAccepted = sequence;
|
|
69
|
+
}
|
|
70
|
+
this.messagesSinceAcknowledgement++;
|
|
71
|
+
this.bytesSinceAcknowledgement += bytes;
|
|
72
|
+
if (isFirst ||
|
|
73
|
+
this.messagesSinceAcknowledgement >= InboundMessageSequence.ACKNOWLEDGE_AFTER_MESSAGES ||
|
|
74
|
+
this.bytesSinceAcknowledgement >= InboundMessageSequence.ACKNOWLEDGE_AFTER_BYTES) {
|
|
75
|
+
this.acknowledge();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.acknowledgementTimer ??= setTimeout(() => this.acknowledge(), InboundMessageSequence.ACKNOWLEDGE_DELAY_MS);
|
|
79
|
+
}
|
|
80
|
+
return isNew;
|
|
81
|
+
}
|
|
82
|
+
/** Sends the acknowledgement now rather than waiting for more traffic. */
|
|
83
|
+
acknowledge() {
|
|
84
|
+
this.cancelTimer();
|
|
85
|
+
this.messagesSinceAcknowledgement = 0;
|
|
86
|
+
this.bytesSinceAcknowledgement = 0;
|
|
87
|
+
this.sendAcknowledgement(this.lastAccepted);
|
|
88
|
+
}
|
|
89
|
+
dispose() {
|
|
90
|
+
this.cancelTimer();
|
|
91
|
+
}
|
|
92
|
+
cancelTimer() {
|
|
93
|
+
clearTimeout(this.acknowledgementTimer);
|
|
94
|
+
this.acknowledgementTimer = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.InboundMessageSequence = InboundMessageSequence;
|
|
98
|
+
//# sourceMappingURL=inbound-message-sequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound-message-sequence.js","sourceRoot":"","sources":["../../src/common/inbound-message-sequence.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,6EAAqE;AAErE,uFAAuF;AAC1E,QAAA,qBAAqB,GAAG,eAAe,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH;IAUkC,mBAAmB;IATlD,MAAM,CAAU,0BAA0B,GAAG,EAAE,CAAC;IAChD,MAAM,CAAU,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;IACpD,MAAM,CAAU,oBAAoB,GAAG,GAAG,CAAC;IAEjC,YAAY,GAAG,CAAC,CAAC;IACjB,4BAA4B,GAAG,CAAC,CAAC;IACjC,yBAAyB,GAAG,CAAC,CAAC;IAC9B,oBAAoB,CAA4C;IAE1E,YAA+B,mBAA+C;mCAA/C,mBAAmB;IAA+B,CAAC;IAElF;;;;;;;;;;OAUG;IACH,MAAM,CAAC,QAAiB,EAAE,KAAa;QACpC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC;QACf,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACT,IAAI,QAAQ,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;gBACpC,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;gBACjD,OAAO,CAAC,IAAI,CACT,GAAG,kDAAqB,SAAS,OAAO,yBAAyB,IAAI,CAAC,YAAY,GAAG,CAAC,OAAO,QAAQ,GAAG,CAAC,IAAI;oBAC1G,iDAAiD,CACtD,CAAC;YACL,CAAC;YACD,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAChC,CAAC;QACD,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,yBAAyB,IAAI,KAAK,CAAC;QACxC,IACG,OAAO;YACP,IAAI,CAAC,4BAA4B,IAAI,sBAAsB,CAAC,0BAA0B;YACtF,IAAI,CAAC,yBAAyB,IAAI,sBAAsB,CAAC,uBAAuB,EACjF,CAAC;YACA,IAAI,CAAC,WAAW,EAAE,CAAC;QACtB,CAAC;aAAM,CAAC;YACL,IAAI,CAAC,oBAAoB,KAAK,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;QACnH,CAAC;QACD,OAAO,KAAK,CAAC;IAChB,CAAC;IAED,0EAA0E;IAC1E,WAAW;QACR,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,yBAAyB,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACJ,IAAI,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;IAES,WAAW;QAClB,YAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACxC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;IACzC,CAAC;CACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
export * from './framed-socket-write-buffer';
|
|
10
|
+
export * from './inbound-message-sequence';
|
|
11
|
+
export * from './connection-resilience-options';
|
|
12
|
+
export * from './clock';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAKlF,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
// Environment-neutral primitives that the browser and the server tiers each
|
|
26
|
+
// bind for their own side, such as the buffer for each half of the socket.
|
|
27
|
+
// Kept out of both tier barrels for that reason.
|
|
28
|
+
__exportStar(require("./framed-socket-write-buffer"), exports);
|
|
29
|
+
__exportStar(require("./inbound-message-sequence"), exports);
|
|
30
|
+
__exportStar(require("./connection-resilience-options"), exports);
|
|
31
|
+
__exportStar(require("./clock"), exports);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,4EAA4E;AAC5E,2EAA2E;AAC3E,iDAAiD;AACjD,+DAA6C;AAC7C,6DAA2C;AAC3C,kEAAgD;AAChD,0CAAwB"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { type Channel, CommandService, type ConnectionHandler, type Disposable, ILogger, type MessageProvider, MessageService } from '@theia/core';
|
|
10
10
|
import * as net from 'node:net';
|
|
11
|
+
import { Clock } from '../common/clock';
|
|
11
12
|
/** Resolved configuration for a {@link AbstractSocketForwardingConnectionHandler}.
|
|
12
13
|
* A head-specific subclass derives these from its own (adopter-facing) options
|
|
13
14
|
* and passes them to `super(...)`. */
|
|
@@ -47,17 +48,17 @@ export interface SocketForwardingConnectionHandlerOptions {
|
|
|
47
48
|
* the same wire protocol the server speaks, so the backend performs no semantic
|
|
48
49
|
* re-proxy — it relays bytes only and stays oblivious to the server's method set.
|
|
49
50
|
*
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* behind the hook is what lets the data head stay GLSP-free while sharing the
|
|
55
|
-
* port-discovery + buffer-and-replay race fix + connect orchestration here.
|
|
51
|
+
* The byte forwarder that bridges the channel and the socket is
|
|
52
|
+
* {@link forwardToSocketConnection}; both heads use {@link SocketChannelForwarder},
|
|
53
|
+
* and the port discovery, buffer-and-replay race fix and connect orchestration
|
|
54
|
+
* here are shared.
|
|
56
55
|
*/
|
|
57
56
|
export declare abstract class AbstractSocketForwardingConnectionHandler implements ConnectionHandler {
|
|
58
57
|
protected messageService: MessageService;
|
|
59
58
|
protected commandService: CommandService;
|
|
60
59
|
protected readonly logger: ILogger;
|
|
60
|
+
/** The clock each {@link SocketChannelForwarder} bounds its flush on: the container's {@link Clock}, or a `SystemClock`. */
|
|
61
|
+
protected readonly clock: Clock;
|
|
61
62
|
readonly path: string;
|
|
62
63
|
protected readonly portCommand: string;
|
|
63
64
|
protected readonly logComponent: string;
|
|
@@ -69,7 +70,10 @@ export declare abstract class AbstractSocketForwardingConnectionHandler implemen
|
|
|
69
70
|
constructor(options: SocketForwardingConnectionHandlerOptions);
|
|
70
71
|
onConnection(connection: Channel): void;
|
|
71
72
|
protected initializeServerConnection(channel: Channel): Promise<void>;
|
|
72
|
-
|
|
73
|
+
/** Tell the user this handler gave up; `message` is the reason it logged. */
|
|
74
|
+
protected reportConnectFailure(message: string): void;
|
|
75
|
+
/** Poll the port command until it answers, its attempts run out, or `signal` aborts. */
|
|
76
|
+
protected findPort(signal?: AbortSignal): Promise<number>;
|
|
73
77
|
protected connectToServer(channel: Channel, port: number, preForwardBuffer?: {
|
|
74
78
|
bufferSub: Disposable;
|
|
75
79
|
buffered: MessageProvider[];
|
|
@@ -79,7 +83,7 @@ export declare abstract class AbstractSocketForwardingConnectionHandler implemen
|
|
|
79
83
|
* relay both ways. Called once, after the socket is created and the
|
|
80
84
|
* pre-forward buffer is about to be replayed.
|
|
81
85
|
*/
|
|
82
|
-
protected
|
|
86
|
+
protected forwardToSocketConnection(clientChannel: Channel, socket: net.Socket): Disposable;
|
|
83
87
|
/**
|
|
84
88
|
* Re-fire pre-forward buffered `MessageProvider`s on the channel's internal
|
|
85
89
|
* `onMessageEmitter` so the now-subscribed forwarder picks them up in arrival
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-socket-forwarding-connection-handler.d.ts","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;
|
|
1
|
+
{"version":3,"file":"abstract-socket-forwarding-connection-handler.d.ts","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,OAAO,EACJ,KAAK,OAAO,EACZ,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,OAAO,EACP,KAAK,eAAe,EACpB,cAAc,EAChB,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC;;uCAEuC;AACvC,MAAM,WAAW,wCAAwC;IACtD,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;iEAC6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;gCAC4B;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;0BACsB;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,8BACsB,yCAA0C,YAAW,iBAAiB;IACjE,SAAS,CAAC,cAAc,EAAG,cAAc,CAAC;IAC1C,SAAS,CAAC,cAAc,EAAG,cAAc,CAAC;IAIjD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAG,OAAO,CAAC;IACrD,4HAA4H;IACjG,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAA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C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,CAgBpF;CACH"}
|
|
@@ -51,11 +51,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.AbstractSocketForwardingConnectionHandler = void 0;
|
|
54
|
+
const protocol_1 = require("@hydranium/protocol");
|
|
54
55
|
const core_1 = require("@theia/core");
|
|
55
56
|
const channel_1 = require("@theia/core/lib/common/message-rpc/channel");
|
|
56
57
|
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
57
58
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
58
59
|
const net = __importStar(require("node:net"));
|
|
60
|
+
const clock_1 = require("../common/clock");
|
|
61
|
+
const socket_channel_forwarder_1 = require("./socket-channel-forwarder");
|
|
59
62
|
/**
|
|
60
63
|
* Cross-head base for the Theia backend half of a protocol head's transport:
|
|
61
64
|
* it bridges a Theia browser-frontend {@link Channel} to a server's TCP socket
|
|
@@ -68,12 +71,10 @@ const net = __importStar(require("node:net"));
|
|
|
68
71
|
* the same wire protocol the server speaks, so the backend performs no semantic
|
|
69
72
|
* re-proxy — it relays bytes only and stays oblivious to the server's method set.
|
|
70
73
|
*
|
|
71
|
-
* The
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* behind the hook is what lets the data head stay GLSP-free while sharing the
|
|
76
|
-
* port-discovery + buffer-and-replay race fix + connect orchestration here.
|
|
74
|
+
* The byte forwarder that bridges the channel and the socket is
|
|
75
|
+
* {@link forwardToSocketConnection}; both heads use {@link SocketChannelForwarder},
|
|
76
|
+
* and the port discovery, buffer-and-replay race fix and connect orchestration
|
|
77
|
+
* here are shared.
|
|
77
78
|
*/
|
|
78
79
|
let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingConnectionHandler {
|
|
79
80
|
messageService;
|
|
@@ -82,6 +83,8 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
82
83
|
// not the spawned language-server process, so the framework `LspLogger`
|
|
83
84
|
// (which needs the Langium connection/services) is out of reach here.
|
|
84
85
|
logger;
|
|
86
|
+
/** The clock each {@link SocketChannelForwarder} bounds its flush on: the container's {@link Clock}, or a `SystemClock`. */
|
|
87
|
+
clock = new protocol_1.SystemClock();
|
|
85
88
|
path;
|
|
86
89
|
portCommand;
|
|
87
90
|
logComponent;
|
|
@@ -115,32 +118,68 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
115
118
|
// window.
|
|
116
119
|
const buffered = [];
|
|
117
120
|
const bufferSub = channel.onMessage(provider => buffered.push(provider));
|
|
121
|
+
const closed = new AbortController();
|
|
122
|
+
const closeSub = channel.onClose(() => closed.abort());
|
|
118
123
|
try {
|
|
119
|
-
const port = await this.findPort();
|
|
124
|
+
const port = await this.findPort(closed.signal);
|
|
125
|
+
closed.signal.throwIfAborted();
|
|
120
126
|
this.logger.info(`[${this.logComponent}] Connecting to ${this.serverName} on port ${port}...`);
|
|
121
127
|
await this.connectToServer(channel, port, { bufferSub, buffered });
|
|
122
128
|
this.logger.info(`[${this.logComponent}] Connected to ${this.serverName} on port ${port}.`);
|
|
123
129
|
}
|
|
124
130
|
catch (error) {
|
|
125
131
|
bufferSub.dispose();
|
|
132
|
+
if (closed.signal.aborted) {
|
|
133
|
+
this.logger.info(`[${this.logComponent}] Stopped connecting to ${this.serverName}: the frontend closed the channel.`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
126
136
|
const message = error && typeof error === 'object' && 'message' in error ? String(error.message) : String(error);
|
|
127
137
|
this.logger.error(`[${this.logComponent}] Could not connect to ${this.serverName}: ${message}`);
|
|
128
|
-
this.
|
|
138
|
+
this.reportConnectFailure(message);
|
|
139
|
+
// Closed so the frontend learns of it: left open, the channel has no
|
|
140
|
+
// server behind it, and every request on it waits for good.
|
|
141
|
+
channel.close();
|
|
129
142
|
}
|
|
143
|
+
finally {
|
|
144
|
+
closeSub.dispose();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Tell the user this handler gave up; `message` is the reason it logged. */
|
|
148
|
+
reportConnectFailure(message) {
|
|
149
|
+
this.messageService.error(`Could not connect to ${this.serverName}: ` + message);
|
|
130
150
|
}
|
|
131
|
-
|
|
151
|
+
/** Poll the port command until it answers, its attempts run out, or `signal` aborts. */
|
|
152
|
+
async findPort(signal) {
|
|
132
153
|
const pendingContent = new promise_util_1.Deferred();
|
|
133
154
|
let counter = 0;
|
|
155
|
+
let timer;
|
|
156
|
+
const stop = () => {
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
pendingContent.reject(signal?.reason);
|
|
159
|
+
};
|
|
160
|
+
if (signal?.aborted) {
|
|
161
|
+
stop();
|
|
162
|
+
}
|
|
163
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
134
164
|
const tryQueryingPort = () => {
|
|
135
|
-
|
|
165
|
+
if (signal?.aborted) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
timer = setTimeout(async () => {
|
|
136
169
|
try {
|
|
137
170
|
const port = await this.commandService.executeCommand(this.portCommand);
|
|
138
|
-
|
|
139
|
-
|
|
171
|
+
// An empty answer fails the attempt like a throw does: left
|
|
172
|
+
// unanswered, it neither resolves nor re-queues, and the lookup
|
|
173
|
+
// stays pending with nothing logged.
|
|
174
|
+
if (!port) {
|
|
175
|
+
throw new Error(`Port command '${this.portCommand}' answered without a port.`);
|
|
140
176
|
}
|
|
177
|
+
pendingContent.resolve(port);
|
|
141
178
|
}
|
|
142
179
|
catch (error) {
|
|
143
180
|
counter++;
|
|
181
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
+
this.logger.debug(`[${this.logComponent}] Port command '${this.portCommand}' attempt ${counter} failed: ${message}`);
|
|
144
183
|
if (this.findPortAttempts >= 0 && counter > this.findPortAttempts) {
|
|
145
184
|
pendingContent.reject(error);
|
|
146
185
|
}
|
|
@@ -173,10 +212,23 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
173
212
|
if (channel instanceof channel_1.ForwardingChannel) {
|
|
174
213
|
socket.on('error', error => channel.onErrorEmitter.fire(error));
|
|
175
214
|
}
|
|
176
|
-
|
|
215
|
+
// `127.0.0.1`, not the `localhost` Node dials when no host is given, and it
|
|
216
|
+
// has to match the head: the socket launchers bind `127.0.0.1` by default,
|
|
217
|
+
// so on a dual-stack machine where `localhost` resolves to `::1` first the
|
|
218
|
+
// dial fails as ECONNREFUSED with nothing in the message naming the address
|
|
219
|
+
// family as the cause.
|
|
220
|
+
socket.connect({ port, host: '127.0.0.1' });
|
|
177
221
|
setTimeout(() => connected.reject('Timeout reached.'), this.connectTimeoutMs);
|
|
178
222
|
return connected.promise;
|
|
179
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Bridge the Theia frontend `clientChannel` and the server `socket` so bytes
|
|
226
|
+
* relay both ways. Called once, after the socket is created and the
|
|
227
|
+
* pre-forward buffer is about to be replayed.
|
|
228
|
+
*/
|
|
229
|
+
forwardToSocketConnection(clientChannel, socket) {
|
|
230
|
+
return new socket_channel_forwarder_1.SocketChannelForwarder(clientChannel, socket, this.clock);
|
|
231
|
+
}
|
|
180
232
|
/**
|
|
181
233
|
* Re-fire pre-forward buffered `MessageProvider`s on the channel's internal
|
|
182
234
|
* `onMessageEmitter` so the now-subscribed forwarder picks them up in arrival
|
|
@@ -217,6 +269,11 @@ __decorate([
|
|
|
217
269
|
(0, inversify_1.inject)(core_1.ILogger),
|
|
218
270
|
__metadata("design:type", Object)
|
|
219
271
|
], AbstractSocketForwardingConnectionHandler.prototype, "logger", void 0);
|
|
272
|
+
__decorate([
|
|
273
|
+
(0, inversify_1.inject)(clock_1.Clock),
|
|
274
|
+
(0, inversify_1.optional)(),
|
|
275
|
+
__metadata("design:type", Object)
|
|
276
|
+
], AbstractSocketForwardingConnectionHandler.prototype, "clock", void 0);
|
|
220
277
|
exports.AbstractSocketForwardingConnectionHandler = AbstractSocketForwardingConnectionHandler = __decorate([
|
|
221
278
|
(0, inversify_1.injectable)(),
|
|
222
279
|
__metadata("design:paramtypes", [Object])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-socket-forwarding-connection-handler.js","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElF,sCAQqB;AACrB,wEAA+E;AAC/E,sEAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"abstract-socket-forwarding-connection-handler.js","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElF,kDAAkD;AAClD,sCAQqB;AACrB,wEAA+E;AAC/E,sEAA+D;AAC/D,4DAA4E;AAC5E,MAAY,GAAG,qCAAiB;AAChC,2CAAwC;AACxC,yEAAoE;AA8BpE;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAe,yCAAyC,GAAxD,MAAe,yCAAyC;IAC1B,cAAc,CAAkB;IAChC,cAAc,CAAkB;IAClE,4EAA4E;IAC5E,wEAAwE;IACxE,sEAAsE;IAClC,MAAM,CAAW;IACrD,4HAA4H;IAC9E,KAAK,GAAU,IAAI,sBAAW,EAAE,CAAC;IAEtE,IAAI,CAAS;IAEH,WAAW,CAAS;IACpB,YAAY,CAAS;IACrB,UAAU,CAAS;IACnB,eAAe,CAAS;IACxB,gBAAgB,CAAS;IACzB,gBAAgB,CAAS;IACzB,eAAe,CAAgC;IAElE,YAAY,OAAiD;QAC1D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI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Ac,QAAQ,CAAC,MAAM,6EAA6E,CACjI,CAAC;YACF,OAAO;QACV,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,YAAY,eAAe,QAAQ,CAAC,MAAM,yDAAyD,CAAC,CAAC;QAC/H,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;IACJ,CAAC;CACH,CAAA;;AA9LoC;IAAjC,IAAA,kBAAM,EAAC,qBAAc,CAAC;8BAA4B,qBAAc;iFAAC;AAChC;IAAjC,IAAA,kBAAM,EAAC,qBAAc,CAAC;;iFAA2C;AAI9B;IAAnC,IAAA,kBAAM,EAAC,cAAO,CAAC;;yEAAqC;AAEP;IAA7C,IAAA,kBAAM,EAAC,aAAK,CAAC;IAAE,IAAA,oBAAQ,GAAE;;wEAAqD;oDAR5D,yCAAyC;IAD9D,IAAA,sBAAU,GAAE;;GACS,yCAAyC,CA+L9D"}
|
package/lib/node/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
export * from './abstract-socket-forwarding-connection-handler';
|
|
10
|
+
export * from './session-bound-frontend-connection-service';
|
|
11
|
+
export * from './socket-channel-forwarder';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,iDAAiD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,iDAAiD,CAAC;AAChE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,4BAA4B,CAAC"}
|
package/lib/node/index.js
CHANGED
|
@@ -23,4 +23,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
__exportStar(require("./abstract-socket-forwarding-connection-handler"), exports);
|
|
26
|
+
__exportStar(require("./session-bound-frontend-connection-service"), exports);
|
|
27
|
+
__exportStar(require("./socket-channel-forwarder"), exports);
|
|
26
28
|
//# sourceMappingURL=index.js.map
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAgE"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAgE;AAChE,8EAA4D;AAC5D,6DAA2C"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
10
|
+
import { AbstractChannel } from '@theia/core/lib/common/message-rpc/channel';
|
|
11
|
+
import { type WriteBuffer } from '@theia/core/lib/common/message-rpc/message-buffer';
|
|
12
|
+
import { WebsocketFrontendConnectionService } from '@theia/core/lib/node/messaging/websocket-frontend-connection-service';
|
|
13
|
+
import { type interfaces } from '@theia/core/shared/inversify';
|
|
14
|
+
import { type ConnectionResilienceOptions } from '../common/connection-resilience-options';
|
|
15
|
+
import { FramedSocketWriteBuffer } from '../common/framed-socket-write-buffer';
|
|
16
|
+
import { InboundMessageSequence } from '../common/inbound-message-sequence';
|
|
17
|
+
/**
|
|
18
|
+
* Socket Theia hands the disconnect handler, read off the base signature rather
|
|
19
|
+
* than imported, which spares a direct `socket.io` dependency carried purely
|
|
20
|
+
* for a parameter type.
|
|
21
|
+
*/
|
|
22
|
+
export type FrontendSocket = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[0];
|
|
23
|
+
/**
|
|
24
|
+
* Channel Theia hands the disconnect handler, read off the base signature so
|
|
25
|
+
* this package's emitted declarations name only
|
|
26
|
+
* `WebsocketFrontendConnectionService`.
|
|
27
|
+
*
|
|
28
|
+
* `ReconnectableSocketChannel` is not exported by every Theia release in the
|
|
29
|
+
* supported range, so importing it would make those declarations unresolvable
|
|
30
|
+
* for an adopter on one of them — a compile error for a feature they may not
|
|
31
|
+
* even be using.
|
|
32
|
+
*/
|
|
33
|
+
export type FrontendChannel = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[1];
|
|
34
|
+
/**
|
|
35
|
+
* The server end of one frontend's session, carried across the sockets the
|
|
36
|
+
* frontend reconnects on.
|
|
37
|
+
*
|
|
38
|
+
* Theia's own channel sends straight into any socket that reports itself
|
|
39
|
+
* connected. A socket whose far end died unnoticed still does, so whatever is
|
|
40
|
+
* sent until the server notices is lost. This one numbers and keeps every
|
|
41
|
+
* message through {@link FramedSocketWriteBuffer}, resends what is still
|
|
42
|
+
* unacknowledged when the frontend reconnects, and drops what it has received
|
|
43
|
+
* twice. Otherwise it behaves as Theia's.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AcknowledgedSocketChannel extends AbstractChannel {
|
|
46
|
+
protected readonly socketBuffer: FramedSocketWriteBuffer;
|
|
47
|
+
protected socket: FrontendSocket | undefined;
|
|
48
|
+
protected socketDisposables: DisposableCollection;
|
|
49
|
+
protected readonly inbound: InboundMessageSequence;
|
|
50
|
+
constructor(socketBuffer: FramedSocketWriteBuffer);
|
|
51
|
+
/** Flushes in the same step that attaches the listeners, so nothing new can overtake the resend. */
|
|
52
|
+
connect(socket: FrontendSocket): void;
|
|
53
|
+
disconnect(): void;
|
|
54
|
+
drainBuffer(): void;
|
|
55
|
+
getWriteBuffer(): WriteBuffer;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Ignores a disconnect from a socket that no longer belongs to the frontend.
|
|
59
|
+
*
|
|
60
|
+
* A frontend that loses its network reconnects on a new socket within seconds;
|
|
61
|
+
* the server only notices the old one is gone when its next heartbeat write
|
|
62
|
+
* fails, which is a whole ping interval later. For that stretch both sockets are
|
|
63
|
+
* registered against the same session, and Theia's disconnect handler tears the
|
|
64
|
+
* session off its socket without checking which one just died. The late
|
|
65
|
+
* notification from the abandoned socket therefore cuts the healthy one loose.
|
|
66
|
+
* The frontend sees a connected socket and never retries, so the session is dead
|
|
67
|
+
* until the page is reloaded.
|
|
68
|
+
*
|
|
69
|
+
* Changed here: only the socket the session is currently using may act on a
|
|
70
|
+
* disconnect. The handler is rewritten rather than wrapped because the problem
|
|
71
|
+
* sits inside the listener Theia installs; the rest of the body is Theia's.
|
|
72
|
+
*
|
|
73
|
+
* Re-diff against Theia when the supported range moves: `override` catches a changed signature,
|
|
74
|
+
* not a changed body, so this copy can go stale in silence.
|
|
75
|
+
*/
|
|
76
|
+
export declare class SessionBoundFrontendConnectionService extends WebsocketFrontendConnectionService {
|
|
77
|
+
/** Socket each frontend's channel is currently bound to, with the time it was bound. */
|
|
78
|
+
protected readonly bindings: Map<string, {
|
|
79
|
+
socketId: string;
|
|
80
|
+
boundAt: number;
|
|
81
|
+
}>;
|
|
82
|
+
/** When a frontend's live socket went away, so the reconnect gap can be reported. */
|
|
83
|
+
protected readonly offlineSince: Map<string, number>;
|
|
84
|
+
handleSocketDisconnect(socket: FrontendSocket, channel: FrontendChannel, frontEndId: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Theia's body, building an {@link AcknowledgedSocketChannel} in place of its own channel.
|
|
87
|
+
*
|
|
88
|
+
* Handed over through a cast, because Theia types the slot as its own channel class. The cast
|
|
89
|
+
* also hides from the compiler what Theia calls on the channel, so a release that calls a member
|
|
90
|
+
* this one lacks fails at runtime: re-diff with the disconnect handler.
|
|
91
|
+
*/
|
|
92
|
+
protected createConnection(socket: FrontendSocket, frontEndId: string): FrontendChannel;
|
|
93
|
+
/**
|
|
94
|
+
* One buffer per session, from the container Theia resolves its own channel's buffer from.
|
|
95
|
+
* Reached through a structural view because Theia 1.70 does not declare `container`.
|
|
96
|
+
*/
|
|
97
|
+
protected createWriteBuffer(): FramedSocketWriteBuffer;
|
|
98
|
+
protected closeConnection(frontEndId: string, reason: string): void;
|
|
99
|
+
/** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
|
|
100
|
+
* Private there, so the copy is forced; re-diff it with the handler above. */
|
|
101
|
+
protected connectionTimeout(): number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Replaces the server pieces that decide how a session survives a reconnect.
|
|
105
|
+
*
|
|
106
|
+
* `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
|
|
107
|
+
* so rebinding the concrete class is enough. The buffer stays transient (one per
|
|
108
|
+
* connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
|
|
109
|
+
* counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
|
|
110
|
+
* module, which is the only point early enough on that side.
|
|
111
|
+
*
|
|
112
|
+
* Does nothing but warn on a Theia too old to expose the buffer binding, so the
|
|
113
|
+
* package keeps one supported range rather than splitting its floor for this
|
|
114
|
+
* feature. Returns whether the hardening was installed, for an adopter that
|
|
115
|
+
* wants to branch on it.
|
|
116
|
+
*/
|
|
117
|
+
export declare function bindConnectionResilience(bind: interfaces.Bind, isBound: interfaces.IsBound, rebind: interfaces.Rebind, options?: ConnectionResilienceOptions): boolean;
|
|
118
|
+
//# sourceMappingURL=session-bound-frontend-connection-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-bound-frontend-connection-service.d.ts","sourceRoot":"","sources":["../../src/node/session-bound-frontend-connection-service.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAc,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAIrF,OAAO,EAAE,kCAAkC,EAAE,MAAM,sEAAsE,CAAC;AAC1H,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAGJ,uBAAuB,EAGzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAyB,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEnG;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,kCAAkC,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzG;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,kCAAkC,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1G;;;;;;;;;;GAUG;AACH,qBAAa,yBAA0B,SAAQ,eAAe;IAK/C,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,uBAAuB;IAJpE,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IAC7C,SAAS,CAAC,iBAAiB,uBAA8B;IACzD,SAAS,CAAC,QAAQ,CAAC,OAAO,yBAA8F;IAExH,YAA+B,YAAY,EAAE,uBAAuB,EAInE;IAED,oGAAoG;IACpG,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CA+BpC;IAED,UAAU,IAAI,IAAI,CAGjB;IA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