MCPcopy Index your code
hub / github.com/callstack/agent-device / resolveRuntimeTransportHints

Function resolveRuntimeTransportHints

src/utils/runtime-transport.ts:11–43  ·  view source on GitHub ↗
(
  runtime: SessionRuntimeHints | undefined,
)

Source from the content-addressed store, hash-verified

9};
10
11export function resolveRuntimeTransportHints(
12 runtime: SessionRuntimeHints | undefined,
13): ResolvedRuntimeTransport | undefined {
14 if (!runtime) return undefined;
15
16 let host = trimRuntimeValue(runtime.metroHost);
17 let port = normalizePort(runtime.metroPort);
18 let scheme: 'http' | 'https' = 'http';
19 const bundleUrl = trimRuntimeValue(runtime.bundleUrl);
20 if (bundleUrl) {
21 let parsed: URL;
22 try {
23 parsed = new URL(bundleUrl);
24 } catch (error) {
25 throw new AppError(
26 'INVALID_ARGS',
27 `Invalid runtime bundle URL: ${bundleUrl}`,
28 {},
29 error as Error,
30 );
31 }
32 if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
33 host ??= trimRuntimeValue(parsed.hostname);
34 port ??= normalizePort(
35 parsed.port.length > 0 ? Number(parsed.port) : defaultPortForProtocol(parsed.protocol),
36 );
37 scheme = parsed.protocol === 'https:' ? 'https' : 'http';
38 }
39 }
40
41 if (!host || !port) return undefined;
42 return { host, port, scheme };
43}
44
45export function trimRuntimeValue(value: string | undefined): string | undefined {
46 const trimmed = value?.trim();

Callers 5

resolveMetroReloadUrlFunction · 0.90
resolveRuntimeTransportFunction · 0.90
hasRuntimeTransportHintsFunction · 0.90
applyRuntimeHintsToAppFunction · 0.90

Calls 3

trimRuntimeValueFunction · 0.85
normalizePortFunction · 0.85
defaultPortForProtocolFunction · 0.85

Tested by

no test coverage detected