package zello

import java.io.ByteArrayOutputStream

/**
 * Stream audio job for Zello client.
 * @param: codec_header The codec header for the audio stream.
 * @param: packet_duration The duration of each audio packet in milliseconds. Values between 2.5 and 60 ms are supported.
 * @param: channel The channel to which the audio stream belongs.
 * @param: streamID The unique identifier for the audio stream.
 * @param: from The user who is sending the audio stream.
 * @param: For Optional. The user for whom the audio stream is intended. If not specified, the audio is sent to the channel.
 */
@Suppress("unused")
class ZelloAudioJob(codec_header: String, packet_duration: Int, val channel: String, val streamID: Int, val from: String, val For: String?=null) {
    val type = "audio"  // must be "audio" for audio jobs
    val codec = "opus" // Default audio codec
    private val baos = ByteArrayOutputStream()
    fun pushAudioData(data: ByteArray){
        baos.write(data)
    }
    fun getAudioData(): ByteArray {
        return baos.toByteArray()
    }
    companion object {
        fun fromEventOnStreamStart(x : Event_OnStreamStart) : ZelloAudioJob {
            return ZelloAudioJob(
                x.codec_header,
                x.packet_duration,
                x.channel,
                x.stream_id,
                x.from,
                x.For
            )
        }
    }
}