From 573022078db882e607d0d39465d6501021a6643c Mon Sep 17 00:00:00 2001 From: Aakash Sharma Date: Tue, 22 Sep 2026 10:04:39 +0530 Subject: [PATCH] fix(rtmp): setLogs(false) now also silences the command logs RtmpClient.setLogs() only reached RtmpSender, so the command logs in CommandsManager and CommandsManagerImp were emitted unconditionally. Those lines print the message as it goes on the wire: send $connect -> includes tcUrl send $releaseStream / $fcPublish / $publish -> include the stream name read $message -> the server's onStatus reply, which echoes the stream name On YouTube Live, Twitch and most other services the stream name IS the stream key, so an app has no way to keep a publishing credential out of logcat. CommandsManager gains isEnableLogs, defaulting to true so nothing changes unless an app opts out, the info-level command logs are guarded by it, and setLogs() now forwards to the commands manager as well as the sender. Log.e is untouched. Co-Authored-By: Claude Opus 5 (1M context) --- .../com/pedro/rtmp/rtmp/CommandsManager.kt | 21 +++++++++++++------ .../com/pedro/rtmp/rtmp/CommandsManagerImp.kt | 14 ++++++------- .../java/com/pedro/rtmp/rtmp/RtmpClient.kt | 1 + 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt b/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt index 6509debdc..945026639 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManager.kt @@ -61,6 +61,15 @@ abstract class CommandsManager { val config = RtmpConfig() var audioDisabled = false var videoDisabled = false + /** + * Controlled by [com.pedro.rtmp.rtmp.RtmpClient.setLogs]. + * + * The command logs print the message as it goes on the wire, which for + * connect/releaseStream/FCPublish/publish includes the tcUrl and the + * stream name. On most services the stream name IS the stream key, so + * these lines put a publishing credential in logcat. + */ + var isEnableLogs = true var customAmfObject: Map = emptyMap() var customMetadata: Map = emptyMap() private var bytesRead = 0 @@ -110,9 +119,9 @@ abstract class CommandsManager { chunkSize.writeHeader(socket) chunkSize.writeBody(socket, config.writeChunkSize) socket.flush() - Log.i(TAG, "send $chunkSize") + if (isEnableLogs) Log.i(TAG, "send $chunkSize") } else { - Log.i(TAG, "using default write chunk size ${RtmpConfig.DEFAULT_CHUNK_SIZE}") + if (isEnableLogs) Log.i(TAG, "using default write chunk size ${RtmpConfig.DEFAULT_CHUNK_SIZE}") } } } @@ -137,7 +146,7 @@ abstract class CommandsManager { suspend fun readMessageResponse(socket: RtmpSocket): RtmpMessage { val message = RtmpMessage.getRtmpMessage(socket, config.readChunkSize, sessionHistory) sessionHistory.setReadHeader(message.header) - Log.i(TAG, "read $message") + if (isEnableLogs) Log.i(TAG, "read $message") bytesRead += message.header.getPacketLength() return message } @@ -174,7 +183,7 @@ abstract class CommandsManager { pong.writeHeader(socket) pong.writeBody(socket, config.writeChunkSize) socket.flush() - Log.i(TAG, "send pong") + if (isEnableLogs) Log.i(TAG, "send pong") } } @@ -184,7 +193,7 @@ abstract class CommandsManager { ping.writeHeader(socket) ping.writeBody(socket, config.writeChunkSize) socket.flush() - Log.i(TAG, "send ping") + if (isEnableLogs) Log.i(TAG, "send ping") } } @@ -204,7 +213,7 @@ abstract class CommandsManager { acknowledgement.writeHeader(socket) acknowledgement.writeBody(socket, config.writeChunkSize) socket.flush() - Log.i(TAG, "send $acknowledgement") + if (isEnableLogs) Log.i(TAG, "send $acknowledgement") } } } diff --git a/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManagerImp.kt b/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManagerImp.kt index c0a10c040..6631a19a0 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManagerImp.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/rtmp/CommandsManagerImp.kt @@ -71,7 +71,7 @@ class CommandsManagerImp: CommandsManager() { connect.writeHeader(socket) connect.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, "connect") - Log.i(TAG, "send $connect") + if (isEnableLogs) Log.i(TAG, "send $connect") } override suspend fun createStreamImp(socket: RtmpSocket) { @@ -83,7 +83,7 @@ class CommandsManagerImp: CommandsManager() { releaseStream.writeHeader(socket) releaseStream.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, "releaseStream") - Log.i(TAG, "send $releaseStream") + if (isEnableLogs) Log.i(TAG, "send $releaseStream") val fcPublish = Command("FCPublish", ++commandId, getCurrentTimestamp(), streamId, BasicHeader(ChunkType.TYPE_0, ChunkStreamId.OVER_STREAM.mark)) @@ -93,7 +93,7 @@ class CommandsManagerImp: CommandsManager() { fcPublish.writeHeader(socket) fcPublish.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, "FCPublish") - Log.i(TAG, "send $fcPublish") + if (isEnableLogs) Log.i(TAG, "send $fcPublish") val createStream = Command("createStream", ++commandId, getCurrentTimestamp(), streamId, BasicHeader(ChunkType.TYPE_0, ChunkStreamId.OVER_CONNECTION.mark)) @@ -102,7 +102,7 @@ class CommandsManagerImp: CommandsManager() { createStream.writeHeader(socket) createStream.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, "createStream") - Log.i(TAG, "send $createStream") + if (isEnableLogs) Log.i(TAG, "send $createStream") } override suspend fun sendMetadataImp(socket: RtmpSocket) { @@ -146,7 +146,7 @@ class CommandsManagerImp: CommandsManager() { metadata.writeHeader(socket) metadata.writeBody(socket, config.writeChunkSize) - Log.i(TAG, "send $metadata") + if (isEnableLogs) Log.i(TAG, "send $metadata") } override suspend fun sendPublishImp(socket: RtmpSocket) { @@ -160,7 +160,7 @@ class CommandsManagerImp: CommandsManager() { publish.writeHeader(socket) publish.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, name) - Log.i(TAG, "send $publish") + if (isEnableLogs) Log.i(TAG, "send $publish") } override suspend fun sendCloseImp(socket: RtmpSocket) { @@ -171,6 +171,6 @@ class CommandsManagerImp: CommandsManager() { closeStream.writeHeader(socket) closeStream.writeBody(socket, config.writeChunkSize) sessionHistory.setPacket(commandId, name) - Log.i(TAG, "send $closeStream") + if (isEnableLogs) Log.i(TAG, "send $closeStream") } } \ No newline at end of file diff --git a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt index 43f3d30ce..ba4c40750 100644 --- a/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt +++ b/rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt @@ -641,6 +641,7 @@ class RtmpClient(private val connectChecker: ConnectChecker) { fun setLogs(enable: Boolean) { rtmpSender.setLogs(enable) + commandsManager.isEnableLogs = enable } fun clearCache() {