Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.net.ssl.TrustManager
* Created by pedro on 12/10/23.
*/
class RtmpStreamClient(
private val rtmpClient: RtmpClient,
private val rtmpClient: RtmpClient,
private val streamClientListener: StreamClientListener?
): StreamBaseClient() {

Expand Down Expand Up @@ -174,4 +174,8 @@ class RtmpStreamClient(
override fun setSocketType(type: SocketType) {
rtmpClient.socketType = type
}

fun setCustomAmfObject(amfObject: Map<String, Any>) {
rtmpClient.setCustomAmfObject(amfObject)
}
}
26 changes: 26 additions & 0 deletions rtmp/src/main/java/com/pedro/rtmp/amf/v0/AmfObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ open class AmfObject(private val properties: LinkedHashMap<AmfString, AmfData> =
bodySize += data.getSize() + 1
}

open fun setProperty(name: String, data: Any) {
val newValue: AmfData = when (data) {
is String -> AmfString(data)
is Int -> AmfNumber(data.toDouble())
is Long -> AmfNumber(data.toDouble())
is Double -> AmfNumber(data)
is Float -> AmfNumber(data.toDouble())
is Boolean -> AmfBoolean(data)
is AmfData -> data
else -> throw IllegalArgumentException(
"Unsupported value type: ${data::class.java.name}"
)
}

val existingEntry = properties.entries.find { it.key.value == name }

if (existingEntry != null) {
properties[existingEntry.key] = newValue
bodySize += newValue.getSize() - existingEntry.value.getSize()
} else {
val key = AmfString(name)
properties[key] = newValue
bodySize += key.getSize() + newValue.getSize() + 1
}
}

fun getProperties() = properties

@Throws(IOException::class)
Expand Down
1 change: 1 addition & 0 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ abstract class CommandsManager {
var readChunkSize = RtmpConfig.DEFAULT_CHUNK_SIZE
var audioDisabled = false
var videoDisabled = false
var customAmfObject: Map<String, Any> = emptyMap()
private var bytesRead = 0
private var acknowledgementSequence = 0

Expand Down
5 changes: 5 additions & 0 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManagerAmf0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class CommandsManagerAmf0: CommandsManager() {
}
}
connectInfo.setProperty("objectEncoding", 0.0)

// Inject other custom AMF fields as-is
customAmfObject.forEach { (key, value) ->
connectInfo.setProperty(key, value)
}
connect.addData(connectInfo)

connect.writeHeader(socket)
Expand Down
4 changes: 4 additions & 0 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
}
}

fun setCustomAmfObject(amfObject: Map<String, Any>) {
commandsManager.customAmfObject = amfObject
}

fun setAuthorization(user: String?, password: String?) {
commandsManager.setAuth(user, password)
}
Expand Down