how do I subscribe to only the audio for a livekit...
# ask-ai
n
how do I subscribe to only the audio for a livekit call swift ios
t
Thanks for reaching out, rohit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you subscribe to only the audio for a LiveKit call in Swift for iOS, here’s a simple step-by-step guide you can follow: 1. Disable Auto-Subscribe: When you connect to the room, set
autoSubscribe
to
false
. This way, you have full control over what you subscribe to:
Copy code
let connectOptions = ConnectOptions(
    url: "ws://<your_host>",
    token: "<your_token>",
    autoSubscribe: false
)
let room = LiveKit.connect(options: connectOptions, delegate: self)
2. Subscribe to Audio Tracks: Use the room delegate methods to make sure you’re only subscribing to audio tracks. Here’s how you can do it:
Copy code
func room(_ room: Room, participant: RemoteParticipant, didPublish publication: RemoteTrackPublication) {
    if publication.source == .microphone && publication.kind == .audio {
        Task {
            try await publication.set(subscribed: true)
        }
    }
}
3. Server-Side Control (Optional): If you want, you can also configure your authentication token to allow subscription permissions only. This adds an extra layer of control:
Copy code
const token = new AccessToken(apiKey, apiSecret, {
  identity: 'audio-only-participant',
});

token.addGrant({
  room: 'your-room-name',
  roomJoin: true,
  canPublish: false,
  canSubscribe: true,
});
If you have any questions or need a hand with the implementation, please don’t hesitate to reach out. I’m here to help! Sources: Subscribing to tracks | LiveKit docs | Multiplatform/Views/ParticipantView.swift | Authentication | LiveKit Docs | Sources/LiveKit/Core/Room+PreConnect.swift | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki
n
how do I record but remote and current particpant together
t
I'm happy to help you with recording both remote and current participants together in LiveKit! The best way to do this is by using Room Composite Egress. This method captures the entire room session, including everyone in it, and combines their audio and video into a single, seamless output. Here’s how you can get started with recording: 1. Start Room Composite Egress: You’ll want to use a LiveKit server SDK to kick off the recording. For example, in Node.js, it looks like this:
Copy code
await egress.startRoomCompositeEgress(
  'your-room-name',
  {
    file: { filepath: 'recording.mp4', s3: { ... } } // specify output location
  },
  { layout: 'grid', audioOnly: false }
);
1. Choose Output Options: You have the flexibility to save your recording to cloud storage like S3, stream it through RTMP, or create HLS files—whatever works best for you. 2. Stop Recording: When you’re ready to stop, just use this command:
Copy code
await egress.stopEgress(egressId);
This method will automatically include all published tracks—audio, video, screen share—from every participant in the room, including yourself. If you have any questions or need a hand with anything else, please don’t hesitate to ask. I’m here to help! Sources: protobufs/livekit_egress.proto | Universal Egress | packages/livekit-server-sdk/src/EgressClient.ts | Recording participants | LiveKit docs
n
in swift
t
Hi there! Room Composite Egress is usually handled on the server side with SDKs like Node.js or Python. Are you hoping to start the recording directly from your Swift iOS app, or would you prefer some help setting up the server-side egress and connecting it with your app? Just let me know—I’m here to help you every step of the way! Sources: packages/livekit-server-sdk/src/EgressClient.ts | src/main/kotlin/io/livekit/server/EgressServiceClient.kt | livekit-api/src/services/egress.rs | livekit-api/livekit/api/egress_service.py | README.md
n
directly on the swift side
t
Hi there! I wanted to share some helpful info about Room Composite Egress and how it works with a Swift iOS app. Since this is a server-side operation that needs API credentials and server SDKs, it can’t be triggered directly from your Swift app. The Swift SDK is fantastic for client-side tasks like connecting to rooms and managing media tracks, but egress features aren’t included there. Here’s a friendly recommendation to get you started: 1. Set up a server endpoint using a LiveKit server SDK—Node.js or Python are great options—to handle starting the Room Composite Egress. 2. From your Swift iOS app, you can then call this server endpoint whenever you want to start recording. 3. Your server can manage the egress response and, if you like, send updates back to your iOS app about the recording status. This approach keeps your API credentials safe on the server while still letting your app initiate recordings smoothly. If you’d like, I’m here to help guide you through setting up the server-side egress—just let me know! Sources: packages/livekit-server-sdk/src/EgressClient.ts | pkg/service/egress.go | livekit-api/src/services/egress.rs | src/main/kotlin/io/livekit/server/EgressServiceClient.kt | lib/livekit/egress_service_client.rb