-
Notifications
You must be signed in to change notification settings - Fork 110
feat: auto failover APIs with LK Cloud #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca6cd9a
6480f0a
b7e7dbe
4f2925c
0619fe1
e6ef3f7
f46034d
56dac7a
1b64ad7
40f656b
981f4fd
3be00d2
d092da9
c7dad88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "livekit-server-sdk": patch | ||
| --- | ||
|
|
||
| feat: auto failover APIs with LK Cloud |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # SPDX-FileCopyrightText: 2026 LiveKit, Inc. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| name: Test API | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| failover: | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| mock-server: | ||
| image: livekit/test-server:latest | ||
| ports: | ||
| - 9999:9999 | ||
| - 10000:10000 | ||
| - 10001:10001 | ||
| - 10002:10002 | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | ||
| with: | ||
| node-version: 24 | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Wait for mock server | ||
| run: | | ||
| for i in $(seq 1 30); do | ||
| curl -sf http://127.0.0.1:9999/settings/regions >/dev/null && exit 0 | ||
| sleep 1 | ||
| done | ||
| echo "mock server did not become ready" && exit 1 | ||
|
|
||
| - name: Run API tests | ||
| run: pnpm --filter="livekit-server-sdk" exec vitest --environment node run test/api |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ import { | |||||||||||||
| import type { ClientOptions } from './ClientOptions.js'; | ||||||||||||||
| import { ServiceBase } from './ServiceBase.js'; | ||||||||||||||
| import { type Rpc, TwirpRpc, livekitPackage } from './TwirpRPC.js'; | ||||||||||||||
| import { DEFAULT_RINGING_TIMEOUT_SECONDS } from './dialTimeout.js'; | ||||||||||||||
|
|
||||||||||||||
| const svc = 'Connector'; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -87,6 +88,12 @@ export interface AcceptWhatsAppCallOptions { | |||||||||||||
| ringingTimeout?: number; | ||||||||||||||
| /** Optional - Wait for the call to be answered before returning */ | ||||||||||||||
| waitUntilAnswered?: boolean; | ||||||||||||||
| /** | ||||||||||||||
| * Optional - Request timeout in seconds. When `waitUntilAnswered` is set, | ||||||||||||||
| * defaults to a longer value (dialing takes time) and is raised, if needed, | ||||||||||||||
| * to stay above `ringingTimeout`; otherwise the client default applies. | ||||||||||||||
| */ | ||||||||||||||
| timeout?: number; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Twilio types | ||||||||||||||
|
|
@@ -123,10 +130,10 @@ export class ConnectorClient extends ServiceBase { | |||||||||||||
| */ | ||||||||||||||
| constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) { | ||||||||||||||
| super(apiKey, secret); | ||||||||||||||
| const rpcOptions = options?.requestTimeout | ||||||||||||||
| ? { requestTimeout: options.requestTimeout } | ||||||||||||||
| : undefined; | ||||||||||||||
| this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions); | ||||||||||||||
| this.rpc = new TwirpRpc(host, livekitPackage, { | ||||||||||||||
| requestTimeout: options?.requestTimeout, | ||||||||||||||
| failover: options?.failover, | ||||||||||||||
| }); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
|
|
@@ -206,11 +213,21 @@ export class ConnectorClient extends ServiceBase { | |||||||||||||
| waitUntilAnswered: options.waitUntilAnswered, | ||||||||||||||
| }).toJson(); | ||||||||||||||
|
|
||||||||||||||
| // Accept can block until the call is answered, so default the request timeout | ||||||||||||||
| // to the standard ring window. The caller overrides it via `timeout` and | ||||||||||||||
| // should set it above the ringing_timeout passed to dialWhatsAppCall; the | ||||||||||||||
| // two calls are separate, so the SDK can't derive it. Non-waiting returns | ||||||||||||||
| // promptly and uses the client default. | ||||||||||||||
| const timeout = options.waitUntilAnswered | ||||||||||||||
| ? (options.timeout ?? DEFAULT_RINGING_TIMEOUT_SECONDS) | ||||||||||||||
| : options.timeout; | ||||||||||||||
|
Comment on lines
+221
to
+223
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 WhatsApp call acceptance times out before ringing finishes when user sets a custom ring duration The HTTP request timeout for waiting WhatsApp calls ignores the user-supplied ringing duration ( Impact: Users who set a custom ringing timeout and wait for the call to be answered will see spurious timeout errors. Timeout computation differs between WhatsApp and SIP pathsThe SIP path in The WhatsApp path at
The
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected behavior |
||||||||||||||
|
|
||||||||||||||
| const data = await this.rpc.request( | ||||||||||||||
| svc, | ||||||||||||||
| 'AcceptWhatsAppCall', | ||||||||||||||
| req, | ||||||||||||||
| await this.authHeader({ roomCreate: true }), | ||||||||||||||
| timeout, | ||||||||||||||
| ); | ||||||||||||||
| return AcceptWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true }); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.