@openclaw/voice-call 2026.5.2 → 2026.5.3-beta.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/dist/api.js +2 -0
- package/dist/call-status-CXldV5o8.js +32 -0
- package/dist/cli-metadata.js +12 -0
- package/dist/config-7w04YpHh.js +548 -0
- package/dist/config-compat-B0me39_4.js +129 -0
- package/dist/guarded-json-api-Btx5EE4w.js +591 -0
- package/dist/http-headers-BrnxBasF.js +10 -0
- package/dist/index.js +1284 -0
- package/dist/mock-CeKvfVEd.js +135 -0
- package/dist/plivo-B-a7KFoT.js +393 -0
- package/dist/realtime-handler-B63CIDP2.js +325 -0
- package/dist/realtime-transcription.runtime-B2h70y2W.js +2 -0
- package/dist/realtime-voice.runtime-Bkh4nvLn.js +2 -0
- package/dist/response-generator-BrcmwDZU.js +182 -0
- package/dist/response-model-CyF5K80p.js +12 -0
- package/dist/runtime-api.js +6 -0
- package/dist/runtime-entry-88ytYAQa.js +3119 -0
- package/dist/runtime-entry.js +2 -0
- package/dist/setup-api.js +37 -0
- package/dist/telnyx-jjBE8boz.js +260 -0
- package/dist/twilio-1OqbcXLL.js +676 -0
- package/dist/voice-mapping-BYDGdWGx.js +40 -0
- package/package.json +14 -6
- package/api.ts +0 -16
- package/cli-metadata.ts +0 -10
- package/config-api.ts +0 -12
- package/index.test.ts +0 -943
- package/index.ts +0 -794
- package/runtime-api.ts +0 -20
- package/runtime-entry.ts +0 -1
- package/setup-api.ts +0 -47
- package/src/allowlist.test.ts +0 -18
- package/src/allowlist.ts +0 -19
- package/src/cli.ts +0 -845
- package/src/config-compat.test.ts +0 -120
- package/src/config-compat.ts +0 -227
- package/src/config.test.ts +0 -479
- package/src/config.ts +0 -808
- package/src/core-bridge.ts +0 -14
- package/src/deep-merge.test.ts +0 -40
- package/src/deep-merge.ts +0 -23
- package/src/gateway-continue-operation.ts +0 -200
- package/src/http-headers.test.ts +0 -16
- package/src/http-headers.ts +0 -15
- package/src/manager/context.ts +0 -42
- package/src/manager/events.test.ts +0 -581
- package/src/manager/events.ts +0 -288
- package/src/manager/lifecycle.ts +0 -53
- package/src/manager/lookup.test.ts +0 -52
- package/src/manager/lookup.ts +0 -35
- package/src/manager/outbound.test.ts +0 -528
- package/src/manager/outbound.ts +0 -486
- package/src/manager/state.ts +0 -48
- package/src/manager/store.ts +0 -106
- package/src/manager/timers.test.ts +0 -129
- package/src/manager/timers.ts +0 -113
- package/src/manager/twiml.test.ts +0 -13
- package/src/manager/twiml.ts +0 -17
- package/src/manager.closed-loop.test.ts +0 -236
- package/src/manager.inbound-allowlist.test.ts +0 -188
- package/src/manager.notify.test.ts +0 -377
- package/src/manager.restore.test.ts +0 -183
- package/src/manager.test-harness.ts +0 -127
- package/src/manager.ts +0 -392
- package/src/media-stream.test.ts +0 -768
- package/src/media-stream.ts +0 -708
- package/src/providers/base.ts +0 -97
- package/src/providers/mock.test.ts +0 -78
- package/src/providers/mock.ts +0 -185
- package/src/providers/plivo.test.ts +0 -93
- package/src/providers/plivo.ts +0 -601
- package/src/providers/shared/call-status.test.ts +0 -24
- package/src/providers/shared/call-status.ts +0 -24
- package/src/providers/shared/guarded-json-api.test.ts +0 -106
- package/src/providers/shared/guarded-json-api.ts +0 -42
- package/src/providers/telnyx.test.ts +0 -340
- package/src/providers/telnyx.ts +0 -394
- package/src/providers/twilio/api.test.ts +0 -145
- package/src/providers/twilio/api.ts +0 -93
- package/src/providers/twilio/twiml-policy.test.ts +0 -84
- package/src/providers/twilio/twiml-policy.ts +0 -87
- package/src/providers/twilio/webhook.ts +0 -34
- package/src/providers/twilio.test.ts +0 -591
- package/src/providers/twilio.ts +0 -861
- package/src/providers/twilio.types.ts +0 -17
- package/src/realtime-defaults.ts +0 -3
- package/src/realtime-fast-context.test.ts +0 -88
- package/src/realtime-fast-context.ts +0 -165
- package/src/realtime-transcription.runtime.ts +0 -4
- package/src/realtime-voice.runtime.ts +0 -5
- package/src/response-generator.test.ts +0 -321
- package/src/response-generator.ts +0 -318
- package/src/response-model.test.ts +0 -71
- package/src/response-model.ts +0 -23
- package/src/runtime.test.ts +0 -536
- package/src/runtime.ts +0 -510
- package/src/telephony-audio.test.ts +0 -61
- package/src/telephony-audio.ts +0 -12
- package/src/telephony-tts.test.ts +0 -196
- package/src/telephony-tts.ts +0 -235
- package/src/test-fixtures.ts +0 -73
- package/src/tts-provider-voice.test.ts +0 -34
- package/src/tts-provider-voice.ts +0 -21
- package/src/tunnel.test.ts +0 -166
- package/src/tunnel.ts +0 -314
- package/src/types.ts +0 -291
- package/src/utils.test.ts +0 -17
- package/src/utils.ts +0 -14
- package/src/voice-mapping.test.ts +0 -34
- package/src/voice-mapping.ts +0 -68
- package/src/webhook/realtime-handler.test.ts +0 -598
- package/src/webhook/realtime-handler.ts +0 -485
- package/src/webhook/stale-call-reaper.test.ts +0 -88
- package/src/webhook/stale-call-reaper.ts +0 -38
- package/src/webhook/tailscale.test.ts +0 -214
- package/src/webhook/tailscale.ts +0 -129
- package/src/webhook-exposure.test.ts +0 -33
- package/src/webhook-exposure.ts +0 -84
- package/src/webhook-security.test.ts +0 -770
- package/src/webhook-security.ts +0 -994
- package/src/webhook.hangup-once.lifecycle.test.ts +0 -135
- package/src/webhook.test.ts +0 -1470
- package/src/webhook.ts +0 -908
- package/src/webhook.types.ts +0 -5
- package/src/websocket-test-support.ts +0 -72
- package/tsconfig.json +0 -16
package/src/tunnel.test.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
class FakeChildProcess extends EventEmitter {
|
|
5
|
-
readonly stdout = new EventEmitter();
|
|
6
|
-
readonly stderr = new EventEmitter();
|
|
7
|
-
killedWith: NodeJS.Signals | null = null;
|
|
8
|
-
|
|
9
|
-
kill(signal: NodeJS.Signals = "SIGTERM"): boolean {
|
|
10
|
-
this.killedWith = signal;
|
|
11
|
-
queueMicrotask(() => this.emit("close", null));
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
close(code: number | null = 0): void {
|
|
16
|
-
this.emit("close", code);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
fail(error: Error): void {
|
|
20
|
-
this.emit("error", error);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const mocks = vi.hoisted(() => ({
|
|
25
|
-
spawn: vi.fn(),
|
|
26
|
-
getTailscaleDnsName: vi.fn(),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
vi.mock("node:child_process", () => ({
|
|
30
|
-
spawn: mocks.spawn,
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
vi.mock("./webhook/tailscale.js", () => ({
|
|
34
|
-
getTailscaleDnsName: mocks.getTailscaleDnsName,
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
import { isNgrokAvailable, startNgrokTunnel, startTailscaleTunnel, startTunnel } from "./tunnel.js";
|
|
38
|
-
|
|
39
|
-
function nextProcess(): FakeChildProcess {
|
|
40
|
-
const proc = new FakeChildProcess();
|
|
41
|
-
mocks.spawn.mockReturnValueOnce(proc as never);
|
|
42
|
-
return proc;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function emitNgrokUrl(proc: FakeChildProcess, url: string): void {
|
|
46
|
-
proc.stdout.emit("data", Buffer.from(`${JSON.stringify({ msg: "started tunnel", url })}\n`));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe("voice-call tunnels", () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
vi.clearAllMocks();
|
|
52
|
-
mocks.getTailscaleDnsName.mockReset();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("checks ngrok availability from the version command exit code", async () => {
|
|
56
|
-
const proc = nextProcess();
|
|
57
|
-
const result = isNgrokAvailable();
|
|
58
|
-
proc.close(0);
|
|
59
|
-
|
|
60
|
-
await expect(result).resolves.toBe(true);
|
|
61
|
-
expect(mocks.spawn).toHaveBeenCalledWith("ngrok", ["version"], expect.any(Object));
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("treats ngrok spawn failures as unavailable", async () => {
|
|
65
|
-
const proc = nextProcess();
|
|
66
|
-
const result = isNgrokAvailable();
|
|
67
|
-
proc.fail(new Error("spawn ngrok ENOENT"));
|
|
68
|
-
|
|
69
|
-
await expect(result).resolves.toBe(false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("starts ngrok and appends the webhook path to the public URL", async () => {
|
|
73
|
-
const proc = nextProcess();
|
|
74
|
-
const result = startNgrokTunnel({ port: 3334, path: "/voice/webhook" });
|
|
75
|
-
|
|
76
|
-
emitNgrokUrl(proc, "https://abc.ngrok.io");
|
|
77
|
-
|
|
78
|
-
await expect(result).resolves.toMatchObject({
|
|
79
|
-
publicUrl: "https://abc.ngrok.io/voice/webhook",
|
|
80
|
-
provider: "ngrok",
|
|
81
|
-
});
|
|
82
|
-
expect(mocks.spawn).toHaveBeenCalledWith(
|
|
83
|
-
"ngrok",
|
|
84
|
-
expect.arrayContaining(["http", "3334"]),
|
|
85
|
-
expect.any(Object),
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("sets ngrok auth token before starting the tunnel", async () => {
|
|
90
|
-
const authProc = nextProcess();
|
|
91
|
-
const tunnelProc = nextProcess();
|
|
92
|
-
const result = startNgrokTunnel({
|
|
93
|
-
port: 3334,
|
|
94
|
-
path: "/hook",
|
|
95
|
-
authToken: "token",
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
authProc.close(0);
|
|
99
|
-
await vi.waitFor(() => expect(mocks.spawn).toHaveBeenCalledTimes(2));
|
|
100
|
-
emitNgrokUrl(tunnelProc, "https://auth.ngrok.io");
|
|
101
|
-
|
|
102
|
-
await expect(result).resolves.toMatchObject({
|
|
103
|
-
publicUrl: "https://auth.ngrok.io/hook",
|
|
104
|
-
});
|
|
105
|
-
expect(mocks.spawn).toHaveBeenNthCalledWith(
|
|
106
|
-
1,
|
|
107
|
-
"ngrok",
|
|
108
|
-
["config", "add-authtoken", "token"],
|
|
109
|
-
expect.any(Object),
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("rejects ngrok startup errors from stderr", async () => {
|
|
114
|
-
const proc = nextProcess();
|
|
115
|
-
const result = startNgrokTunnel({ port: 3334, path: "/hook" });
|
|
116
|
-
|
|
117
|
-
proc.stderr.emit("data", Buffer.from("ERR_NGROK_3200: invalid auth token"));
|
|
118
|
-
|
|
119
|
-
await expect(result).rejects.toThrow("ngrok error:");
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("starts Tailscale serve using the resolved tailnet DNS name", async () => {
|
|
123
|
-
mocks.getTailscaleDnsName.mockResolvedValue("host.tailnet.ts.net");
|
|
124
|
-
const proc = nextProcess();
|
|
125
|
-
const result = startTailscaleTunnel({
|
|
126
|
-
mode: "serve",
|
|
127
|
-
port: 3334,
|
|
128
|
-
path: "voice/webhook",
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
await vi.waitFor(() => expect(mocks.spawn).toHaveBeenCalled());
|
|
132
|
-
proc.close(0);
|
|
133
|
-
|
|
134
|
-
await expect(result).resolves.toMatchObject({
|
|
135
|
-
publicUrl: "https://host.tailnet.ts.net/voice/webhook",
|
|
136
|
-
provider: "tailscale-serve",
|
|
137
|
-
});
|
|
138
|
-
expect(mocks.spawn).toHaveBeenCalledWith(
|
|
139
|
-
"tailscale",
|
|
140
|
-
expect.arrayContaining(["serve", "--set-path", "/voice/webhook"]),
|
|
141
|
-
expect.any(Object),
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("rejects Tailscale tunnel startup when the DNS name is unavailable", async () => {
|
|
146
|
-
mocks.getTailscaleDnsName.mockResolvedValue(null);
|
|
147
|
-
|
|
148
|
-
await expect(
|
|
149
|
-
startTailscaleTunnel({ mode: "funnel", port: 3334, path: "/hook" }),
|
|
150
|
-
).rejects.toThrow("Could not get Tailscale DNS name");
|
|
151
|
-
expect(mocks.spawn).not.toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("dispatches tunnel providers from config", async () => {
|
|
155
|
-
await expect(startTunnel({ provider: "none", port: 3334, path: "/hook" })).resolves.toBeNull();
|
|
156
|
-
|
|
157
|
-
const proc = nextProcess();
|
|
158
|
-
const result = startTunnel({ provider: "ngrok", port: 3334, path: "/hook" });
|
|
159
|
-
emitNgrokUrl(proc, "https://dispatch.ngrok.io");
|
|
160
|
-
|
|
161
|
-
await expect(result).resolves.toMatchObject({
|
|
162
|
-
publicUrl: "https://dispatch.ngrok.io/hook",
|
|
163
|
-
provider: "ngrok",
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
package/src/tunnel.ts
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { getTailscaleDnsName } from "./webhook/tailscale.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Tunnel configuration for exposing the webhook server.
|
|
6
|
-
*/
|
|
7
|
-
interface TunnelConfig {
|
|
8
|
-
/** Tunnel provider: ngrok, tailscale-serve, or tailscale-funnel */
|
|
9
|
-
provider: "ngrok" | "tailscale-serve" | "tailscale-funnel" | "none";
|
|
10
|
-
/** Local port to tunnel */
|
|
11
|
-
port: number;
|
|
12
|
-
/** Path prefix for the tunnel (e.g., /voice/webhook) */
|
|
13
|
-
path: string;
|
|
14
|
-
/** ngrok auth token (optional, enables longer sessions) */
|
|
15
|
-
ngrokAuthToken?: string;
|
|
16
|
-
/** ngrok custom domain (paid feature) */
|
|
17
|
-
ngrokDomain?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Result of starting a tunnel.
|
|
22
|
-
*/
|
|
23
|
-
export interface TunnelResult {
|
|
24
|
-
/** The public URL */
|
|
25
|
-
publicUrl: string;
|
|
26
|
-
/** Function to stop the tunnel */
|
|
27
|
-
stop: () => Promise<void>;
|
|
28
|
-
/** Tunnel provider name */
|
|
29
|
-
provider: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Start an ngrok tunnel to expose the local webhook server.
|
|
34
|
-
*
|
|
35
|
-
* Uses the ngrok CLI which must be installed: https://ngrok.com/download
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* const tunnel = await startNgrokTunnel({ port: 3334, path: '/voice/webhook' });
|
|
39
|
-
* console.log('Public URL:', tunnel.publicUrl);
|
|
40
|
-
* // Later: await tunnel.stop();
|
|
41
|
-
*/
|
|
42
|
-
export async function startNgrokTunnel(config: {
|
|
43
|
-
port: number;
|
|
44
|
-
path: string;
|
|
45
|
-
authToken?: string;
|
|
46
|
-
domain?: string;
|
|
47
|
-
}): Promise<TunnelResult> {
|
|
48
|
-
// Set auth token if provided
|
|
49
|
-
if (config.authToken) {
|
|
50
|
-
await runNgrokCommand(["config", "add-authtoken", config.authToken]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Build ngrok command args
|
|
54
|
-
const args = ["http", String(config.port), "--log", "stdout", "--log-format", "json"];
|
|
55
|
-
|
|
56
|
-
// Add custom domain if provided (paid ngrok feature)
|
|
57
|
-
if (config.domain) {
|
|
58
|
-
args.push("--domain", config.domain);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
const proc = spawn("ngrok", args, {
|
|
63
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
let resolved = false;
|
|
67
|
-
let publicUrl: string | null = null;
|
|
68
|
-
let outputBuffer = "";
|
|
69
|
-
|
|
70
|
-
const timeout = setTimeout(() => {
|
|
71
|
-
if (!resolved) {
|
|
72
|
-
resolved = true;
|
|
73
|
-
proc.kill("SIGTERM");
|
|
74
|
-
reject(new Error("ngrok startup timed out (30s)"));
|
|
75
|
-
}
|
|
76
|
-
}, 30000);
|
|
77
|
-
|
|
78
|
-
const processLine = (line: string) => {
|
|
79
|
-
try {
|
|
80
|
-
const log = JSON.parse(line);
|
|
81
|
-
|
|
82
|
-
// ngrok logs the public URL in a 'started tunnel' message
|
|
83
|
-
if (log.msg === "started tunnel" && log.url) {
|
|
84
|
-
publicUrl = log.url;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Also check for the URL field directly
|
|
88
|
-
if (log.addr && log.url && !publicUrl) {
|
|
89
|
-
publicUrl = log.url;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Check for ready state
|
|
93
|
-
if (publicUrl && !resolved) {
|
|
94
|
-
resolved = true;
|
|
95
|
-
clearTimeout(timeout);
|
|
96
|
-
|
|
97
|
-
// Add path to the public URL
|
|
98
|
-
const fullUrl = publicUrl + config.path;
|
|
99
|
-
|
|
100
|
-
console.log(`[voice-call] ngrok tunnel active: ${fullUrl}`);
|
|
101
|
-
|
|
102
|
-
resolve({
|
|
103
|
-
publicUrl: fullUrl,
|
|
104
|
-
provider: "ngrok",
|
|
105
|
-
stop: async () => {
|
|
106
|
-
proc.kill("SIGTERM");
|
|
107
|
-
await new Promise<void>((res) => {
|
|
108
|
-
proc.on("close", () => res());
|
|
109
|
-
setTimeout(res, 2000); // Fallback timeout
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
} catch {
|
|
115
|
-
// Not JSON, might be startup message
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
proc.stdout.on("data", (data: Buffer) => {
|
|
120
|
-
outputBuffer += data.toString();
|
|
121
|
-
const lines = outputBuffer.split("\n");
|
|
122
|
-
outputBuffer = lines.pop() || "";
|
|
123
|
-
|
|
124
|
-
for (const line of lines) {
|
|
125
|
-
if (line.trim()) {
|
|
126
|
-
processLine(line);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
proc.stderr.on("data", (data: Buffer) => {
|
|
132
|
-
const msg = data.toString();
|
|
133
|
-
// Check for common errors
|
|
134
|
-
if (msg.includes("ERR_NGROK")) {
|
|
135
|
-
if (!resolved) {
|
|
136
|
-
resolved = true;
|
|
137
|
-
clearTimeout(timeout);
|
|
138
|
-
reject(new Error(`ngrok error: ${msg}`));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
proc.on("error", (err) => {
|
|
144
|
-
if (!resolved) {
|
|
145
|
-
resolved = true;
|
|
146
|
-
clearTimeout(timeout);
|
|
147
|
-
reject(new Error(`Failed to start ngrok: ${err.message}`));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
proc.on("close", (code) => {
|
|
152
|
-
if (!resolved) {
|
|
153
|
-
resolved = true;
|
|
154
|
-
clearTimeout(timeout);
|
|
155
|
-
reject(new Error(`ngrok exited unexpectedly with code ${code}`));
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Run an ngrok command and wait for completion.
|
|
163
|
-
*/
|
|
164
|
-
async function runNgrokCommand(args: string[]): Promise<string> {
|
|
165
|
-
return new Promise((resolve, reject) => {
|
|
166
|
-
const proc = spawn("ngrok", args, {
|
|
167
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
let stdout = "";
|
|
171
|
-
let stderr = "";
|
|
172
|
-
|
|
173
|
-
proc.stdout.on("data", (data) => {
|
|
174
|
-
stdout += data.toString();
|
|
175
|
-
});
|
|
176
|
-
proc.stderr.on("data", (data) => {
|
|
177
|
-
stderr += data.toString();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
proc.on("close", (code) => {
|
|
181
|
-
if (code === 0) {
|
|
182
|
-
resolve(stdout);
|
|
183
|
-
} else {
|
|
184
|
-
reject(new Error(`ngrok command failed: ${stderr || stdout}`));
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
proc.on("error", reject);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Check if ngrok is installed and available.
|
|
194
|
-
*/
|
|
195
|
-
export async function isNgrokAvailable(): Promise<boolean> {
|
|
196
|
-
return new Promise((resolve) => {
|
|
197
|
-
const proc = spawn("ngrok", ["version"], {
|
|
198
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
proc.on("close", (code) => {
|
|
202
|
-
resolve(code === 0);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
proc.on("error", () => {
|
|
206
|
-
resolve(false);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Start a Tailscale serve/funnel tunnel.
|
|
213
|
-
*/
|
|
214
|
-
export async function startTailscaleTunnel(config: {
|
|
215
|
-
mode: "serve" | "funnel";
|
|
216
|
-
port: number;
|
|
217
|
-
path: string;
|
|
218
|
-
}): Promise<TunnelResult> {
|
|
219
|
-
// Get Tailscale DNS name
|
|
220
|
-
const dnsName = await getTailscaleDnsName();
|
|
221
|
-
if (!dnsName) {
|
|
222
|
-
throw new Error("Could not get Tailscale DNS name. Is Tailscale running?");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const path = config.path.startsWith("/") ? config.path : `/${config.path}`;
|
|
226
|
-
const localUrl = `http://127.0.0.1:${config.port}${path}`;
|
|
227
|
-
|
|
228
|
-
return new Promise((resolve, reject) => {
|
|
229
|
-
const proc = spawn("tailscale", [config.mode, "--bg", "--yes", "--set-path", path, localUrl], {
|
|
230
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const timeout = setTimeout(() => {
|
|
234
|
-
proc.kill("SIGKILL");
|
|
235
|
-
reject(new Error(`Tailscale ${config.mode} timed out`));
|
|
236
|
-
}, 10000);
|
|
237
|
-
|
|
238
|
-
proc.on("close", (code) => {
|
|
239
|
-
clearTimeout(timeout);
|
|
240
|
-
if (code === 0) {
|
|
241
|
-
const publicUrl = `https://${dnsName}${path}`;
|
|
242
|
-
console.log(`[voice-call] Tailscale ${config.mode} active: ${publicUrl}`);
|
|
243
|
-
|
|
244
|
-
resolve({
|
|
245
|
-
publicUrl,
|
|
246
|
-
provider: `tailscale-${config.mode}`,
|
|
247
|
-
stop: async () => {
|
|
248
|
-
await stopTailscaleTunnel(config.mode, path);
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
} else {
|
|
252
|
-
reject(new Error(`Tailscale ${config.mode} failed with code ${code}`));
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
proc.on("error", (err) => {
|
|
257
|
-
clearTimeout(timeout);
|
|
258
|
-
reject(err);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Stop a Tailscale serve/funnel tunnel.
|
|
265
|
-
*/
|
|
266
|
-
async function stopTailscaleTunnel(mode: "serve" | "funnel", path: string): Promise<void> {
|
|
267
|
-
return new Promise((resolve) => {
|
|
268
|
-
const proc = spawn("tailscale", [mode, "off", path], {
|
|
269
|
-
stdio: "ignore",
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
const timeout = setTimeout(() => {
|
|
273
|
-
proc.kill("SIGKILL");
|
|
274
|
-
resolve();
|
|
275
|
-
}, 5000);
|
|
276
|
-
|
|
277
|
-
proc.on("close", () => {
|
|
278
|
-
clearTimeout(timeout);
|
|
279
|
-
resolve();
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Start a tunnel based on configuration.
|
|
286
|
-
*/
|
|
287
|
-
export async function startTunnel(config: TunnelConfig): Promise<TunnelResult | null> {
|
|
288
|
-
switch (config.provider) {
|
|
289
|
-
case "ngrok":
|
|
290
|
-
return startNgrokTunnel({
|
|
291
|
-
port: config.port,
|
|
292
|
-
path: config.path,
|
|
293
|
-
authToken: config.ngrokAuthToken,
|
|
294
|
-
domain: config.ngrokDomain,
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
case "tailscale-serve":
|
|
298
|
-
return startTailscaleTunnel({
|
|
299
|
-
mode: "serve",
|
|
300
|
-
port: config.port,
|
|
301
|
-
path: config.path,
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
case "tailscale-funnel":
|
|
305
|
-
return startTailscaleTunnel({
|
|
306
|
-
mode: "funnel",
|
|
307
|
-
port: config.port,
|
|
308
|
-
path: config.path,
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
default:
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
}
|