chirpsdk / io.chirp.chirpsdk / ChirpSDK

ChirpSDK

class ChirpSDK : Closeable

The ChirpSDK SDK allows the user to send and receive data via sound. Requires an app_key, app_secret and a config string which you can download from developers.chirp.io Only one single instance should be instantiated per application. The SDK extends java closeable interface

Constructors

<init>

ChirpSDK(context: <ERROR CLASS>, appKey: String, appSecret: String, settingsContentObserver: SettingsContentObserver? = null)

The ChirpSDK SDK allows the user to send and receive data via sound. Requires an app_key, app_secret and a config string which you can download from developers.chirp.io Only one single instance should be instantiated per application. The SDK extends java closeable interface

Properties

audioFocusType

var audioFocusType: Int

audioFocusType - set/get audioFocus type Default value = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK Available to use only after settingsContentObserver is ready available options:

systemVolume

var systemVolume: Float

Set and get system volume level in Float from 0.0f to 1.0f Available to use only after settingsContentObserver is ready

version

val version: String

The full version string of the SDK and audio engine.

Functions

close

fun close(): Unit

Close the SDK. Required to be called when you no longer need to use the SDK. This will delete Audio I/O, and free the memory used by the SDK.

getChannelCount

fun getChannelCount(): Int

Get the number of available channels for the current config.

getChannelState

fun getChannelState(channel: Int): ChirpSDKState

Get the current channel state of the SDK. Use getChannelCount to get the number of available channels.

getDurationForPayloadLength

fun getDurationForPayloadLength(payloadLength: Int): Float

Get the duration in seconds for a specified payload length.

getProtocolName

fun getProtocolName(): String

Get the protocol name for the current config.

getProtocolVersion

fun getProtocolVersion(): Int

Get the protocol version for the current config.

getState

fun getState(): ChirpSDKState

Get the current state of the SDK.

getTransmissionChannel

fun getTransmissionChannel(): Int

Get current channel number that Chirp signals are being sent over. Each channel corresponds to a different frequency band. Defaults to zero. Standard Chirp protocols typically only support a single channel. For multi-channel support, please get in touch developers@chirp.io

isValidPayload

fun isValidPayload(payload: ByteArray): ChirpError

Check whether a payload is valid and able to be sent using the ChirpSDK as it is currently configured via its config.

maxPayloadLength

fun maxPayloadLength(): Int

The maximum payload size, in bytes, that the SDK’s current config permits.

onReceived

fun onReceived(onReceivedCallback: (payload: ByteArray?, channel: Int) -> Unit): Unit

Set onReceived Unit callback. Will be triggered when data is received.

onReceiving

fun onReceiving(onReceivingCallback: (channel: Int) -> Unit): Unit

Set onReceiving Unit callback. Will be triggered when a payload will be detected. Will be followed by onReceived callback

onSending

fun onSending(onSendingCallback: (payload: ByteArray, channel: Int) -> Unit): Unit

Set onSending Unit callback. Will be triggered when a payload will start to be playing. Will be followed by onSent callback

onSent

fun onSent(onSentCallback: (payload: ByteArray, channel: Int) -> Unit): Unit

Set onSent Unit callback. Will be triggered when a payload is sent.

onSettingsContentObserverReady

fun onSettingsContentObserverReady(onSettingsContentObserverReadyCallback: () -> Unit): Unit

If SettingsContentObserver is not set through constructor, this will be automatically created withing the SDK, however because this requires new Handlers, it needs to create a new thread which takes a while to be completed. onSettingsContentObserverReady will be called when SettingsContentObserver is fully created and functional

onStateChanged

fun onStateChanged(onStateChangedCallback: (oldState: ChirpSDKState, newState: ChirpSDKState) -> Unit): Unit

Set onStateChanged Unit callback. Will be triggered when the SDK state will change.

onSystemVolumeChanged

fun onSystemVolumeChanged(onSystemVolumeChanged: (oldVolume: Float, newVolume: Float) -> Unit): Unit

Set onSystemVolumeChanged Unit callback. Will be triggered when system volume will change.

randomPayload

fun randomPayload(size: Int): ByteArray

Generate random data of a specific size. If the SDK will fail to generate data (for ex: config is not set), it will return an empty ByteArray.

fun randomPayload(): ByteArray

Generate random data which is guaranteed to be valid for the ChirpSDK’s current config. If the SDK will fail to generate data (for ex: config is not set), it will return an empty ByteArray.

send

fun send(payload: ByteArray): ChirpError

Send data. The data parameter must be a ByteArray that is within the size of the maximum payload size set by the config. You can check the maximum payload size using the maxPayloadLength method. You can also check if the payload is valid with isValidPayload method

setConfig

fun setConfig(config: String): ChirpError

Set the config to use within the SDK. This configures audio transmission properties, and must be done before starting the SDK via the start method. Config strings can be downloaded from the Chirp developer hub at https://developers.chirp.io.

setConfigFromNetwork

fun setConfigFromNetwork(callback: (success: Boolean, error: ChirpError?) -> Unit): Unit
fun setConfigFromNetwork(listener: ChirpSetConfigListener): ChirpError

Set your default app config by fetching it from the Chirp REST API. This should typically only be used in cases in which you want your configuration to be generated dynamically – for example, if you are rapidly prototyping different transmission settings with Chirp.

setContentObserverReadyListener

fun setContentObserverReadyListener(listener: SettingsContentObserverReady): Unit

Set SettingsContentObserverReady listener, identical to onSettingsContentObserverReady but for easier java usage

setListenToSelf

fun setListenToSelf(selfToListen: Boolean): ChirpError

Enables the SDK to detect its own payloads that are sent.

setListener

fun setListener(listener: ChirpEventListener): Unit

Set ChirpEventListener which is made of all SDK event interfaces.

setRandomSeed

fun setRandomSeed(seed: Int): ChirpError

Set the random seed used by the SDK. This is useful if you want to control the sequence of random payloads generated by randomPayload method

setTransmissionChannel

fun setTransmissionChannel(channel: Int): ChirpError

Set current channel number that Chirp signals are being sent over. Each channel corresponds to a different frequency band. Defaults to zero. Standard Chirp protocols typically only support a single channel. For multi-channel support, please get in touch developers@chirp.io

setVolume

fun setVolume(volume: Float): ChirpError

Set the software volume of the SDK. This is not the overall system volume, just the volume of the chirp output into the main audio mix.

start

fun start(send: Boolean = true, receive: Boolean = true): ChirpError

Start the SDK. Sender and Receiver are enabled by default. NOTE: Microphone permissions are required when receiver is enabled. The config must be set before triggering this method.

stop

fun stop(): ChirpError

Stop the SDK running.