import { RoomServiceClient, ParticipantInfo, ...
# ask-ai
l
import { RoomServiceClient, ParticipantInfo, SipClient, Room, } from "livekit-server-sdk"; what does this participantInfo do and how do i use it ?
t
Thanks for reaching out, Istiaque. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
ParticipantInfo
in the LiveKit SDK is a wonderful way to get detailed information about a participant in a room. It includes helpful metadata like: • sid: A unique session ID for the participant. • identity: A unique identifier for the participant within the room. • name: An optional display name. • state: The participant's connection state (e.g., JOINING, JOINED, ACTIVE, DISCONNECTED). • tracks: Information about the media tracks published by the participant. • metadata: Custom metadata associated with the participant. • permission: Defines the participant's allowed actions, such as publishing or subscribing to tracks. You can use
ParticipantInfo
to easily manage and keep track of participant details, whether you’re listing who’s in a room or handling events when participants join or leave. If you’d like, I’d be happy to walk you through specific use cases or share some examples—just let me know! Sources: Rooms, participants, and tracks | LiveKit docs | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | Core Platform Architecture & Authentication | livekit/livekit_composite | D... | packages/livekit-rtc/src/proto/participant_pb.ts | livekit-protocol/src/livekit.rs
l
show me how to use this in nodejs code
t
Here is an example of how to use
ParticipantInfo
in Node.js with the LiveKit SDK:
Copy code
import { RoomServiceClient } from "livekit-server-sdk";

const client = new RoomServiceClient("ws://localhost:7880", "api-key", "api-secret");

async function getParticipantInfo(roomName, identity) {
  try {
    const participant = await client.getParticipant(roomName, identity);
    console.log("Participant SID:", participant.sid);
    console.log("Identity:", participant.identity);
    console.log("Name:", participant.name);
    console.log("Metadata:", participant.metadata);
    console.log("Kind:", participant.kind); // e.g., STANDARD, AGENT
    console.log("Attributes:", participant.attributes);
    console.log("State:", participant.state); // Connection state
  } catch (error) {
    console.error("Failed to get participant:", error);
  }
}

// Example usage
getParticipantInfo("example-room", "participant-identity");
This code helps you retrieve participant details using the
getParticipant
method of
RoomServiceClient
. Just be sure to replace
"api-key"
,
"api-secret"
, and
"ws://localhost:7880"
with your own LiveKit server credentials and URL. If you have any questions or need more examples, please don’t hesitate to ask—I’m here to help! Sources: Managing participants | LiveKit docs | packages/livekit-server-sdk/src/index.ts | Rooms, participants, and tracks | LiveKit docs | TEMPLATE.md
l
how do i get the sipTrunkPhoneNumber ?
t
To help you retrieve the
sipTrunkPhoneNumber
in Node.js, you can use the
listSipInboundTrunk
or
listSipOutboundTrunk
methods from the
SipClient
. Here’s a simple example to guide you:
Copy code
import { SipClient } from "livekit-server-sdk";

const sipClient = new SipClient("https://your-livekit-url", "API_KEY", "API_SECRET");

async function getSipTrunkPhoneNumbers() {
  try {
    // List inbound trunks
    const inboundTrunks = await sipClient.listSipInboundTrunk();
    inboundTrunks.forEach(trunk => {
      console.log("Inbound Trunk ID:", trunk.sipTrunkId);
      console.log("Phone Numbers:", trunk.numbers); // Array of phone numbers
    });

    // List outbound trunks
    const outboundTrunks = await sipClient.listSipOutboundTrunk();
    outboundTrunks.forEach(trunk => {
      console.log("Outbound Trunk ID:", trunk.sipTrunkId);
      console.log("Phone Numbers:", trunk.numbers); // Array of phone numbers
    });
  } catch (error) {
    console.error("Failed to retrieve SIP trunk phone numbers:", error);
  }
}

// Example usage
getSipTrunkPhoneNumbers();
The
numbers
field inside each trunk object holds the
sipTrunkPhoneNumber
values you’re looking for. Just make sure to replace
"API_KEY"
,
"API_SECRET"
, and
"https://your-livekit-url"
with your actual LiveKit server credentials and URL. If you have any questions or need more help, please don’t hesitate to ask—I’m here to support you! Sources: SIP participant | LiveKit Docs | packages/livekit-server-sdk/src/SipClient.ts | lib/livekit/sip_service_client.rb | livekit-protocol/livekit/protocol/sip.pyi | SIP APIs | LiveKit Docs
l
no, i want to get the sipTrunkPhoneNumber when a phoen call is made to the ai agent
t
To help you get the
sipTrunkPhoneNumber
during a phone call to an AI agent, you can easily access it from the SIP participant's attributes. The attribute
sip.trunkPhoneNumber
holds the phone number linked to the SIP trunk. Here’s a friendly example of how you can retrieve it using Node.js:
Copy code
import { RoomServiceClient } from "livekit-server-sdk";

const client = new RoomServiceClient("ws://localhost:7880", "api-key", "api-secret");

async function getSipTrunkPhoneNumber(roomName, participantIdentity) {
  try {
    const participant = await client.getParticipant(roomName, participantIdentity);
    const sipTrunkPhoneNumber = participant.attributes["sip.trunkPhoneNumber"];
    console.log("SIP Trunk Phone Number:", sipTrunkPhoneNumber);
  } catch (error) {
    console.error("Oops! Failed to retrieve SIP trunk phone number:", error);
  }
}

// Example usage
getSipTrunkPhoneNumber("example-room", "sip-participant-identity");
Just remember to replace
"api-key"
,
"api-secret"
, and
"ws://localhost:7880"
with your LiveKit server credentials and URL. Also, the
participantIdentity
should match the identity of the SIP participant in your room. If you have any questions or need a hand with this, please don’t hesitate to ask—I’m here to help! Sources: SIP participant | LiveKit Docs | ivr-nagivator/README.mdoc | livekit-protocol/livekit/protocol/sip.pyi | src/setup-livekit.ts
l
how do i get the agent name ?
t
To help you get the AI agent's name during a phone call, you can easily retrieve it from the agent's identity or metadata. Here's a simple way to do it using Node.js:
Copy code
import { RoomServiceClient } from "livekit-server-sdk";

const client = new RoomServiceClient("ws://localhost:7880", "api-key", "api-secret");

async function getAgentName(roomName, participantIdentity) {
  try {
    const participant = await client.getParticipant(roomName, participantIdentity);
    const agentName = participant.name || participant.identity; // Use name if set, fallback to identity
    console.log("Agent Name:", agentName);
  } catch (error) {
    console.error("Failed to retrieve agent name:", error);
  }
}

// Example usage
getAgentName("example-room", "agent-participant-identity");
Just be sure to replace
"api-key"
,
"api-secret"
, and
"ws://localhost:7880"
with your own LiveKit server credentials and URL. Also, the
participantIdentity
should match the identity of the AI agent in the room. If you have any questions or need a hand with anything else, feel free to ask—I'm here to help! Sources: src/components/playground/Playground.tsx | packages/sip--make-a-call/src/agent.ts | agent.py | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | livekit-plugins/livekit-plugins-hedra/livekit/plugins/hedra/avatar.py