Skip to content

Commit 749929e

Browse files
authored
Merge pull request #2037 from pedroSG94/ignoredcomandcallback
add setIgnoredCommandCallback to rtmp
2 parents 74599b5 + c4aa283 commit 749929e

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

library/src/main/java/com/pedro/library/util/streamclient/RtmpStreamClient.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class RtmpStreamClient(
2828
private val streamClientListener: StreamClientListener?
2929
): StreamBaseClient() {
3030

31+
fun setIgnoredCommandCallback(callback: ((String) -> Unit)?) {
32+
rtmpClient.setIgnoredCommandCallback(callback)
33+
}
34+
3135
/**
3236
* Must be called before start stream or will be ignored.
3337
*

rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
9494
private var reTries = 0
9595
private var checkServerAlive = false
9696
private var publishPermitted = false
97+
private var ignoredCommandReceived: ((String) -> Unit)? = null
9798

9899
val droppedAudioFrames: Long
99100
get() = rtmpSender.getDroppedAudioFrames()
@@ -144,6 +145,10 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
144145
}
145146
}
146147

148+
fun setIgnoredCommandCallback(callback: ((String) -> Unit)?) {
149+
ignoredCommandReceived = callback
150+
}
151+
147152
/**
148153
* Check periodically if server is alive using Echo protocol.
149154
*/
@@ -424,9 +429,7 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
424429
when (commandName) {
425430
"connect" -> {
426431
if (commandsManager.onAuth) {
427-
onMainThread {
428-
connectChecker.onAuthSuccess()
429-
}
432+
onMainThread { connectChecker.onAuthSuccess() }
430433
commandsManager.onAuth = false
431434
}
432435
commandsManager.createStream(socket)
@@ -520,15 +523,19 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
520523
}
521524
}
522525
else -> {
523-
Log.i(TAG, "onStatus $code response received from ${commandName ?: "unknown command"}")
526+
val message = "onStatus $code response received from ${commandName ?: "unknown command"}"
527+
Log.i(TAG, message)
528+
ignoredCommandReceived?.let { onMainThread { it.invoke(message) } }
524529
}
525530
}
526531
} catch (e: ClassCastException) {
527532
Log.e(TAG, "error parsing onStatus command", e)
528533
}
529534
}
530535
else -> {
531-
Log.i(TAG, "unknown ${command.name} response received from ${commandName ?: "unknown command"}")
536+
val message = "unknown ${command.name} response received from ${commandName ?: "unknown command"}"
537+
Log.i(TAG, message)
538+
ignoredCommandReceived?.let { onMainThread { it.invoke(message) } }
532539
}
533540
}
534541
}

0 commit comments

Comments
 (0)