浏览代码

Use generic data channel message instead of nick specific one

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 <danxuliu@gmail.com>
Daniel Calviño Sánchez 2 年之前
父节点
当前提交
68cf4ee028

+ 4 - 5
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.Participant;
 import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
 import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
 import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
 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.NCMessagePayload;
 import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;
 import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;
 import com.nextcloud.talk.models.json.signaling.Signaling;
 import com.nextcloud.talk.models.json.signaling.Signaling;
@@ -2176,12 +2175,12 @@ public class CallActivity extends CallBaseActivity {
     }
     }
 
 
     private void startSendingNick() {
     private void startSendingNick() {
-        DataChannelMessageNick dataChannelMessage = new DataChannelMessageNick();
+        DataChannelMessage dataChannelMessage = new DataChannelMessage();
         dataChannelMessage.setType("nickChanged");
         dataChannelMessage.setType("nickChanged");
-        HashMap<String, String> nickChangedPayload = new HashMap<>();
+        Map<String, String> nickChangedPayload = new HashMap<>();
         nickChangedPayload.put("userid", conversationUser.getUserId());
         nickChangedPayload.put("userid", conversationUser.getUserId());
         nickChangedPayload.put("name", conversationUser.getDisplayName());
         nickChangedPayload.put("name", conversationUser.getDisplayName());
-        dataChannelMessage.setPayload(nickChangedPayload);
+        dataChannelMessage.setPayloadMap(nickChangedPayload);
         for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
         for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
             if (peerConnectionWrapper.isMCUPublisher()) {
             if (peerConnectionWrapper.isMCUPublisher()) {
                 Observable
                 Observable
@@ -2196,7 +2195,7 @@ public class CallActivity extends CallBaseActivity {
 
 
                         @Override
                         @Override
                         public void onNext(@io.reactivex.annotations.NonNull Long aLong) {
                         public void onNext(@io.reactivex.annotations.NonNull Long aLong) {
-                            peerConnectionWrapper.sendNickChannelData(dataChannelMessage);
+                            peerConnectionWrapper.sendChannelData(dataChannelMessage);
                         }
                         }
 
 
                         @Override
                         @Override

+ 7 - 2
app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessage.kt

@@ -34,10 +34,15 @@ import kotlinx.android.parcel.TypeParceler
 data class DataChannelMessage(
 data class DataChannelMessage(
     @JsonField(name = ["type"])
     @JsonField(name = ["type"])
     var type: String? = null,
     var type: String? = null,
+    /** Can be String or Map<String, String>
+     *  Use only for received messages */
     @JsonField(name = ["payload"])
     @JsonField(name = ["payload"])
-    var payload: Any? = null
+    var payload: Any? = null,
+    /** Use only to send messages */
+    @JsonField(name = ["payload"])
+    var payloadMap: Map<String, String>? = null
 ) : Parcelable {
 ) : Parcelable {
     // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
     // 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)
     constructor(type: String) : this(type, null)
 }
 }

+ 0 - 40
app/src/main/java/com/nextcloud/talk/models/json/signaling/DataChannelMessageNick.kt

@@ -1,40 +0,0 @@
-/*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Andy Scherzinger
- * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
- * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-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<String, String>? = null
-) : Parcelable {
-    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
-    constructor() : this(null, null)
-}

+ 0 - 13
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.MediaStreamEvent;
 import com.nextcloud.talk.events.PeerConnectionEvent;
 import com.nextcloud.talk.events.PeerConnectionEvent;
 import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
 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.NCIceCandidate;
 import com.nextcloud.talk.models.json.signaling.NCMessagePayload;
 import com.nextcloud.talk.models.json.signaling.NCMessagePayload;
 import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;
 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) {
     public void sendChannelData(DataChannelMessage dataChannelMessage) {
         ByteBuffer buffer;
         ByteBuffer buffer;
         if (dataChannel != null) {
         if (dataChannel != null) {