DeviceStore
Introduction
DeviceStore provides a comprehensive set of APIs to manage audio and video devices, including microphone, camera and screen sharing features.
Important:
Use shared singleton to get the DeviceStore instance. Do not attempt to initialize directly.
Note:
Device state updates are delivered through the state publisher. Subscribe to it to receive real-time updates about microphone, camera, network and other states.
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
Subscribable Data
DeviceState fields are described below:
Property | Type | Description |
microphoneStatus | Microphone status. | |
microphoneLastError | Microphone error, used to extract error information when an error occurs. | |
captureVolume | Int | Capture volume, range [0, 100]. |
currentMicVolume | Int | Current user's actual output volume. |
outputVolume | Int | Maximum output volume, range [0, 100]. |
cameraStatus | Camera status. | |
cameraLastError | Camera error, used to extract error information when an error occurs. | |
isFrontCamera | Bool | Whether it's front camera. |
localMirrorType | Mirror state. | |
localVideoQuality | Local video quality. | |
currentAudioRoute | Current audio route location. | |
screenStatus | Screen sharing status. | |
networkInfo | Network information. |
API List
Function | Description |
Singleton object. | |
Open local microphone. | |
Close local microphone. | |
Set capture volume. | |
Set output volume. | |
Set audio route. | |
Start camera test. | |
Stop camera test. | |
Open local camera. | |
Close local camera. | |
Switch camera. | |
Switch mirror state. | |
Update video quality. | |
Start screen sharing. | |
Stop screen sharing. | |
Reset to default state. |
Getting Instance
shared
Singleton object
Microphone Operations
openLocalMicrophone
Open local microphone
public func openLocalMicrophone(completion: CompletionClosure?) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
completion | Required | Whether operation succeeded. |
closeLocalMicrophone
Close local microphone
public func closeLocalMicrophone() {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
setCaptureVolume
Set capture volume
public func setCaptureVolume(volume: Int) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
volume | Int | Required | Capture volume, range [0, 100]. |
setOutputVolume
Set maximum output volume
public func setOutputVolume(_ volume: Int) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
volume | Int | Required | Maximum volume, range [0, 100]. |
Audio Route
setAudioRoute
Set audio route
public func setAudioRoute(_ route: AudioRoute) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
route | Required | Route location. |
Camera Operations
startCameraTest
Start camera test, if camera opens successfully, the view will be rendered to the set CameraView
public func startCameraTest(cameraView: UIView,completion: CompletionClosure?) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
cameraView | UIView | Required | Rendering view for camera capture. |
completion | Required | Whether operation succeeded. |
stopCameraTest
Stop camera test
public func stopCameraTest() {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
openLocalCamera
Open local camera
public func openLocalCamera(isFront: Bool,completion: CompletionClosure?) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
isFront | Bool | Required | Whether front camera. |
completion | Required | Whether operation succeeded. |
closeLocalCamera
Close local camera
public func closeLocalCamera() {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
switchCamera
Switch camera
public func switchCamera(isFront: Bool) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
isFront | Bool | Required | Whether front camera. |
switchMirror
Switch mirror state
public func switchMirror(mirrorType: MirrorType) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
mirrorType | Required | Mirror state. |
updateVideoQuality
Update video quality
public func updateVideoQuality(_ quality: VideoQuality) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
quality | Required | Video quality. |
Screen Sharing
startScreenShare
Start screen sharing
public func startScreenShare(appGroup: String) {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Parameters
Parameter | Type | Required | Description |
appGroup | String | Required | App Group ID. |
stopScreenShare
Stop screen capture
public func stopScreenShare() {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Reset
reset
Reset to default state
public func reset() {fatalError("\(#function) must be overridden by subclass")}
Version
Supported since version 3.5.
Data Structures
DeviceType
Device type
Enum Value | Value | Description |
microphone | 0 | Microphone type. |
camera | 1 | Camera type. |
screenShare | 2 | Screen sharing type. |
DeviceError
Device related error codes
Enum Value | Value | Description |
noError | 0 | Operation successful. |
noDeviceDetected | 1 | No device detected. |
noSystemPermission | 2 | No system permission. |
notSupportCapture | 3 | Capture not supported. |
occupiedError | 4 | Device occupied. |
unknownError | 5 | Unknown error. |
DeviceStatus
Device on/off status
Enum Value | Value | Description |
off | 0 | Off. |
on | 1 | On. |
AudioRoute
Audio route
Enum Value | Value | Description |
speakerphone | 0 | Speaker, using speaker to play (i.e., "hands-free"), located at the bottom of the phone, louder sound, suitable for playing music out loud. |
earpiece | 1 | Earpiece, using earpiece to play, located at the top of the phone, quieter sound, suitable for private call scenarios. |
VideoQuality
Video quality
Enum Value | Value | Description |
quality360P | 1 | 360P. |
quality540P | 2 | 540P. |
quality720P | 3 | 720P. |
quality1080P | 4 | 1080P. |
NetworkQuality
Network quality
Enum Value | Value | Description |
unknown | 0 | Unknown network. |
excellent | 1 | Excellent. |
good | 2 | Good. |
poor | 3 | Poor. |
bad | 4 | Bad. |
veryBad | 5 | Very bad. |
down | 6 | Disconnected. |
MirrorType
Camera mirror state
Enum Value | Value | Description |
auto | 0 | Auto, front camera mirrored, rear camera not mirrored. |
enable | 1 | Both front and rear cameras mirrored. |
disable | 2 | Neither front nor rear camera mirrored. |
DeviceFocusOwner
Device focus
Enum Value | Description |
call | Voice call scenario. |
live | Live streaming scenario. |
none | Not set. |
NetworkInfo
Network information
Property | Type | Description |
userID | String | User unique ID. |
quality | Network quality. | |
upLoss | UInt32 | Uplink packet loss rate, range [0, 100]. |
downLoss | UInt32 | Downlink packet loss rate, range [0, 100]. |
delay | UInt32 | Latency (unit: milliseconds). |
DeviceState
Device state
Property | Type | Description |
microphoneStatus | Microphone status. | |
microphoneLastError | Microphone error, used to extract error information when an error occurs. | |
captureVolume | Int | Capture volume, range [0, 100]. |
currentMicVolume | Int | Current user's actual output volume. |
outputVolume | Int | Maximum output volume, range [0, 100]. |
cameraStatus | Camera status. | |
cameraLastError | Camera error, used to extract error information when an error occurs. | |
isFrontCamera | Bool | Whether it's front camera. |
localMirrorType | Mirror state. | |
localVideoQuality | Local video quality. | |
currentAudioRoute | Current audio route location. | |
screenStatus | Screen sharing status. | |
networkInfo | Network information. |
Usage Example
// Get singleton instancelet store = DeviceStore.shared// Subscribe to state changesstore.state.subscribe { state inprint("Microphone status: \(state.microphoneStatus)")print("Camera status: \(state.cameraStatus)")print("Network quality: \(state.networkInfo.quality)")}// Open microphonestore.openLocalMicrophone { code, message inif code == 0 {print("Microphone opened successfully")}}// Open front camerastore.openLocalCamera(isFront: true) { code, message inif code == 0 {print("Camera opened successfully")}}