cuddly-cartoon-47334
03/26/2025, 3:54 AMtall-airline-16756
03/26/2025, 3:54 AMtall-airline-16756
03/26/2025, 3:54 AMawait self.ctx.room.disconnect()
: This is a client-side action where the participant voluntarily leaves the room. It is typically called by the participant themselves, and on some platforms, it is automatically triggered when the application exits. If not explicitly called, the participant will be removed after a timeout period (e.g., 15 seconds after application termination).
• await self.api.room.remove_participant()
: This is a server-side action used to forcibly disconnect a participant from the room. It triggers a Disconnected
event for the participant with a specific reason. However, this method does not invalidate the participant's token, meaning they could potentially rejoin unless additional measures are taken (e.g., using short TTL tokens or not issuing new tokens).
In terms of ending the call, both methods can achieve this, but the context differs. The first is participant-initiated, while the second is server-initiated.
Sources: Connecting to LiveKit | LiveKit Docs | Managing participants | LiveKit Docscuddly-cartoon-47334
03/26/2025, 3:55 AMtall-airline-16756
03/26/2025, 3:55 AMawait self.api.room.remove_participant()
ends a SIP trunk call with Twilio in LiveKit. This might depend on how the SIP integration is configured and managed within your setup.
If you need further assistance, I recommend consulting the LiveKit documentation on SIP integration or reaching out to a LiveKit specialist for more detailed guidance.cuddly-cartoon-47334
03/26/2025, 4:01 AMtall-airline-16756
03/26/2025, 4:01 AMawait self.api.room.remove_participant()
is a server-initiated action, typically used to forcibly disconnect a participant from the room.
On the other hand, if the client is taking a web call, they would use await self.ctx.room.disconnect()
to voluntarily leave the room. This is a client-side action initiated by the participant themselves.cuddly-cartoon-47334
03/26/2025, 5:59 AMtall-airline-16756
03/26/2025, 5:59 AMcuddly-cartoon-47334
03/26/2025, 5:59 AMtall-airline-16756
03/26/2025, 6:00 AMcuddly-cartoon-47334
03/26/2025, 6:00 AMtall-airline-16756
03/26/2025, 6:00 AMDeleteRoom
API, participants in that room are automatically disconnected, and they receive a Disconnected
event with the reason ROOM_DELETED
.
You can use this disconnection reason in your application code to trigger any necessary actions or callbacks when a room is deleted.
Sources: Connecting to LiveKit | LiveKit Docs | ROOM_DELETEDcuddly-cartoon-47334
03/26/2025, 6:01 AMtall-airline-16756
03/26/2025, 6:01 AMDisconnected
event with the ROOM_DELETED
reason in LiveKit. However, you can typically listen for disconnection events in your client SDK and check the reason code to handle this scenario.
For detailed implementation, I recommend referring to the LiveKit Python SDK documentation or reaching out to a LiveKit specialist for assistance.cuddly-cartoon-47334
03/26/2025, 6:02 AMtall-airline-16756
03/26/2025, 6:02 AMDisconnected
event in Python using the LiveKit SDK:
from livekit import Room, RoomEvent
# Define a callback function to handle room events
def on_room_event(event):
if isinstance(event, RoomEvent.Disconnected):
if event.reason == "ROOM_DELETED":
print("The room was deleted, and the participant has been disconnected.")
# Create a room instance and set up the event listener
room = Room()
room.on_event = on_room_event
# Connect to the room (replace with your connection details)
await room.connect("your_server_url", "your_token")
# Keep the application running to listen for events
await room.run()
Note: This is a general example and may need adjustments based on the specific LiveKit Python SDK you are using. Please refer to the SDK documentation for exact implementation details.cuddly-cartoon-47334
03/26/2025, 6:03 AMtall-airline-16756
03/26/2025, 6:03 AMDeleteRoom
API, the Disconnected
event with the reason ROOM_DELETED
is triggered for participants before the room is fully deleted. This allows the client to handle the disconnection event appropriately before the room ceases to exist.
So yes, the on_room_event
callback will be called before the room is completely deleted.cuddly-cartoon-47334
03/26/2025, 9:39 AMtall-airline-16756
03/26/2025, 9:39 AMLocalAudioTrackRecorder
class captures audio from a local track and streams it as a data stream in a selected format. This can then be sent to other participants using ByteStreamWriter
.
• Using AudioByteStream (Agents JS): The AudioByteStream
class is available for handling audio byte streams in LiveKit Agents.
• Working with AudioTracks (JS Client SDK): The JS Client SDK provides AudioTrack
types for handling audio streams.
• Using RemoteAudioTrack (JS Client SDK): For receiving audio from remote participants, you can use the RemoteAudioTrack
class.
For detailed implementation, please refer to the LiveKit documentation for your specific SDK.
Sources: AudioByteStream | LiveKit Agents | AudioTrack | LiveKit JS Client SDK - v2.8.1 | RemoteAudioTrack | LiveKit JS Client SDK - v2.8.1 | LocalAudioTrackRecorder | Documentationcuddly-cartoon-47334
03/26/2025, 9:40 AMtall-airline-16756
03/26/2025, 9:40 AMif __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
prewarm_fnc=prewarm,
agent_name="inbound-agent",
),
)
3. Run the Agent: `python3 agent.py dev`This starts your Python agent, which can now handle audio streams.
4. Stream Audio to iOS: On the iOS side, use the LiveKit iOS SDK to connect to the room and receive the audio stream. The SDK provides tools to handle audio tracks and play them in your app.
LiveKit's framework ensures low-latency audio streaming between the Python agent and the iOS app. For detailed implementation, refer to the LiveKit documentation for both the Python agent and iOS SDK.
Sources: LiveKit Docs | Accepting incoming calls | LiveKit Docs | LiveKitcuddly-cartoon-47334
03/26/2025, 9:41 AMtall-airline-16756
03/26/2025, 9:41 AM