tirtc-devtools-cli 0.0.13 → 0.0.15
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 +42 -46
- package/USAGE.md +87 -312
- package/dist/cli/src/embedded_paths.d.ts +0 -2
- package/dist/cli/src/embedded_paths.js +3 -25
- package/dist/cli/src/index.js +82 -584
- package/dist/cli/src/role_driver.d.ts +33 -0
- package/dist/cli/src/role_driver.js +500 -0
- package/dist/cli/src/token_command.js +4 -2
- package/dist/cli/src/token_issue.d.ts +9 -0
- package/dist/cli/src/token_issue.js +138 -0
- package/dist/cli/src/token_tool.d.ts +2 -4
- package/dist/cli/src/token_tool.js +12 -186
- package/package.json +3 -2
- package/vendor/devtools/driver/macos-arm64/devtools_driver_probe +0 -0
- package/vendor/devtools/driver/macos-arm64/runtime_validation_client_bin +0 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio.h +56 -2
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io.h +9 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/av.h +52 -0
- package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/error.h +11 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_downlink.h +11 -5
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_uplink.h +4 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/transport.h +52 -15
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/trp.h +7 -5
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_codec.h +41 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io.h +7 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_android.h +2 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_audio.a +0 -0
- package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_foundation_http.a +0 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_foundation_logging.a +0 -0
- package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
- package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
- package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
- package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/manifest.txt +20 -25
- package/vendor/runtime/script/prepare_runtime_media_dataset.sh +308 -12
- package/dist/app-server/protocol-client/index.d.ts +0 -25
- package/dist/app-server/protocol-client/index.js +0 -114
- package/dist/cli/src/bootstrap_flows.d.ts +0 -46
- package/dist/cli/src/bootstrap_flows.js +0 -249
- package/dist/cli/src/config.d.ts +0 -26
- package/dist/cli/src/config.js +0 -62
- package/dist/cli/src/facade.d.ts +0 -430
- package/dist/cli/src/facade.js +0 -170
- package/dist/cli/src/guide.d.ts +0 -1
- package/dist/cli/src/guide.js +0 -48
- package/dist/cli/src/session_manager.d.ts +0 -25
- package/dist/cli/src/session_manager.js +0 -391
- package/dist/cli/src/transport.d.ts +0 -30
- package/dist/cli/src/transport.js +0 -84
- package/vendor/app-server/bin/native/linux-x64/credential_napi.node +0 -0
- package/vendor/app-server/bin/native/macos-arm64/credential_napi.node +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/credential.h +0 -34
- package/vendor/app-server/bin/runtime/linux-x64/lib/libcrypto.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_credential.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_http.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_logging.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libssl.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/lib/libxlog.a +0 -0
- package/vendor/app-server/bin/runtime/linux-x64/manifest.txt +0 -4
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/credential.h +0 -34
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/error.h +0 -52
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/foundation/build_info.h +0 -27
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/http.h +0 -57
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/logging.h +0 -55
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_av_sync.h +0 -61
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_source.h +0 -77
- package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_live_source.h +0 -71
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_credential.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
- package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
- package/vendor/app-server/bin/tirtc-devtool-host.js +0 -2
- package/vendor/app-server/dist/host/ArtifactManager.d.ts +0 -18
- package/vendor/app-server/dist/host/ArtifactManager.js +0 -98
- package/vendor/app-server/dist/host/HostCommandCoordinator.d.ts +0 -19
- package/vendor/app-server/dist/host/HostCommandCoordinator.js +0 -196
- package/vendor/app-server/dist/host/HostProtocol.d.ts +0 -103
- package/vendor/app-server/dist/host/HostProtocol.js +0 -239
- package/vendor/app-server/dist/host/HostServer.d.ts +0 -52
- package/vendor/app-server/dist/host/HostServer.js +0 -727
- package/vendor/app-server/dist/host/HostState.d.ts +0 -69
- package/vendor/app-server/dist/host/HostState.js +0 -19
- package/vendor/app-server/dist/host/RuntimeAdapter.d.ts +0 -95
- package/vendor/app-server/dist/host/RuntimeAdapter.js +0 -636
- package/vendor/app-server/dist/host/RuntimeReceiveWorker.d.ts +0 -37
- package/vendor/app-server/dist/host/RuntimeReceiveWorker.js +0 -186
- package/vendor/app-server/dist/host/RuntimeSendWorker.d.ts +0 -58
- package/vendor/app-server/dist/host/RuntimeSendWorker.js +0 -438
- package/vendor/app-server/dist/host/TokenTool.d.ts +0 -15
- package/vendor/app-server/dist/host/TokenTool.js +0 -84
- package/vendor/app-server/dist/host/WebPreviewGateway.d.ts +0 -28
- package/vendor/app-server/dist/host/WebPreviewGateway.js +0 -815
- package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.d.ts +0 -23
- package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.js +0 -115
- package/vendor/app-server/dist/host/native/RuntimeHostBridge.d.ts +0 -32
- package/vendor/app-server/dist/host/native/RuntimeHostBridge.js +0 -157
- package/vendor/app-server/dist/host/runtime_backed_preflight.d.ts +0 -10
- package/vendor/app-server/dist/host/runtime_backed_preflight.js +0 -78
- package/vendor/app-server/dist/host/tests/helpers/host_socket_client.d.ts +0 -28
- package/vendor/app-server/dist/host/tests/helpers/host_socket_client.js +0 -85
- package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.d.ts +0 -10
- package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.js +0 -41
- package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.d.ts +0 -11
- package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.js +0 -32
- package/vendor/app-server/dist/protocol/contract.d.ts +0 -1128
- package/vendor/app-server/dist/protocol/contract.js +0 -217
- package/vendor/app-server/dist/protocol-client/index.d.ts +0 -25
- package/vendor/app-server/dist/protocol-client/index.js +0 -114
- package/vendor/app-server/dist/src/index.d.ts +0 -1
- package/vendor/app-server/dist/src/index.js +0 -294
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_codec.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_frame.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_android.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_apple.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_harmony.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_windows.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_processing.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_sample_rate.h +0 -0
- /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/foundation/build_info.h +0 -0
- /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/http.h +0 -0
- /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/logging.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_codec.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_frame.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_apple.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_harmony.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_windows.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_processing.h +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libTGTRP.a +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libTiRTC.a +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libcrypto.a +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libcrypto.dylib +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libssl.a +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libssl.dylib +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libtgrtc.dylib +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libwebrtc_apm.a +0 -0
- /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libxlog.a +0 -0
|
@@ -1,727 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.HostServer = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const HostCommandCoordinator_1 = require("./HostCommandCoordinator");
|
|
40
|
-
const TokenTool_1 = require("./TokenTool");
|
|
41
|
-
const HostState_1 = require("./HostState");
|
|
42
|
-
const HostProtocol_1 = require("./HostProtocol");
|
|
43
|
-
function streamBindingKey(streamId, media) {
|
|
44
|
-
return `${streamId}/${media}`;
|
|
45
|
-
}
|
|
46
|
-
function resolveLocalAssetsDir(source) {
|
|
47
|
-
if (source.mode !== 'local_assets') {
|
|
48
|
-
throw new HostProtocol_1.HostProtocolError('invalid_request', 'Unsupported source.mode', false);
|
|
49
|
-
}
|
|
50
|
-
const assetsDir = path.resolve(source.local_assets.assets_dir);
|
|
51
|
-
let stats;
|
|
52
|
-
try {
|
|
53
|
-
stats = fs.statSync(assetsDir);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
throw new HostProtocol_1.HostProtocolError('invalid_request', 'source.local_assets.assets_dir does not exist', false);
|
|
57
|
-
}
|
|
58
|
-
if (!stats.isDirectory()) {
|
|
59
|
-
throw new HostProtocol_1.HostProtocolError('invalid_request', 'source.local_assets.assets_dir must be a directory', false);
|
|
60
|
-
}
|
|
61
|
-
const manifestPath = path.join(assetsDir, 'manifest.json');
|
|
62
|
-
if (!fs.existsSync(manifestPath)) {
|
|
63
|
-
throw new HostProtocol_1.HostProtocolError('invalid_request', 'source.local_assets.assets_dir missing manifest.json', false);
|
|
64
|
-
}
|
|
65
|
-
return assetsDir;
|
|
66
|
-
}
|
|
67
|
-
class HostServer {
|
|
68
|
-
state;
|
|
69
|
-
artifactManager;
|
|
70
|
-
runtimeAdapter;
|
|
71
|
-
commandCoordinator;
|
|
72
|
-
isInitialized = false;
|
|
73
|
-
eventCounter = 1;
|
|
74
|
-
commandSequence = 1;
|
|
75
|
-
tokenTool;
|
|
76
|
-
eventSinks = new Set();
|
|
77
|
-
constructor(artifactManager, runtimeAdapter, hostEndpoint) {
|
|
78
|
-
this.state = new HostState_1.HostState();
|
|
79
|
-
this.artifactManager = artifactManager;
|
|
80
|
-
this.runtimeAdapter = runtimeAdapter;
|
|
81
|
-
this.state.runtimeTarget = runtimeAdapter.runtimeTarget;
|
|
82
|
-
this.state.hostEndpoint = hostEndpoint ?? runtimeAdapter.hostEndpoint;
|
|
83
|
-
this.tokenTool = new TokenTool_1.TokenTool(this.artifactManager.getPaths().rootPath);
|
|
84
|
-
this.commandCoordinator = new HostCommandCoordinator_1.HostCommandCoordinator(this.state, this.runtimeAdapter, (family, kind, payload) => this.writeEvent(family, kind, payload), () => this.snapshotPendingConnectionSummary(), (payload) => this.noteIncomingConnection(payload));
|
|
85
|
-
this.runtimeAdapter.setEventHandler((family, kind, payload) => {
|
|
86
|
-
this.handleRuntimeEvent(family, kind, payload);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async handleMessage(message) {
|
|
90
|
-
let request;
|
|
91
|
-
try {
|
|
92
|
-
request = (0, HostProtocol_1.parseRequest)(message);
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
return JSON.stringify({
|
|
96
|
-
error: {
|
|
97
|
-
code: -32700,
|
|
98
|
-
message: 'Parse error',
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (request.method === 'initialized') {
|
|
103
|
-
this.isInitialized = true;
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
const params = (0, HostProtocol_1.toParamsRecord)(request.params);
|
|
107
|
-
try {
|
|
108
|
-
const result = await this.dispatch(request.method, params);
|
|
109
|
-
if (request.id === undefined) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
return JSON.stringify({ id: request.id, result });
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (request.id === undefined) {
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
const normalized = (0, HostProtocol_1.normalizeError)(error);
|
|
119
|
-
const response = {
|
|
120
|
-
id: request.id,
|
|
121
|
-
error: {
|
|
122
|
-
code: -32000,
|
|
123
|
-
message: normalized.message,
|
|
124
|
-
data: {
|
|
125
|
-
reasonCode: normalized.reasonCode,
|
|
126
|
-
message: normalized.message,
|
|
127
|
-
retryable: normalized.retryable,
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
return JSON.stringify(response);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
writeEvent(family, kind, payload) {
|
|
135
|
-
const event = {
|
|
136
|
-
eventId: 'evt-' + String(this.eventCounter++),
|
|
137
|
-
timestamp: new Date().toISOString(),
|
|
138
|
-
family,
|
|
139
|
-
kind,
|
|
140
|
-
payload,
|
|
141
|
-
};
|
|
142
|
-
this.artifactManager.writeEvent(event);
|
|
143
|
-
if (this.state.subscriptions.has(family) || this.state.subscriptions.has('*')) {
|
|
144
|
-
this.pushEvent(event);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
pushEvent(event) {
|
|
148
|
-
for (const sink of this.eventSinks) {
|
|
149
|
-
try {
|
|
150
|
-
sink(event);
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
// no-op
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
addEventSink(sink) {
|
|
158
|
-
this.eventSinks.add(sink);
|
|
159
|
-
}
|
|
160
|
-
removeEventSink(sink) {
|
|
161
|
-
this.eventSinks.delete(sink);
|
|
162
|
-
}
|
|
163
|
-
appendHostLog(line) {
|
|
164
|
-
const withNewline = line.endsWith('\n') ? line : line + '\n';
|
|
165
|
-
this.artifactManager.appendHostLog(withNewline);
|
|
166
|
-
const normalized = withNewline.endsWith('\n') ? withNewline.slice(0, -1) : withNewline;
|
|
167
|
-
this.writeEvent('logs', 'host.line', { line: normalized });
|
|
168
|
-
}
|
|
169
|
-
handleRuntimeEvent(family, kind, payload) {
|
|
170
|
-
this.writeEvent(family, kind, payload);
|
|
171
|
-
if (family !== 'runtime') {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (kind === 'connection.accepted') {
|
|
175
|
-
this.noteIncomingConnection(payload);
|
|
176
|
-
this.activatePendingStreamsOnConnected();
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (kind === 'connection.disconnected') {
|
|
180
|
-
this.handleIncomingConnectionDisconnected(payload);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (kind === 'command.remote.requested') {
|
|
184
|
-
this.commandCoordinator.handleInboundRemoteCommandRequest(payload);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (kind === 'transport.remote.request_audio' ||
|
|
188
|
-
kind === 'transport.remote.request_video' ||
|
|
189
|
-
kind === 'transport.remote.request_iframe') {
|
|
190
|
-
const streamId = Number(payload.streamId);
|
|
191
|
-
if (!Number.isFinite(streamId)) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const media = kind === 'transport.remote.request_audio' ? 'audio' : 'video';
|
|
195
|
-
this.noteIncomingConnection(payload);
|
|
196
|
-
this.maybeAutoStartStreamFromRemoteDemand(streamId, media, payload);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
snapshotPendingConnectionSummary() {
|
|
200
|
-
return {
|
|
201
|
-
state: this.state.connection.state,
|
|
202
|
-
direction: this.state.connection.direction,
|
|
203
|
-
peerId: this.state.connection.peerId,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
noteIncomingConnection(payload) {
|
|
207
|
-
if (this.state.connection.state === 'connected') {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
this.state.connection = {
|
|
211
|
-
state: 'connected',
|
|
212
|
-
direction: 'incoming',
|
|
213
|
-
peerId: typeof payload.peerId === 'string' && payload.peerId.length > 0 ? payload.peerId : undefined,
|
|
214
|
-
connectedAt: new Date().toISOString(),
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
handleIncomingConnectionDisconnected(payload) {
|
|
218
|
-
if (this.state.connection.state === 'idle' || this.state.connection.state === 'disconnected') {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
this.commandCoordinator.clearPendingRemoteCommands('connection_disconnect');
|
|
222
|
-
const disconnectedAt = new Date().toISOString();
|
|
223
|
-
this.state.connection = {
|
|
224
|
-
state: 'disconnected',
|
|
225
|
-
direction: 'incoming',
|
|
226
|
-
peerId: this.state.connection.peerId,
|
|
227
|
-
connectedAt: this.state.connection.connectedAt,
|
|
228
|
-
disconnectedAt,
|
|
229
|
-
reasonCode: typeof payload.reasonCode === 'string' && payload.reasonCode.length > 0
|
|
230
|
-
? payload.reasonCode
|
|
231
|
-
: undefined,
|
|
232
|
-
};
|
|
233
|
-
for (const stream of this.state.streams.values()) {
|
|
234
|
-
if (stream.direction !== 'send') {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (stream.state !== 'active') {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
stream.state = 'pending_on_connection';
|
|
241
|
-
stream.updatedAt = disconnectedAt;
|
|
242
|
-
this.writeEvent('stream', 'state.pending_on_reconnect', {
|
|
243
|
-
streamId: stream.streamId,
|
|
244
|
-
media: stream.media,
|
|
245
|
-
direction: stream.direction,
|
|
246
|
-
at: disconnectedAt,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
maybeAutoStartStreamFromRemoteDemand(streamId, media, payload) {
|
|
251
|
-
const key = streamBindingKey(streamId, media);
|
|
252
|
-
const bound = this.state.streamSourceBindings.get(key);
|
|
253
|
-
if (!bound) {
|
|
254
|
-
this.writeEvent('stream', 'send.auto.skipped', {
|
|
255
|
-
reason: 'source_not_bound',
|
|
256
|
-
streamId,
|
|
257
|
-
media,
|
|
258
|
-
at: new Date().toISOString(),
|
|
259
|
-
});
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const existing = this.state.streams.get(streamId);
|
|
263
|
-
if (existing && existing.direction === 'send' && existing.state === 'active') {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const stream = {
|
|
267
|
-
streamId,
|
|
268
|
-
media,
|
|
269
|
-
direction: 'send',
|
|
270
|
-
state: this.state.connection.state === 'connected' ? 'active' : 'pending_on_connection',
|
|
271
|
-
source: bound.source,
|
|
272
|
-
updatedAt: new Date().toISOString(),
|
|
273
|
-
};
|
|
274
|
-
this.state.streams.set(streamId, stream);
|
|
275
|
-
this.writeEvent('stream', 'send.auto.started', {
|
|
276
|
-
streamId,
|
|
277
|
-
media,
|
|
278
|
-
sourceMode: bound.source.mode,
|
|
279
|
-
assetsDir: bound.source.local_assets.assets_dir,
|
|
280
|
-
trigger: payload.kind ?? 'remote_request',
|
|
281
|
-
at: new Date().toISOString(),
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
async dispatch(method, params) {
|
|
285
|
-
if (method === 'initialize') {
|
|
286
|
-
return this.handleInitialize();
|
|
287
|
-
}
|
|
288
|
-
if (!this.isInitialized) {
|
|
289
|
-
throw new HostProtocol_1.HostProtocolError('not_initialized', 'Initialize has not been called', false);
|
|
290
|
-
}
|
|
291
|
-
switch (method) {
|
|
292
|
-
case 'host/status':
|
|
293
|
-
return this.handleHostStatus();
|
|
294
|
-
case 'host/shutdown':
|
|
295
|
-
return this.handleHostShutdown();
|
|
296
|
-
case 'service/start':
|
|
297
|
-
return this.handleServiceStart((0, HostProtocol_1.parseServiceStartParams)(params));
|
|
298
|
-
case 'service/stop':
|
|
299
|
-
return this.handleServiceStop();
|
|
300
|
-
case 'connection/get':
|
|
301
|
-
return this.handleConnectionGet();
|
|
302
|
-
case 'connection/connect':
|
|
303
|
-
return this.handleConnectionConnect((0, HostProtocol_1.parseConnectionConnectParams)(params));
|
|
304
|
-
case 'connection/disconnect':
|
|
305
|
-
return this.handleConnectionDisconnect();
|
|
306
|
-
case 'stream/list':
|
|
307
|
-
return this.handleStreamList();
|
|
308
|
-
case 'stream/sendStart':
|
|
309
|
-
return this.handleStreamSendStart((0, HostProtocol_1.parseStreamSendStartParams)(params));
|
|
310
|
-
case 'stream/sendStop':
|
|
311
|
-
return this.handleStreamSendStop((0, HostProtocol_1.parseStreamStopParams)(params));
|
|
312
|
-
case 'stream/message/send':
|
|
313
|
-
return this.handleStreamMessageSend((0, HostProtocol_1.parseStreamMessageSendParams)(params));
|
|
314
|
-
case 'stream/receiveStart':
|
|
315
|
-
return this.handleStreamReceiveStart((0, HostProtocol_1.parseStreamReceiveStartParams)(params));
|
|
316
|
-
case 'stream/receiveStop':
|
|
317
|
-
return this.handleStreamReceiveStop((0, HostProtocol_1.parseStreamStopParams)(params));
|
|
318
|
-
case 'output/attach':
|
|
319
|
-
return this.handleOutputAttach((0, HostProtocol_1.parseOutputAttachParams)(params));
|
|
320
|
-
case 'output/detach':
|
|
321
|
-
return this.handleOutputDetach((0, HostProtocol_1.parseOutputDetachParams)(params));
|
|
322
|
-
case 'command/request':
|
|
323
|
-
case 'command/send':
|
|
324
|
-
return this.handleCommandSend((0, HostProtocol_1.parseCommandSendParams)(params));
|
|
325
|
-
case 'command/reply':
|
|
326
|
-
return this.handleCommandReply((0, HostProtocol_1.parseCommandReplyParams)(params));
|
|
327
|
-
case 'command/pending/list':
|
|
328
|
-
return this.handleCommandPendingList();
|
|
329
|
-
case 'events/subscribe':
|
|
330
|
-
return this.handleEventsSubscribe((0, HostProtocol_1.parseEventsSubscribeParams)(params));
|
|
331
|
-
case 'artifact/readReport':
|
|
332
|
-
return this.handleArtifactReadReport();
|
|
333
|
-
case 'artifact/exportLogs':
|
|
334
|
-
return this.handleArtifactExportLogs((0, HostProtocol_1.parseArtifactExportParams)(params));
|
|
335
|
-
case 'artifact/exportReport':
|
|
336
|
-
return this.handleArtifactExportReport((0, HostProtocol_1.parseArtifactExportParams)(params));
|
|
337
|
-
case 'debug/token/qrcode':
|
|
338
|
-
return this.handleDebugTokenQrcode((0, HostProtocol_1.parseDebugTokenQrcodeParams)(params));
|
|
339
|
-
default:
|
|
340
|
-
throw new HostProtocol_1.HostProtocolError('method_not_found', `Method ${method} not found`, false);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
async handleInitialize() {
|
|
344
|
-
return {
|
|
345
|
-
serverInfo: {
|
|
346
|
-
name: 'TiRTC App Server Host',
|
|
347
|
-
version: this.state.serverVersion,
|
|
348
|
-
},
|
|
349
|
-
protocolVersion: this.state.protocolVersion,
|
|
350
|
-
runtimeTarget: this.state.runtimeTarget,
|
|
351
|
-
hostEndpoint: this.state.hostEndpoint,
|
|
352
|
-
capabilities: {},
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
async handleHostStatus() {
|
|
356
|
-
return {
|
|
357
|
-
hostEndpoint: this.state.hostEndpoint,
|
|
358
|
-
serverVersion: this.state.serverVersion,
|
|
359
|
-
protocolVersion: this.state.protocolVersion,
|
|
360
|
-
runtimeTarget: this.state.runtimeTarget,
|
|
361
|
-
startedAt: this.state.startedAt,
|
|
362
|
-
service: this.state.service,
|
|
363
|
-
connection: this.state.connection,
|
|
364
|
-
artifactPaths: this.artifactManager.getPaths(),
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
async handleHostShutdown() {
|
|
368
|
-
this.commandCoordinator.clearPendingRemoteCommands('host_shutdown');
|
|
369
|
-
return {
|
|
370
|
-
acceptedAt: new Date().toISOString(),
|
|
371
|
-
service: this.state.service,
|
|
372
|
-
connection: this.state.connection,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
async handleServiceStart(params) {
|
|
376
|
-
if (this.state.service.state !== 'stopped') {
|
|
377
|
-
throw new HostProtocol_1.HostProtocolError('busy', 'Service is not stopped', false);
|
|
378
|
-
}
|
|
379
|
-
if (this.state.connection.state !== 'idle' &&
|
|
380
|
-
this.state.connection.state !== 'disconnected' &&
|
|
381
|
-
this.state.connection.state !== 'failed') {
|
|
382
|
-
throw new HostProtocol_1.HostProtocolError('busy', 'Connection is not idle', false);
|
|
383
|
-
}
|
|
384
|
-
const resolvedServiceEntry = await this.runtimeAdapter.startService(params.serviceEntry, params.license, params.timeoutMs);
|
|
385
|
-
this.state.service = {
|
|
386
|
-
state: 'waiting_peer',
|
|
387
|
-
serviceEntry: resolvedServiceEntry,
|
|
388
|
-
startedAt: new Date().toISOString(),
|
|
389
|
-
};
|
|
390
|
-
if (params.bootstrapSendStreams && params.bootstrapSendStreams.length > 0) {
|
|
391
|
-
const bootstrapStreams = params.bootstrapSendStreams.map((streamParams) => ({
|
|
392
|
-
streamId: streamParams.streamId,
|
|
393
|
-
media: streamParams.media,
|
|
394
|
-
source: streamParams.source,
|
|
395
|
-
}));
|
|
396
|
-
const sendResults = this.runtimeAdapter.startSendStreams
|
|
397
|
-
? await this.runtimeAdapter.startSendStreams(bootstrapStreams)
|
|
398
|
-
: await Promise.all(bootstrapStreams.map(async (streamParams) => await this.runtimeAdapter.startSendStream(streamParams.streamId, streamParams.media, streamParams.source)));
|
|
399
|
-
const updatedAt = new Date().toISOString();
|
|
400
|
-
bootstrapStreams.forEach((streamParams, index) => {
|
|
401
|
-
const stream = {
|
|
402
|
-
streamId: streamParams.streamId,
|
|
403
|
-
media: streamParams.media,
|
|
404
|
-
direction: 'send',
|
|
405
|
-
state: this.state.connection.state === 'connected' ? 'active' : 'pending_on_connection',
|
|
406
|
-
source: streamParams.source,
|
|
407
|
-
updatedAt,
|
|
408
|
-
};
|
|
409
|
-
this.state.streams.set(streamParams.streamId, stream);
|
|
410
|
-
this.state.streamSourceBindings.set(streamBindingKey(streamParams.streamId, streamParams.media), {
|
|
411
|
-
streamId: streamParams.streamId,
|
|
412
|
-
media: streamParams.media,
|
|
413
|
-
source: streamParams.source,
|
|
414
|
-
updatedAt,
|
|
415
|
-
});
|
|
416
|
-
this.writeEvent('stream', 'send.bootstrap.bound', {
|
|
417
|
-
streamId: streamParams.streamId,
|
|
418
|
-
media: streamParams.media,
|
|
419
|
-
sourceMode: streamParams.source.mode,
|
|
420
|
-
assetsDir: streamParams.source.local_assets.assets_dir,
|
|
421
|
-
autoStarted: sendResults[index]?.autoStarted ?? false,
|
|
422
|
-
workerPid: sendResults[index]?.workerPid,
|
|
423
|
-
state: stream.state,
|
|
424
|
-
at: updatedAt,
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return this.state.service;
|
|
429
|
-
}
|
|
430
|
-
async handleServiceStop() {
|
|
431
|
-
if (this.state.service.state === 'stopped') {
|
|
432
|
-
return {
|
|
433
|
-
acceptedAt: new Date().toISOString(),
|
|
434
|
-
service: this.state.service,
|
|
435
|
-
connection: this.state.connection,
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
await this.runtimeAdapter.stopService();
|
|
439
|
-
this.commandCoordinator.clearPendingRemoteCommands('service_stop');
|
|
440
|
-
this.state.service.state = 'stopped';
|
|
441
|
-
this.state.service.stoppedAt = new Date().toISOString();
|
|
442
|
-
return {
|
|
443
|
-
acceptedAt: new Date().toISOString(),
|
|
444
|
-
service: this.state.service,
|
|
445
|
-
connection: this.state.connection,
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
async handleConnectionGet() {
|
|
449
|
-
return this.state.connection;
|
|
450
|
-
}
|
|
451
|
-
async handleConnectionConnect(params) {
|
|
452
|
-
if (this.state.connection.state !== "idle" &&
|
|
453
|
-
this.state.connection.state !== "disconnected" &&
|
|
454
|
-
this.state.connection.state !== "failed") {
|
|
455
|
-
throw new HostProtocol_1.HostProtocolError("busy", "Connection is not idle", false);
|
|
456
|
-
}
|
|
457
|
-
if (this.state.service.state !== "stopped") {
|
|
458
|
-
throw new HostProtocol_1.HostProtocolError("busy", "Service is not stopped", false);
|
|
459
|
-
}
|
|
460
|
-
this.writeEvent("connection", "token.prepared", {
|
|
461
|
-
mode: 'manual',
|
|
462
|
-
peerId: params.peerId,
|
|
463
|
-
tokenLength: params.token.length,
|
|
464
|
-
at: new Date().toISOString(),
|
|
465
|
-
});
|
|
466
|
-
const resolvedServiceEntry = await this.runtimeAdapter.connect(params.serviceEntry, params.peerId, params.token, params.timeoutMs);
|
|
467
|
-
this.state.connection = {
|
|
468
|
-
state: 'connecting',
|
|
469
|
-
direction: 'outgoing',
|
|
470
|
-
peerId: params.peerId,
|
|
471
|
-
};
|
|
472
|
-
if (this.state.service.state === 'stopped') {
|
|
473
|
-
this.state.service.serviceEntry = resolvedServiceEntry;
|
|
474
|
-
}
|
|
475
|
-
this.state.connection.state = 'connected';
|
|
476
|
-
this.state.connection.connectedAt = new Date().toISOString();
|
|
477
|
-
await this.startDeferredSendStreamsOnConnected();
|
|
478
|
-
this.activatePendingStreamsOnConnected();
|
|
479
|
-
return this.state.connection;
|
|
480
|
-
}
|
|
481
|
-
async startDeferredSendStreamsOnConnected() {
|
|
482
|
-
if (this.state.service.state === 'stopped') {
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
const now = new Date().toISOString();
|
|
486
|
-
for (const stream of this.state.streams.values()) {
|
|
487
|
-
if (stream.direction !== 'send' || stream.state !== 'pending_on_connection' || !stream.source) {
|
|
488
|
-
continue;
|
|
489
|
-
}
|
|
490
|
-
try {
|
|
491
|
-
const sendResult = await this.runtimeAdapter.startSendStream(stream.streamId, stream.media, stream.source);
|
|
492
|
-
this.writeEvent('stream', 'send.deferred.started_on_connection', {
|
|
493
|
-
streamId: stream.streamId,
|
|
494
|
-
media: stream.media,
|
|
495
|
-
sourceMode: stream.source.mode,
|
|
496
|
-
assetsDir: stream.source.local_assets.assets_dir,
|
|
497
|
-
autoStarted: sendResult.autoStarted,
|
|
498
|
-
workerPid: sendResult.workerPid,
|
|
499
|
-
at: now,
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
catch (error) {
|
|
503
|
-
stream.state = 'failed';
|
|
504
|
-
stream.updatedAt = now;
|
|
505
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
506
|
-
this.writeEvent('stream', 'send.deferred.failed_on_connection', {
|
|
507
|
-
streamId: stream.streamId,
|
|
508
|
-
media: stream.media,
|
|
509
|
-
sourceMode: stream.source.mode,
|
|
510
|
-
assetsDir: stream.source.local_assets.assets_dir,
|
|
511
|
-
message,
|
|
512
|
-
at: now,
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
activatePendingStreamsOnConnected() {
|
|
518
|
-
const now = new Date().toISOString();
|
|
519
|
-
for (const stream of this.state.streams.values()) {
|
|
520
|
-
if (stream.state !== 'pending_on_connection') {
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
stream.state = 'active';
|
|
524
|
-
stream.updatedAt = now;
|
|
525
|
-
this.writeEvent('stream', 'state.activated_on_connection', {
|
|
526
|
-
streamId: stream.streamId,
|
|
527
|
-
media: stream.media,
|
|
528
|
-
direction: stream.direction,
|
|
529
|
-
at: now,
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
async handleConnectionDisconnect() {
|
|
534
|
-
if (this.state.connection.state === 'idle' || this.state.connection.state === 'disconnected') {
|
|
535
|
-
return {
|
|
536
|
-
acceptedAt: new Date().toISOString(),
|
|
537
|
-
service: this.state.service,
|
|
538
|
-
connection: this.state.connection,
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
await this.runtimeAdapter.disconnect();
|
|
542
|
-
this.commandCoordinator.clearPendingRemoteCommands('connection_disconnect');
|
|
543
|
-
this.state.connection.state = 'disconnected';
|
|
544
|
-
this.state.connection.disconnectedAt = new Date().toISOString();
|
|
545
|
-
return {
|
|
546
|
-
acceptedAt: new Date().toISOString(),
|
|
547
|
-
service: this.state.service,
|
|
548
|
-
connection: this.state.connection,
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
async handleStreamList() {
|
|
552
|
-
return {
|
|
553
|
-
streams: Array.from(this.state.streams.values()),
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
async handleStreamSendStart(params) {
|
|
557
|
-
resolveLocalAssetsDir(params.source);
|
|
558
|
-
const hasActiveService = this.state.service.state !== 'stopped';
|
|
559
|
-
if (hasActiveService) {
|
|
560
|
-
await this.runtimeAdapter.startSendStream(params.streamId, params.media, params.source);
|
|
561
|
-
}
|
|
562
|
-
const stream = {
|
|
563
|
-
streamId: params.streamId,
|
|
564
|
-
media: params.media,
|
|
565
|
-
direction: 'send',
|
|
566
|
-
state: this.state.connection.state === 'connected' ? 'active' : 'pending_on_connection',
|
|
567
|
-
source: params.source,
|
|
568
|
-
updatedAt: new Date().toISOString(),
|
|
569
|
-
};
|
|
570
|
-
this.state.streams.set(params.streamId, stream);
|
|
571
|
-
this.state.streamSourceBindings.set(streamBindingKey(params.streamId, params.media), {
|
|
572
|
-
streamId: params.streamId,
|
|
573
|
-
media: params.media,
|
|
574
|
-
source: params.source,
|
|
575
|
-
updatedAt: new Date().toISOString(),
|
|
576
|
-
});
|
|
577
|
-
return stream;
|
|
578
|
-
}
|
|
579
|
-
async handleStreamSendStop(params) {
|
|
580
|
-
const stream = this.state.streams.get(params.streamId);
|
|
581
|
-
if (!stream || stream.direction !== 'send') {
|
|
582
|
-
throw new HostProtocol_1.HostProtocolError('stream_not_found', `Stream ${params.streamId} not found or not a send stream`, false);
|
|
583
|
-
}
|
|
584
|
-
await this.runtimeAdapter.stopSendStream(params.streamId);
|
|
585
|
-
stream.state = 'stopped';
|
|
586
|
-
stream.updatedAt = new Date().toISOString();
|
|
587
|
-
return stream;
|
|
588
|
-
}
|
|
589
|
-
async handleStreamMessageSend(params) {
|
|
590
|
-
const acceptedAt = new Date().toISOString();
|
|
591
|
-
this.writeEvent('stream', 'message.send.requested', {
|
|
592
|
-
streamId: params.streamId,
|
|
593
|
-
payloadPreview: params.payload.slice(0, 120),
|
|
594
|
-
payloadLength: params.payload.length,
|
|
595
|
-
at: acceptedAt,
|
|
596
|
-
});
|
|
597
|
-
try {
|
|
598
|
-
await this.runtimeAdapter.sendStreamMessage(params.streamId, params.payload);
|
|
599
|
-
}
|
|
600
|
-
catch (error) {
|
|
601
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
602
|
-
this.writeEvent('stream', 'message.send.failed', {
|
|
603
|
-
streamId: params.streamId,
|
|
604
|
-
payloadPreview: params.payload.slice(0, 120),
|
|
605
|
-
payloadLength: params.payload.length,
|
|
606
|
-
message,
|
|
607
|
-
at: new Date().toISOString(),
|
|
608
|
-
});
|
|
609
|
-
throw error;
|
|
610
|
-
}
|
|
611
|
-
this.writeEvent('stream', 'message.send.completed', {
|
|
612
|
-
streamId: params.streamId,
|
|
613
|
-
payloadPreview: params.payload.slice(0, 120),
|
|
614
|
-
payloadLength: params.payload.length,
|
|
615
|
-
at: new Date().toISOString(),
|
|
616
|
-
});
|
|
617
|
-
return {
|
|
618
|
-
streamId: params.streamId,
|
|
619
|
-
payloadLength: params.payload.length,
|
|
620
|
-
acceptedAt,
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
async handleStreamReceiveStart(params) {
|
|
624
|
-
await this.runtimeAdapter.startReceiveStream(params.streamId, params.media);
|
|
625
|
-
const stream = {
|
|
626
|
-
streamId: params.streamId,
|
|
627
|
-
media: params.media,
|
|
628
|
-
direction: 'receive',
|
|
629
|
-
state: this.state.connection.state === 'connected' ? 'active' : 'pending_on_connection',
|
|
630
|
-
updatedAt: new Date().toISOString(),
|
|
631
|
-
};
|
|
632
|
-
this.state.streams.set(params.streamId, stream);
|
|
633
|
-
return stream;
|
|
634
|
-
}
|
|
635
|
-
async handleStreamReceiveStop(params) {
|
|
636
|
-
const stream = this.state.streams.get(params.streamId);
|
|
637
|
-
if (!stream || stream.direction !== 'receive') {
|
|
638
|
-
throw new HostProtocol_1.HostProtocolError('stream_not_found', `Stream ${params.streamId} not found or not a receive stream`, false);
|
|
639
|
-
}
|
|
640
|
-
await this.runtimeAdapter.stopReceiveStream(params.streamId);
|
|
641
|
-
stream.state = 'stopped';
|
|
642
|
-
stream.updatedAt = new Date().toISOString();
|
|
643
|
-
return stream;
|
|
644
|
-
}
|
|
645
|
-
async handleOutputAttach(params) {
|
|
646
|
-
const attachment = await this.runtimeAdapter.attachOutput(params.streamId, params.consumer, params.mediaView, params.format, params.delivery, params.targetPath, params.maxFiles);
|
|
647
|
-
return {
|
|
648
|
-
outputId: attachment.outputId,
|
|
649
|
-
streamId: params.streamId,
|
|
650
|
-
consumer: params.consumer,
|
|
651
|
-
mediaView: params.mediaView,
|
|
652
|
-
format: params.format,
|
|
653
|
-
delivery: params.delivery,
|
|
654
|
-
target: attachment.targetPath,
|
|
655
|
-
attachedAt: attachment.attachedAt,
|
|
656
|
-
preview: attachment.preview,
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
async handleOutputDetach(params) {
|
|
660
|
-
await this.runtimeAdapter.detachOutput(params.outputId);
|
|
661
|
-
return {
|
|
662
|
-
outputId: params.outputId,
|
|
663
|
-
detachedAt: new Date().toISOString(),
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
async handleCommandSend(params) {
|
|
667
|
-
const result = await this.commandCoordinator.handleCommandSend(params, this.commandSequence);
|
|
668
|
-
this.commandSequence += 1;
|
|
669
|
-
return result;
|
|
670
|
-
}
|
|
671
|
-
async handleCommandReply(params) {
|
|
672
|
-
return this.commandCoordinator.handleCommandReply(params);
|
|
673
|
-
}
|
|
674
|
-
async handleCommandPendingList() {
|
|
675
|
-
return this.commandCoordinator.handleCommandPendingList();
|
|
676
|
-
}
|
|
677
|
-
async handleEventsSubscribe(params) {
|
|
678
|
-
const families = params.families ?? [];
|
|
679
|
-
for (const family of families) {
|
|
680
|
-
this.state.subscriptions.add(family);
|
|
681
|
-
}
|
|
682
|
-
this.appendHostLog('events subscribed: ' + (families.length > 0 ? families.join(',') : '(none)'));
|
|
683
|
-
return {
|
|
684
|
-
families,
|
|
685
|
-
subscribedAt: new Date().toISOString(),
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
async handleArtifactReadReport() {
|
|
689
|
-
const report = {
|
|
690
|
-
status: 'completed',
|
|
691
|
-
reasonCode: 'success',
|
|
692
|
-
summary: 'Report summary runtime-backed contract',
|
|
693
|
-
service: this.state.service,
|
|
694
|
-
connection: this.state.connection,
|
|
695
|
-
streams: Array.from(this.state.streams.values()),
|
|
696
|
-
artifacts: this.artifactManager.getPaths(),
|
|
697
|
-
lastError: this.state.lastError,
|
|
698
|
-
};
|
|
699
|
-
this.artifactManager.writeReport(report);
|
|
700
|
-
return report;
|
|
701
|
-
}
|
|
702
|
-
async handleArtifactExportLogs(params) {
|
|
703
|
-
return {
|
|
704
|
-
outputPath: params.outputPath,
|
|
705
|
-
exportedAt: new Date().toISOString(),
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
async handleArtifactExportReport(params) {
|
|
709
|
-
return {
|
|
710
|
-
outputPath: params.outputPath,
|
|
711
|
-
exportedAt: new Date().toISOString(),
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
async handleDebugTokenQrcode(params) {
|
|
715
|
-
const qr = await this.tokenTool.generateQrcode({
|
|
716
|
-
payload: params.payload,
|
|
717
|
-
outputStem: params.outputStem,
|
|
718
|
-
});
|
|
719
|
-
return {
|
|
720
|
-
payload: qr.payload,
|
|
721
|
-
qrAsciiPath: qr.asciiPath,
|
|
722
|
-
qrPngPath: qr.pngPath,
|
|
723
|
-
generatedAt: new Date().toISOString(),
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
exports.HostServer = HostServer;
|