From 68cf4ee02855d65945bc4fb84ba156432c91adc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Sun, 23 Oct 2022 22:01:31 +0200 Subject: [PATCH] Use generic data channel message instead of nick specific one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generic data channel message works fine for receiving, but it could not be used for sending, because the serialization of the payload failed (the generated JsonMapper did not call 'writeFieldName("payload")', apparently because the payload was defined as "Any", so there was no field name set when serializing the payload contents). It is very likely that the nick data channel message, which has an explicit payload type and was used only for sending but not for receiving, was added back in the day just to work around that limitation. However, due to how the JsonMappers are generated if several properties with the same name are defined only the first one will be parsed, and only those with a value will be serialized. This makes possible to define first a generic payload property and then a payload property with an explicit type to have a single data channel message class that can be used both for sending and receiving. As the nick data channel message is now no longer needed it was removed. Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 9 ++--- .../json/signaling/DataChannelMessage.kt | 9 ++++- .../json/signaling/DataChannelMessageNick.kt | 40 ------------------- .../talk/webrtc/PeerConnectionWrapper.java | 13 ------ 4 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessageNick.kt diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index b184425b5..22f490ef5 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -76,7 +76,6 @@ import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.models.json.participants.Participant; import com.nextcloud.talk.models.json.participants.ParticipantsOverall; import com.nextcloud.talk.models.json.signaling.DataChannelMessage; -import com.nextcloud.talk.models.json.signaling.DataChannelMessageNick; import com.nextcloud.talk.models.json.signaling.NCMessagePayload; import com.nextcloud.talk.models.json.signaling.NCSignalingMessage; import com.nextcloud.talk.models.json.signaling.Signaling; @@ -2176,12 +2175,12 @@ public class CallActivity extends CallBaseActivity { } private void startSendingNick() { - DataChannelMessageNick dataChannelMessage = new DataChannelMessageNick(); + DataChannelMessage dataChannelMessage = new DataChannelMessage(); dataChannelMessage.setType("nickChanged"); - HashMap nickChangedPayload = new HashMap<>(); + Map nickChangedPayload = new HashMap<>(); nickChangedPayload.put("userid", conversationUser.getUserId()); nickChangedPayload.put("name", conversationUser.getDisplayName()); - dataChannelMessage.setPayload(nickChangedPayload); + dataChannelMessage.setPayloadMap(nickChangedPayload); for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) { if (peerConnectionWrapper.isMCUPublisher()) { Observable @@ -2196,7 +2195,7 @@ public class CallActivity extends CallBaseActivity { @Override public void onNext(@io.reactivex.annotations.NonNull Long aLong) { - peerConnectionWrapper.sendNickChannelData(dataChannelMessage); + peerConnectionWrapper.sendChannelData(dataChannelMessage); } @Override diff --git a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.kt b/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.kt index 1024afc0f..b0ab14457 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.kt @@ -34,10 +34,15 @@ import kotlinx.android.parcel.TypeParceler data class DataChannelMessage( @JsonField(name = ["type"]) var type: String? = null, + /** Can be String or Map + * Use only for received messages */ @JsonField(name = ["payload"]) - var payload: Any? = null + var payload: Any? = null, + /** Use only to send messages */ + @JsonField(name = ["payload"]) + var payloadMap: Map? = null ) : Parcelable { // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' - constructor() : this(null, null) + constructor() : this(null, null, null) constructor(type: String) : this(type, null) } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessageNick.kt b/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessageNick.kt deleted file mode 100644 index 652106fa0..000000000 --- a/app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessageNick.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2022 Andy Scherzinger - * Copyright (C) 2017 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.nextcloud.talk.models.json.signaling - -import android.os.Parcelable -import com.bluelinelabs.logansquare.annotation.JsonField -import com.bluelinelabs.logansquare.annotation.JsonObject -import java.util.HashMap -import kotlinx.android.parcel.Parcelize - -@Parcelize -@JsonObject -data class DataChannelMessageNick( - @JsonField(name = ["type"]) - var type: String? = null, - @JsonField(name = ["payload"]) - var payload: HashMap? = null -) : Parcelable { - // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' - constructor() : this(null, null) -} 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 e5bea1847..d55b85d24 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java @@ -33,7 +33,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.events.MediaStreamEvent; import com.nextcloud.talk.events.PeerConnectionEvent; import com.nextcloud.talk.models.json.signaling.DataChannelMessage; -import com.nextcloud.talk.models.json.signaling.DataChannelMessageNick; import com.nextcloud.talk.models.json.signaling.NCIceCandidate; import com.nextcloud.talk.models.json.signaling.NCMessagePayload; import com.nextcloud.talk.models.json.signaling.NCSignalingMessage; @@ -203,18 +202,6 @@ public class PeerConnectionWrapper { } } - public void sendNickChannelData(DataChannelMessageNick dataChannelMessage) { - ByteBuffer buffer; - if (dataChannel != null) { - try { - buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes()); - dataChannel.send(new DataChannel.Buffer(buffer, false)); - } catch (IOException e) { - Log.d(TAG, "Failed to send channel data, attempting regular " + dataChannelMessage); - } - } - } - public void sendChannelData(DataChannelMessage dataChannelMessage) { ByteBuffer buffer; if (dataChannel != null) {