DeviceStore

abstract class DeviceStore

Device related interfaces, operating microphone, camera, etc.

Overview

DeviceStore Device management class for handling host camera, microphone and other business. DeviceStore provides a comprehensive set of APIs to manage audio and video devices, including microphone, camera and screen sharing features.

Core Features

  • Microphone Management: Open/close microphone, set capture volume and output volume

  • Camera Management: Open/close camera, switch front/rear camera, set mirror and video quality

  • Audio Route: Switch between speaker and earpiece

  • Screen Sharing: Start and stop screen sharing feature

  • Network Status: Real-time monitoring of network quality information

Important: Use DeviceStore.shared singleton to get the DeviceStore instance. Do not attempt to initialize directly. Device state updates are delivered through the deviceState publisher. Subscribe to it to receive real-time updates about microphone, camera, network and other states.

Device Operations Overview

FeatureMethodDescription
MicrophoneopenLocalMicrophone/closeLocalMicrophoneOpen/close local microphone
CameraopenLocalCamera/closeLocalCameraOpen/close local camera
Audio RoutesetAudioRouteSwitch speaker/earpiece
Screen SharingstartScreenShare/stopScreenShareStart/stop screen sharing
Volume ControlsetCaptureVolume/setOutputVolumeSet capture/output volume

Usage Example

// Get singleton instance
val store = DeviceStore.shared()

// Subscribe to state changes
lifecycleScope.launch {
store.deviceState.microphoneStatus.collect { status ->
println("Microphone status: $status")
}
}

lifecycleScope.launch {
store.deviceState.cameraStatus.collect { status ->
println("Camera status: $status")
}
}

// Open microphone
store.openLocalMicrophone { code, message ->
if (code == 0) {
println("Microphone opened successfully")
}
}

// Open front camera
store.openLocalCamera(isFront = true) { code, message ->
if (code == 0) {
println("Camera opened successfully")
}
}

Topics

Getting Instance

Observing State

  • deviceState - Reactive state containing microphone, camera, network and other device states

Microphone Operations

Audio Route

Camera Operations

Screen Sharing

Reset

  • reset - Reset to default state

See Also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Singleton object

Properties

Link copied to clipboard
abstract val deviceState: DeviceState

State

Functions

Link copied to clipboard
abstract fun closeLocalCamera()

Close local camera

Link copied to clipboard
abstract fun closeLocalMicrophone()

Close local microphone

Link copied to clipboard
abstract fun openLocalCamera(isFront: Boolean, completion: CompletionHandler?)

Open local camera

Link copied to clipboard
abstract fun openLocalMicrophone(completion: CompletionHandler?)

Open local microphone

Link copied to clipboard
abstract fun reset()

Reset to default state

Link copied to clipboard
abstract fun setAudioRoute(audioRoute: AudioRoute)

Set audio route

Link copied to clipboard
abstract fun setCaptureVolume(volume: Int)

Set capture volume

Link copied to clipboard
abstract fun setOutputVolume(volume: Int)

Set maximum output volume

Link copied to clipboard
abstract fun startCameraTest(cameraView: CameraView, completion: CompletionHandler?)

Start camera test, if camera opens successfully, the view will be rendered to the set CameraView

Link copied to clipboard
abstract fun startScreenShare()

Start screen sharing

Link copied to clipboard
abstract fun stopCameraTest()

Stop camera test

Link copied to clipboard
abstract fun stopScreenShare()

Stop screen capture

Link copied to clipboard
abstract fun switchCamera(isFront: Boolean)

Switch camera

Link copied to clipboard
abstract fun switchMirror(mirrorType: MirrorType)

Switch mirror state

Link copied to clipboard
abstract fun updateVideoQuality(quality: VideoQuality)

Update video quality