Эх сурвалжийг харах

Preparing all the models for websockets

Mario Danic 6 жил өмнө
parent
commit
0f0509c2d4

+ 3 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/AuthParametersWebSocketMessage.java

@@ -24,10 +24,13 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.squareup.moshi.Json;
 
+import org.parceler.Parcel;
+
 import lombok.Data;
 
 @Data
 @JsonObject
+@Parcel
 public class AuthParametersWebSocketMessage {
     @JsonField(name = "userid")
     String userid;

+ 3 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/AuthWebSocketMessage.java

@@ -24,10 +24,13 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.squareup.moshi.Json;
 
+import org.parceler.Parcel;
+
 import lombok.Data;
 
 @Data
 @JsonObject
+@Parcel
 public class AuthWebSocketMessage {
     @JsonField(name = "url")
     String url;

+ 33 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/BaseSignalingWebSocketMessage.java

@@ -0,0 +1,33 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class BaseSignalingWebSocketMessage extends BaseWebSocketMessage {
+}

+ 4 - 1
app/src/main/java/com/nextcloud/talk/models/json/websocket/BaseWebSocketMessage.java

@@ -23,11 +23,14 @@ package com.nextcloud.talk.models.json.websocket;
 import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 
+import org.parceler.Parcel;
+
 import lombok.Data;
 
 @Data
 @JsonObject
-public class BaseWebSocketMessage {
+@Parcel
+public class BaseWebSocketMessage{
     @JsonField(name = "type")
     String type;
 }

+ 3 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/HelloOverallWebSocketMessage.java

@@ -24,10 +24,13 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.squareup.moshi.Json;
 
+import org.parceler.Parcel;
+
 import lombok.Data;
 
 @Data
 @JsonObject
+@Parcel
 public class HelloOverallWebSocketMessage extends BaseWebSocketMessage {
     @JsonField(name = "hello")
     HelloWebSocketMessage helloWebSocketMessage;

+ 3 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/HelloWebSocketMessage.java

@@ -24,10 +24,13 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.squareup.moshi.Json;
 
+import org.parceler.Parcel;
+
 import lombok.Data;
 
 @Data
 @JsonObject
+@Parcel
 public class HelloWebSocketMessage {
     @JsonField(name = "version")
     String version;

+ 39 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/RecipientWebSocketMessage.java

@@ -0,0 +1,39 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class RecipientWebSocketMessage {
+    @JsonField(name = "type")
+    String type;
+
+    @JsonField(name = "sessionid")
+    String sessionId;
+}

+ 36 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferOverallWebSocketMessage.java

@@ -0,0 +1,36 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class RequestOfferOverallWebSocketMessage extends BaseWebSocketMessage {
+    @JsonField(name = "message")
+    RequestOfferSignalingMessage requestOfferOverallWebSocketMessage;
+}

+ 40 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferSignalingMessage.java

@@ -0,0 +1,40 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+import com.squareup.moshi.Json;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class RequestOfferSignalingMessage {
+    @JsonField(name = "recipient")
+    RecipientWebSocketMessage recipientWebSocketMessage;
+
+    @JsonField(name = "data")
+    SignalingDataWebSocketMessageForOffer signalingDataWebSocketMessageForOffer;
+}

+ 37 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomOverallWebSocketMessage.java

@@ -0,0 +1,37 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+import com.nextcloud.talk.models.json.rooms.RoomOverall;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class RoomOverallWebSocketMessage extends BaseWebSocketMessage {
+    @JsonField(name = "room")
+    RoomOverallWebSocketMessage roomOverallWebSocketMessage;
+}

+ 39 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/RoomWebSocketMessage.java

@@ -0,0 +1,39 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class RoomWebSocketMessage {
+    @JsonField(name = "roomid")
+    String roomId;
+
+    @JsonField(name = "sessionid")
+    String sessiondId;
+}

+ 39 - 0
app/src/main/java/com/nextcloud/talk/models/json/websocket/SignalingDataWebSocketMessageForOffer.java

@@ -0,0 +1,39 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 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.websocket;
+
+import com.bluelinelabs.logansquare.annotation.JsonField;
+import com.bluelinelabs.logansquare.annotation.JsonObject;
+
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@JsonObject
+@Parcel
+public class SignalingDataWebSocketMessageForOffer {
+    @JsonField(name = "type")
+    String type;
+
+    @JsonField(name = "roomType")
+    String roomType;
+}

+ 87 - 0
app/src/main/java/com/nextcloud/talk/webrtc/ScarletHelper.java

@@ -20,8 +20,23 @@
 
 package com.nextcloud.talk.webrtc;
 
+import com.google.android.gms.common.api.Api;
 import com.nextcloud.talk.api.ExternalSignaling;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
+import com.nextcloud.talk.models.database.UserEntity;
+import com.nextcloud.talk.models.json.rooms.Conversation;
+import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;
+import com.nextcloud.talk.models.json.websocket.AuthParametersWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.AuthWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.HelloOverallWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.HelloWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.RecipientWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.RequestOfferOverallWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.RequestOfferSignalingMessage;
+import com.nextcloud.talk.models.json.websocket.RoomOverallWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.RoomWebSocketMessage;
+import com.nextcloud.talk.models.json.websocket.SignalingDataWebSocketMessageForOffer;
+import com.nextcloud.talk.utils.ApiUtils;
 import com.tinder.scarlet.Scarlet;
 import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter;
 import com.tinder.scarlet.retry.LinearBackoffStrategy;
@@ -76,4 +91,76 @@ public class ScarletHelper {
             return externalSignaling;
         }
     }
+
+    public HelloOverallWebSocketMessage getAssembledHelloModel(UserEntity userEntity, String ticket) {
+        HelloOverallWebSocketMessage helloOverallWebSocketMessage = new HelloOverallWebSocketMessage();
+        helloOverallWebSocketMessage.setType("hello");
+        HelloWebSocketMessage helloWebSocketMessage = new HelloWebSocketMessage();
+        helloWebSocketMessage.setVersion("1.0");
+        AuthWebSocketMessage authWebSocketMessage = new AuthWebSocketMessage();
+        authWebSocketMessage.setUrl(ApiUtils.getUrlForExternalServerAuthBackend(userEntity.getBaseUrl()));
+        AuthParametersWebSocketMessage authParametersWebSocketMessage = new AuthParametersWebSocketMessage();
+        authParametersWebSocketMessage.setTicket(ticket);
+        authParametersWebSocketMessage.setUserid(userEntity.getUserId());
+        authWebSocketMessage.setAuthParametersWebSocketMessage(authParametersWebSocketMessage);
+        helloWebSocketMessage.setAuthWebSocketMessage(authWebSocketMessage);
+        return helloOverallWebSocketMessage;
+    }
+
+    public HelloOverallWebSocketMessage getAssembledHelloModelForResume(String resumeId) {
+        HelloOverallWebSocketMessage helloOverallWebSocketMessage = new HelloOverallWebSocketMessage();
+        helloOverallWebSocketMessage.setType("hello");
+        HelloWebSocketMessage helloWebSocketMessage = new HelloWebSocketMessage();
+        helloWebSocketMessage.setVersion("1.0");
+        helloWebSocketMessage.setResumeid(resumeId);
+        return helloOverallWebSocketMessage;
+    }
+
+    public RoomOverallWebSocketMessage getAssembledJoinOrLeaveRoomModel(String roomId, String sessionId) {
+        RoomOverallWebSocketMessage roomOverallWebSocketMessage = new RoomOverallWebSocketMessage();
+        roomOverallWebSocketMessage.setType("room");
+        RoomWebSocketMessage roomWebSocketMessage = new RoomWebSocketMessage();
+        roomWebSocketMessage.setRoomId(roomId);
+        roomWebSocketMessage.setSessiondId(sessionId);
+        return roomOverallWebSocketMessage;
+    }
+
+    public RequestOfferOverallWebSocketMessage getAssembledRequestOfferModel(String sessionId, String roomType) {
+        RequestOfferOverallWebSocketMessage requestOfferOverallWebSocketMessage = new RequestOfferOverallWebSocketMessage();
+        requestOfferOverallWebSocketMessage.setType("message");
+
+        RequestOfferSignalingMessage requestOfferSignalingMessage = new RequestOfferSignalingMessage();
+
+        RecipientWebSocketMessage recipientWebSocketMessage = new RecipientWebSocketMessage();
+        recipientWebSocketMessage.setType("session");
+        recipientWebSocketMessage.setSessionId(sessionId);
+        requestOfferSignalingMessage.setRecipientWebSocketMessage(recipientWebSocketMessage);
+
+        SignalingDataWebSocketMessageForOffer signalingDataWebSocketMessageForOffer = new SignalingDataWebSocketMessageForOffer();
+        signalingDataWebSocketMessageForOffer.setRoomType(roomType);
+        signalingDataWebSocketMessageForOffer.setType("requestoffer");
+        requestOfferSignalingMessage.setSignalingDataWebSocketMessageForOffer(signalingDataWebSocketMessageForOffer);
+
+        requestOfferOverallWebSocketMessage.setRequestOfferOverallWebSocketMessage(requestOfferSignalingMessage);
+        return requestOfferOverallWebSocketMessage;
+    }
+
+    /*
+    - (void)sendCallMessage:(NCSignalingMessage *)message
+    {
+    NSDictionary *messageDict = @{
+                                  @"type": @"message",
+                                  @"message": @{
+                                          @"recipient": @{
+                                                  @"type": @"session",
+                                                  @"sessionid": message.to
+                                                  },
+                                          @"data": [message functionDict]
+                                          }
+                                  };
+
+    [self sendMessage:messageDict];
+    }
+
+     */
 }