Skip to content

rtviClient.connect() promise never resolves after successful connection #156

@satvikbatra

Description

@satvikbatra

The promise returned by rtviClient.connect() never resolves, even when the connection is successfully established. This makes it impossible to reliably detect when a connection is ready using an await statement.


Steps to Reproduce

  1. Create an RTVIClient instance using DailyTransport.
  2. Call await rtviClient.connect().
  3. Observe that the connection succeeds functionally:
    • The onTransportStateChanged callback fires with state='ready'.
    • Audio tracks start playing.
    • Bot interaction works as expected.
  4. Notice that the connect() promise never resolves, and code execution halts at the await line.

Expected Behavior

The connect() promise should resolve once the transport state becomes 'ready' and the connection is fully established, allowing the await call to complete and subsequent code to execute.


Actual Behavior

The connection is successfully established and becomes fully functional. All relevant callbacks (onConnected, onTransportStateChanged, etc.) fire correctly. However, the await rtviClient.connect() call hangs indefinitely and never returns.


Code Example

import { RTVIClient } from "@pipecat-ai/client-js";
import { DailyTransport } from '@pipecat-ai/daily-transport';

const rtviClient = new RTVIClient({
  transport: new DailyTransport(),
  params: {
    baseUrl: "[https://api.example.com](https://api.example.com)",
    endpoints: { connect: "/connect" },
    requestData: {
      /* ... connection parameters ... */
    },
  },
  callbacks: {
    onConnected: () => {
      console.log("Connected!"); // ✅ This fires
    },
    onTransportStateChanged: (state) => {
      console.log("State:", state); // ✅ Fires with 'ready'
    },
  },
});
console.log("About to call rtviClient.connect()...");
await rtviClient.connect(); // ❌ Hangs here forever
console.log("Returned from connect()!"); // ❌ This line is never reached

Observed Console Output:

About to call rtviClient.connect()...
State: ready
Connected!
// ... The connection works perfectly, but "Returned from connect()!" never appears.

Impact

This bug prevents standard asynchronous control flow and makes it difficult to:

  • Reliably detect when the connection is complete.
  • Use async/await for managing connection logic sequentially.
  • Implement robust reconnection mechanisms that depend on the connect() method completing.

Workaround

The current workaround is to avoid awaiting the connect() promise and instead rely on the onTransportStateChanged callback to detect a successful connection.

const rtviClient = new RTVIClient({
  // ... other config ...
  callbacks: {
    onTransportStateChanged: (state) => {
      if (state === "ready") {
        // Connection is ready, proceed with application logic here.
        console.log("Connection is fully established.");
      }
    },
  },
});
// Call connect() without awaiting it.
rtviClient.connect();

Environment:

  • Package: @pipecat-ai/client-js
  • Transport: DailyTransport
  • Browser: Chrome / Safari

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions