run When Connected
fun runWhenConnected( name: String? = null, oneshot: Boolean = false, task: PolyOsManager.() -> Unit)
Content copied to clipboard
Runs the given task if/when connected.
By default the given task is run each time PolyOsManager gets connected.
Since
3.12.0.0-11
Samples
import android.content.Context
import com.poly.polyos.AppState
import com.poly.polyos.PolyOsManager
import com.poly.polyos.audio.IPolyAudioListener
import com.poly.polyos.room.IPolyRoomListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
fun main() {
//sampleStart
//register listeners whenever polyos gets connected/reconnected
polyOsManager.runWhenConnected {
//Register for audio notifications
audioService.registerAudioListener(audioListener)
//Register for messages
roomService.registerRoomListener(roomListener)
}
//Perform a one time task on first connection
polyOsManager.runWhenConnected (oneshot = true) {
val muted = audioService.isMicrophoneMuted
println( "Audio is muted: $muted")
}
//sampleEnd
}See also
Parameters
name
Optional name for the task.
oneshot
Specify whether this is a one time task or not. Default false. Set this to true if the task needs to be run only once.