From a301bdeb76a58ee411635c83e744fee6d1f0e561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 9 Dec 2024 03:11:54 +0100 Subject: [PATCH] Store data channel label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Getting the label is no longer possible once the data channel has been disposed. This will help to make the observer thread-safe. Signed-off-by: Daniel Calviño Sánchez --- .../com/nextcloud/talk/webrtc/PeerConnectionWrapper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java index 7bc1f0469..08da1f726 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java @@ -400,9 +400,11 @@ public class PeerConnectionWrapper { private class DataChannelObserver implements DataChannel.Observer { private final DataChannel dataChannel; + private final String dataChannelLabel; public DataChannelObserver(DataChannel dataChannel) { this.dataChannel = Objects.requireNonNull(dataChannel); + this.dataChannelLabel = dataChannel.label(); } @Override @@ -412,7 +414,7 @@ public class PeerConnectionWrapper { @Override public void onStateChange() { - if (dataChannel.state() == DataChannel.State.OPEN && "status".equals(dataChannel.label())) { + if (dataChannel.state() == DataChannel.State.OPEN && "status".equals(dataChannelLabel)) { for (DataChannelMessage dataChannelMessage: pendingDataChannelMessages) { send(dataChannelMessage); } @@ -427,7 +429,7 @@ public class PeerConnectionWrapper { @Override public void onMessage(DataChannel.Buffer buffer) { if (buffer.binary) { - Log.d(TAG, "Received binary data channel message over " + dataChannel.label() + " " + sessionId); + Log.d(TAG, "Received binary data channel message over " + dataChannelLabel + " " + sessionId); return; } @@ -435,7 +437,7 @@ public class PeerConnectionWrapper { final byte[] bytes = new byte[data.capacity()]; data.get(bytes); String strData = new String(bytes); - Log.d(TAG, "Received data channel message (" + strData + ") over " + dataChannel.label() + " " + sessionId); + Log.d(TAG, "Received data channel message (" + strData + ") over " + dataChannelLabel + " " + sessionId); DataChannelMessage dataChannelMessage; try {