-
- All Implemented Interfaces:
-
io.livekit.android.room.datastream.outgoing.OutgoingDataStreamManager,io.livekit.android.room.rpc.RpcManager
public final class LocalParticipant extends Participant implements OutgoingDataStreamManager, RpcManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceLocalParticipant.PublishListenerpublic interfaceLocalParticipant.Factory
-
Field Summary
-
Method Summary
Modifier and Type Method Description final LocalAudioTrackOptionsgetAudioTrackCaptureDefaults()final UnitsetAudioTrackCaptureDefaults(LocalAudioTrackOptions audioTrackCaptureDefaults)final AudioTrackPublishDefaultsgetAudioTrackPublishDefaults()final UnitsetAudioTrackPublishDefaults(AudioTrackPublishDefaults audioTrackPublishDefaults)final LocalVideoTrackOptionsgetVideoTrackCaptureDefaults()final UnitsetVideoTrackCaptureDefaults(LocalVideoTrackOptions videoTrackCaptureDefaults)final VideoTrackPublishDefaultsgetVideoTrackPublishDefaults()final UnitsetVideoTrackPublishDefaults(VideoTrackPublishDefaults videoTrackPublishDefaults)final LocalVideoTrackOptionsgetScreenShareTrackCaptureDefaults()final UnitsetScreenShareTrackCaptureDefaults(LocalVideoTrackOptions screenShareTrackCaptureDefaults)final VideoTrackPublishDefaultsgetScreenShareTrackPublishDefaults()final UnitsetScreenShareTrackPublishDefaults(VideoTrackPublishDefaults screenShareTrackPublishDefaults)final EventListenable<ParticipantEvent>getEvents()final LivekitModels.ParticipantInfogetParticipantInfo()Changes can be observed by using io.livekit.android.util.flow final UnitsetParticipantInfo(@FlowObservable() LivekitModels.ParticipantInfo participantInfo)final Participant.IdentitygetIdentity()The participant's identity on the server. final UnitsetIdentity(@FlowObservable() Participant.Identity identity)final Participant.StategetState()The participant state. final UnitsetState(@FlowObservable() Participant.State state)final FloatgetAudioLevel()Changes can be observed by using io.livekit.android.util.flow final UnitsetAudioLevel(@FlowObservable() Float audioLevel)final BooleangetIsSpeaking()Changes can be observed by using io.livekit.android.util.flowA ParticipantEvent.SpeakingChanged event is emitted from events whenever this changes. final UnitsetIsSpeaking(@FlowObservable() Boolean isSpeaking)final StringgetName()The participant's name. final UnitsetName(@FlowObservable() String name)final StringgetMetadata()The metadata for this participant. final UnitsetMetadata(@FlowObservable() String metadata)final Map<String, String>getAttributes()The attributes set on this participant. final UnitsetAttributes(@FlowObservable() Map<String, String> attributes)final AgentAttributesgetAgentAttributes()The agent attributes for this participant. final UnitsetAgentAttributes(@FlowObservable() AgentAttributes agentAttributes)The agent attributes for this participant. final ParticipantPermissiongetPermissions()The permissions for this participant. final UnitsetPermissions(@FlowObservable() ParticipantPermission permissions)final ConnectionQualitygetConnectionQuality()Changes can be observed by using io.livekit.android.util.flow final UnitsetConnectionQuality(@FlowObservable() ConnectionQuality connectionQuality)final LonggetJoinedAt()final LonggetLastSpokeAt()Timestamp when the participant last started speaking, in milliseconds final UnitsetLastSpokeAt(@FlowObservable() Long lastSpokeAt)final Participant.KindgetKind()The kind of participant (i.e. final UnitsetKind(@FlowObservable() Participant.Kind kind)final BooleangetHasInfo()final <ERROR CLASS>getTrackPublications()Maps track sids to their track publications. final Unit)>setTrackPublications(@FlowObservable() <ERROR CLASS> trackPublications)final <ERROR CLASS>getAudioTrackPublications()Changes can be observed by using io.livekit.android.util.flow final <ERROR CLASS>getVideoTrackPublications()Changes can be observed by using io.livekit.android.util.flow final <ERROR CLASS>getIsMicrophoneEnabled()final <ERROR CLASS>getIsCameraEnabled()final <ERROR CLASS>getIsScreenShareEnabled()final Participant.SidgetSid()final UnitsetSid(Participant.Sid sid)final LocalAudioTrackgetOrCreateDefaultAudioTrack()Returns the default audio track, or creates one if it doesn't exist. final LocalVideoTrackgetOrCreateDefaultVideoTrack()Returns the default video track, or creates one if it doesn't exist. final LocalAudioTrackcreateAudioTrack(String name, LocalAudioTrackOptions options)Creates an audio track, recording audio through the microphone with the given options. final LocalVideoTrackcreateVideoTrack(String name, VideoCapturer capturer, LocalVideoTrackOptions options, VideoProcessor videoProcessor)Creates a video track, recording video through the supplied capturer. final LocalVideoTrackcreateVideoTrack(String name, LocalVideoTrackOptions options, VideoProcessor videoProcessor)Creates a video track, recording video through the camera with the given options. final LocalScreencastVideoTrackcreateScreencastTrack(String name, Intent mediaProjectionPermissionResultData, LocalVideoTrackOptions options, VideoProcessor videoProcessor, Function1<Track, Unit> onStop)Creates a screencast video track. LocalTrackPublicationgetTrackPublication(Track.Source source)Retrieves the first track that matches the source, or null LocalTrackPublicationgetTrackPublicationByName(String name)Retrieves the first track that matches name, or null final BooleansetCameraEnabled(Boolean enabled)If set to enabled, creates and publishes a camera video track if not already done, and starts the camera. final BooleansetMicrophoneEnabled(Boolean enabled)If set to enabled, creates and publishes a microphone audio track if not already done, and unmutes the mic. final BooleansetScreenShareEnabled(Boolean enabled, ScreenCaptureParams screenCaptureParams)If set to enabled, creates and publishes a screenshare video track. final BooleanpublishAudioTrack(LocalAudioTrack track, AudioTrackPublishOptions options, LocalParticipant.PublishListener publishListener)Publishes an audio track. final BooleanpublishVideoTrack(LocalVideoTrack track, VideoTrackPublishOptions options, LocalParticipant.PublishListener publishListener)Publishes an video track. final UnitsetTrackSubscriptionPermissions(Boolean allParticipantsAllowed, List<ParticipantTrackPermission> participantTrackPermissions)Control who can subscribe to LocalParticipant's published tracks. final UnitunpublishTrack(Track track, Boolean stopOnUnpublish)Unpublish a track. final Result<Unit>publishData(ByteArray data, DataPublishReliability reliability, String topic, List<Participant.Identity> identities)Publish a new data payload to the room. final Result<Unit>publishDtmf(Integer code, String digit)This suspend function allows you to publish DTMF (Dual-Tone Multi-Frequency) signals within a LiveKit room. UnitregisterRpcMethod(String method, SuspendFunction1<RpcInvocationData, String> handler)Establishes the participant as a receiver for calls of the specified RPC method. UnitunregisterRpcMethod(String method)Unregisters a previously registered RPC method. StringperformRpc(Participant.Identity destinationIdentity, String method, String payload, Duration responseTimeout)Initiate an RPC call to a remote participant final UnitupdateMetadata(String metadata)Updates the metadata of the local participant. final UnitupdateName(String name)Updates the name of the local participant. final UnitupdateAttributes(Map<String, String> attributes)Set or update participant attributes. -
-
Method Detail
-
getAudioTrackCaptureDefaults
final LocalAudioTrackOptions getAudioTrackCaptureDefaults()
-
setAudioTrackCaptureDefaults
final Unit setAudioTrackCaptureDefaults(LocalAudioTrackOptions audioTrackCaptureDefaults)
-
getAudioTrackPublishDefaults
final AudioTrackPublishDefaults getAudioTrackPublishDefaults()
-
setAudioTrackPublishDefaults
final Unit setAudioTrackPublishDefaults(AudioTrackPublishDefaults audioTrackPublishDefaults)
-
getVideoTrackCaptureDefaults
final LocalVideoTrackOptions getVideoTrackCaptureDefaults()
-
setVideoTrackCaptureDefaults
final Unit setVideoTrackCaptureDefaults(LocalVideoTrackOptions videoTrackCaptureDefaults)
-
getVideoTrackPublishDefaults
final VideoTrackPublishDefaults getVideoTrackPublishDefaults()
-
setVideoTrackPublishDefaults
final Unit setVideoTrackPublishDefaults(VideoTrackPublishDefaults videoTrackPublishDefaults)
-
getScreenShareTrackCaptureDefaults
final LocalVideoTrackOptions getScreenShareTrackCaptureDefaults()
-
setScreenShareTrackCaptureDefaults
final Unit setScreenShareTrackCaptureDefaults(LocalVideoTrackOptions screenShareTrackCaptureDefaults)
-
getScreenShareTrackPublishDefaults
final VideoTrackPublishDefaults getScreenShareTrackPublishDefaults()
-
setScreenShareTrackPublishDefaults
final Unit setScreenShareTrackPublishDefaults(VideoTrackPublishDefaults screenShareTrackPublishDefaults)
-
getEvents
final EventListenable<ParticipantEvent> getEvents()
-
getParticipantInfo
@FlowObservable() final LivekitModels.ParticipantInfo getParticipantInfo()
Changes can be observed by using io.livekit.android.util.flow
-
setParticipantInfo
final Unit setParticipantInfo(@FlowObservable() LivekitModels.ParticipantInfo participantInfo)
-
getIdentity
@FlowObservable() final Participant.Identity getIdentity()
The participant's identity on the server. name should be preferred for UI usecases.
Changes can be observed by using io.livekit.android.util.flow
-
setIdentity
@VisibleForTesting() final Unit setIdentity(@FlowObservable() Participant.Identity identity)
-
getState
@FlowObservable() final Participant.State getState()
The participant state.
Changes can be observed by using io.livekit.android.util.flow
-
setState
@VisibleForTesting() final Unit setState(@FlowObservable() Participant.State state)
-
getAudioLevel
@FlowObservable() final Float getAudioLevel()
Changes can be observed by using io.livekit.android.util.flow
-
setAudioLevel
@VisibleForTesting() final Unit setAudioLevel(@FlowObservable() Float audioLevel)
-
getIsSpeaking
@FlowObservable() final Boolean getIsSpeaking()
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.SpeakingChanged event is emitted from events whenever this changes.
-
setIsSpeaking
@VisibleForTesting() final Unit setIsSpeaking(@FlowObservable() Boolean isSpeaking)
-
getName
@FlowObservable() final String getName()
The participant's name. To be used for user-facing purposes (i.e. when displayed in the UI).
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.NameChanged event is emitted from events whenever this changes.
-
setName
@VisibleForTesting() final Unit setName(@FlowObservable() String name)
-
getMetadata
@FlowObservable() final String getMetadata()
The metadata for this participant.
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.MetadataChanged event is emitted from events whenever this changes.
-
setMetadata
@VisibleForTesting() final Unit setMetadata(@FlowObservable() String metadata)
-
getAttributes
@FlowObservable() final Map<String, String> getAttributes()
The attributes set on this participant.
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.AttributesChanged event is emitted from events whenever this changes.
-
setAttributes
@VisibleForTesting() final Unit setAttributes(@FlowObservable() Map<String, String> attributes)
-
getAgentAttributes
@FlowObservable() final AgentAttributes getAgentAttributes()
The agent attributes for this participant.
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.AttributesChanged event is emitted from events whenever this changes.
-
setAgentAttributes
final Unit setAgentAttributes(@FlowObservable() AgentAttributes agentAttributes)
The agent attributes for this participant.
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.AttributesChanged event is emitted from events whenever this changes.
-
getPermissions
@FlowObservable() final ParticipantPermission getPermissions()
The permissions for this participant.
Changes can be observed by using io.livekit.android.util.flow
A ParticipantEvent.ParticipantPermissionsChanged event is emitted from events whenever this changes.
-
setPermissions
final Unit setPermissions(@FlowObservable() ParticipantPermission permissions)
-
getConnectionQuality
@FlowObservable() final ConnectionQuality getConnectionQuality()
Changes can be observed by using io.livekit.android.util.flow
-
setConnectionQuality
final Unit setConnectionQuality(@FlowObservable() ConnectionQuality connectionQuality)
-
getJoinedAt
final Long getJoinedAt()
-
getLastSpokeAt
@FlowObservable() final Long getLastSpokeAt()
Timestamp when the participant last started speaking, in milliseconds
-
setLastSpokeAt
final Unit setLastSpokeAt(@FlowObservable() Long lastSpokeAt)
-
getKind
@FlowObservable() final Participant.Kind getKind()
The kind of participant (i.e. a standard client participant, AI agent, etc.)
-
setKind
final Unit setKind(@FlowObservable() Participant.Kind kind)
-
getHasInfo
final Boolean getHasInfo()
-
getTrackPublications
@FlowObservable() final <ERROR CLASS> getTrackPublications()
Maps track sids to their track publications.
Changes can be observed by using io.livekit.android.util.flow
-
setTrackPublications
final Unit )>setTrackPublications(@FlowObservable() <ERROR CLASS> trackPublications)
-
getAudioTrackPublications
@FlowObservable() final <ERROR CLASS> getAudioTrackPublications()
Changes can be observed by using io.livekit.android.util.flow
-
getVideoTrackPublications
@FlowObservable() final <ERROR CLASS> getVideoTrackPublications()
Changes can be observed by using io.livekit.android.util.flow
-
getIsMicrophoneEnabled
@FlowObservable() final <ERROR CLASS> getIsMicrophoneEnabled()
-
getIsCameraEnabled
@FlowObservable() final <ERROR CLASS> getIsCameraEnabled()
-
getIsScreenShareEnabled
@FlowObservable() final <ERROR CLASS> getIsScreenShareEnabled()
-
getSid
final Participant.Sid getSid()
-
setSid
final Unit setSid(Participant.Sid sid)
-
getOrCreateDefaultAudioTrack
final LocalAudioTrack getOrCreateDefaultAudioTrack()
Returns the default audio track, or creates one if it doesn't exist.
-
getOrCreateDefaultVideoTrack
final LocalVideoTrack getOrCreateDefaultVideoTrack()
Returns the default video track, or creates one if it doesn't exist.
-
createAudioTrack
final LocalAudioTrack createAudioTrack(String name, LocalAudioTrackOptions options)
Creates an audio track, recording audio through the microphone with the given options.
- Parameters:
name- The name of the track.options- The capture options to use for this track, or Room.audioTrackCaptureDefaults if none is passed.
-
createVideoTrack
final LocalVideoTrack createVideoTrack(String name, VideoCapturer capturer, LocalVideoTrackOptions options, VideoProcessor videoProcessor)
Creates a video track, recording video through the supplied capturer.
This method will call VideoCapturer.initialize and handle the lifecycle of SurfaceTextureHelper.
- Parameters:
name- The name of the track.capturer- The capturer to use for this track.options- The capture options to use for this track, or Room.videoTrackCaptureDefaults if none is passed.videoProcessor- A video processor to attach to this track that can modify the frames before publishing.
-
createVideoTrack
final LocalVideoTrack createVideoTrack(String name, LocalVideoTrackOptions options, VideoProcessor videoProcessor)
Creates a video track, recording video through the camera with the given options.
Note: If using this in conjunction with setCameraEnabled, ensure that your created camera track is published first before using setCameraEnabled. Otherwise, the LiveKit SDK will attempt to create its own camera track to manage, and will cause issues since generally only one camera session can be active at a time.
- Parameters:
name- The name of the trackoptions- The capture options to use for this track, or Room.videoTrackCaptureDefaults if none is passed.videoProcessor- A video processor to attach to this track that can modify the frames before publishing.
-
createScreencastTrack
final LocalScreencastVideoTrack createScreencastTrack(String name, Intent mediaProjectionPermissionResultData, LocalVideoTrackOptions options, VideoProcessor videoProcessor, Function1<Track, Unit> onStop)
Creates a screencast video track.
- Parameters:
name- The name of the track.mediaProjectionPermissionResultData- The resultData returned from launching MediaProjectionManager.createScreenCaptureIntent().options- The capture options to use for this track, or Room.screenShareTrackCaptureDefaults if none is passed.videoProcessor- A video processor to attach to this track that can modify the frames before publishing.
-
getTrackPublication
LocalTrackPublication getTrackPublication(Track.Source source)
Retrieves the first track that matches the source, or null
-
getTrackPublicationByName
LocalTrackPublication getTrackPublicationByName(String name)
Retrieves the first track that matches name, or null
-
setCameraEnabled
final Boolean setCameraEnabled(Boolean enabled)
If set to enabled, creates and publishes a camera video track if not already done, and starts the camera.
If set to disabled, mutes and stops the camera.
This will use capture and publish default options from Room.
-
setMicrophoneEnabled
final Boolean setMicrophoneEnabled(Boolean enabled)
If set to enabled, creates and publishes a microphone audio track if not already done, and unmutes the mic.
If set to disabled, mutes the mic.
This will use capture and publish default options from Room.
-
setScreenShareEnabled
final Boolean setScreenShareEnabled(Boolean enabled, ScreenCaptureParams screenCaptureParams)
If set to enabled, creates and publishes a screenshare video track.
If set to disabled, unpublishes the screenshare video track.
This will use capture and publish default options from Room.
For screenshare audio, a ScreenAudioCapturer can be used.
- Parameters:
screenCaptureParams- When enabling the screenshare, this must be provided with ScreenCaptureParams.mediaProjectionPermissionResultData containing resultData returned from launching MediaProjectionManager.createScreenCaptureIntent().
-
publishAudioTrack
final Boolean publishAudioTrack(LocalAudioTrack track, AudioTrackPublishOptions options, LocalParticipant.PublishListener publishListener)
Publishes an audio track.
- Parameters:
track- The track to publish.options- The publish options to use, or Room.audioTrackPublishDefaults if none is passed.
-
publishVideoTrack
final Boolean publishVideoTrack(LocalVideoTrack track, VideoTrackPublishOptions options, LocalParticipant.PublishListener publishListener)
Publishes an video track.
- Parameters:
track- The track to publish.options- The publish options to use, or Room.videoTrackPublishDefaults if none is passed.
-
setTrackSubscriptionPermissions
final Unit setTrackSubscriptionPermissions(Boolean allParticipantsAllowed, List<ParticipantTrackPermission> participantTrackPermissions)
Control who can subscribe to LocalParticipant's published tracks.
By default, all participants can subscribe. This allows fine-grained control over who is able to subscribe at a participant and track level.
Note: if access is given at a track-level (i.e. both allParticipantsAllowed and ParticipantTrackPermission.allTracksAllowed are false), any newer published tracks will not grant permissions to any participants and will require a subsequent permissions update to allow subscription.
- Parameters:
allParticipantsAllowed- Allows all participants to subscribe all tracks.participantTrackPermissions- Full list of individual permissions per participant/track.
-
unpublishTrack
final Unit unpublishTrack(Track track, Boolean stopOnUnpublish)
Unpublish a track.
- Parameters:
stopOnUnpublish- if true, stops the track after unpublishing the track.
-
publishData
@CheckResult() final Result<Unit> publishData(ByteArray data, DataPublishReliability reliability, String topic, List<Participant.Identity> identities)
Publish a new data payload to the room. Data will be forwarded to each participant in the room. Each payload must not exceed 15k in size
- Parameters:
data- payload to sendreliability- for delivery guarantee, use RELIABLE.topic- the topic under which the message was publishedidentities- list of participant identities to deliver the payload, null to deliver to everyone
-
publishDtmf
@CheckResult() final Result<Unit> publishDtmf(Integer code, String digit)
This suspend function allows you to publish DTMF (Dual-Tone Multi-Frequency) signals within a LiveKit room. The
publishDtmffunction constructs a SipDTMF message using the provided code and digit, then encapsulates it in a DataPacket before sending it via the engine.- Parameters:
code- an integer representing the DTMF signal codedigit- the string representing the DTMF digit (e.g.
-
registerRpcMethod
Unit registerRpcMethod(String method, SuspendFunction1<RpcInvocationData, String> handler)
Establishes the participant as a receiver for calls of the specified RPC method. Will overwrite any existing callback for the same method.
Example:
room.registerRpcMethod("greet") { (requestId, callerIdentity, payload, responseTimeout) -> Log.i("TAG", "Received greeting from ${callerIdentity}: ${payload}") // Return a string "Hello, ${callerIdentity}!" }The handler receives an RpcInvocationData with the following parameters:
requestId: A unique identifier for this RPC requestcallerIdentity: The identity of the RemoteParticipant who initiated the RPC callpayload: The data sent by the caller (as a string)responseTimeout: The maximum time available to return a response
The handler should return a string. If unable to respond within RpcInvocationData.responseTimeout, the request will result in an error on the caller's side.
You may throw errors of type RpcError with a string
messagein the handler, and they will be received on the caller's side with the message intact. Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as1500("Application Error").- Parameters:
method- The name of the indicated RPC methodhandler- Will be invoked when an RPC request for this method is received
-
unregisterRpcMethod
Unit unregisterRpcMethod(String method)
Unregisters a previously registered RPC method.
- Parameters:
method- The name of the RPC method to unregister
-
performRpc
String performRpc(Participant.Identity destinationIdentity, String method, String payload, Duration responseTimeout)
Initiate an RPC call to a remote participant
- Parameters:
destinationIdentity- The identity of the destination participant.method- The method name to call.payload- The payload to pass to the method.responseTimeout- Timeout for receiving a response after initial connection.
-
updateMetadata
final Unit updateMetadata(String metadata)
Updates the metadata of the local participant. Changes will not be reflected until the server responds confirming the update. Note: this requires
CanUpdateOwnMetadatapermission encoded in the token.
-
updateName
final Unit updateName(String name)
Updates the name of the local participant. Changes will not be reflected until the server responds confirming the update. Note: this requires
CanUpdateOwnMetadatapermission encoded in the token.
-
updateAttributes
final Unit updateAttributes(Map<String, String> attributes)
Set or update participant attributes. It will make updates only to keys that are present in attributes, and will not override others.
To delete a value, set the value to an empty string.
Note: this requires
canUpdateOwnMetadatapermission.- Parameters:
attributes- attributes to update
-
-
-
-