Skip to content

Commit

Permalink
Add documentation for anroid audio preview part
Browse files Browse the repository at this point in the history
  • Loading branch information
kbetl-dlb committed Jul 6, 2023
1 parent 8d1f635 commit 3a24094
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package io.dolby.sdk.comms.reactnative.eventemitters
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactApplicationContext
import com.voxeet.android.media.capture.audio.preview.RecorderStatus
import com.voxeet.sdk.models.Participant
import com.voxeet.sdk.services.AudioService
import com.voxeet.sdk.services.ConferenceService

/**
* The audio preview event emitter
* @param reactContext react application context for sending event
* @param audioService [AudioService] from Android SDK
*/
class RNAudioPreviewEventEmitter (
reactContext: ReactApplicationContext,
private val audioService: AudioService
) : RNEventEmitter(reactContext) {
private var isRegister = false

/**
* Emitted when the application user received an audio preview status changed.
*/
private val previewCallback: (RecorderStatus) -> Unit = { status ->
android.util.Log.d(TAG, "onStatusChanged status: ${status.name}")
if (isRegister) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.dolby.sdk.comms.reactnative.services.audio
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.voxeet.sdk.services.AudioService
import com.voxeet.sdk.services.MediaDeviceService
import com.voxeet.sdk.services.audio.LocalAudio
import io.dolby.sdk.comms.reactnative.eventemitters.RNAudioPreviewEventEmitter
import io.dolby.sdk.comms.reactnative.mapper.AudioMapper
Expand All @@ -12,6 +14,17 @@ import io.dolby.sdk.comms.reactnative.utils.Promises.forward
import io.dolby.sdk.comms.reactnative.utils.Promises.thenValue
import io.dolby.sdk.comms.reactnative.utils.ReactPromise

/**
* The [RNAudioPreviewModule] allows recording and playing audio sample to test audio before joinning conference
* checking the capture mode and comfort noise level.
*
* @constructor
* Creates a bridge wrapper for [com.voxeet.sdk.services.audio.AudioPreview] model.
*
* @param reactContext react context
* @param localAudio [LocalAudio] from Android SDK
* @param audioMapper mapper for a audio related models
*/
class RNAudioPreviewModule(
reactContext: ReactApplicationContext,
eventEmitter: RNAudioPreviewEventEmitter,
Expand All @@ -20,19 +33,34 @@ class RNAudioPreviewModule(
) : RNEventEmitterModule(reactContext, eventEmitter) {
override fun getName() = "CommsAPIAudioPreviewModule"

/**
* Returns the audio preview status.
*
* @param promise returns preview status
*/
@ReactMethod
fun status(promise: ReactPromise) {
Promises.promise(localAudio.preview().status.name)
.forward(promise)
}

/**
* Returns the local participant's audio capture mode from audio preview.
*
* @param promise returns capture mode
*/
@ReactMethod
fun getCaptureMode(promise: ReactPromise) {
Promises.promise(localAudio.preview().captureMode) { "Could not get capture mode" }
.thenValue(audioMapper::audioCaptureToRN)
.forward(promise)
}

/**
* Sets the local participant's audio capture mode in audio preview.
*
* @param promise returns null
*/
@ReactMethod
fun setCaptureMode(captureMode: ReadableMap, promise: ReactPromise) {
Promises.promise({ audioMapper.audioCaptureFromRN(captureMode) }) { "Invalid capture mode" }
Expand All @@ -42,27 +70,47 @@ class RNAudioPreviewModule(
.forward(promise, ignoreReturnType = true)
}

/**
* Starts recording an audio sample if no recording is in progress. This method requires the Android AudioRecord permission.
* Calling this method without the permission granted results in the promise to reject the call.
* @param The preferred recording duration that ranges from 0 to 5, in seconds.
* @param promise returns null
*/
@ReactMethod
fun record(duration: Int?, promise: ReactPromise) {
Promises.promise({ duration }) { "Invalid params: duration is required" }
.thenValue { d ->
localAudio.preview().record(d)
}
.forward(promise)
.forward(promise, ignoreReturnType = true)
}

/**
* Plays back the recorded audio sample. To test how your audio sounds while using different capture modes and voice fonts,
* set the setCaptureMode method to a preferred setting before using the method.
* @param loop A boolean that indicates whether the SDK should play the recorded audio in a loop.
* @param promise returns null
*/
@ReactMethod
fun play(loop: Boolean, promise: ReactPromise) {
localAudio.preview().play(loop)
.forward(promise)
.forward(promise, ignoreReturnType = true)
}

/**
* Cancels recording or playing an audio sample.
* @param promise return Boolean
*/
@ReactMethod
fun cancel(promise: ReactPromise) {
Promises.promise({ localAudio.preview().cancel() })
.forward(promise)
}

/**
* Release the internal memory and restart the audio session configuration.
* @param promise returns null
*/
@ReactMethod
fun release(promise: ReactPromise) {
Promises.promise({ localAudio.preview().release() })
Expand Down

0 comments on commit 3a24094

Please sign in to comment.