[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-mobile/master] Setting remote description and SDP serialization, deserialization



commit 490059722e519533b74a68f5bf3a07b2ed0f07ec
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date:   Tue Jun 9 14:57:00 2020 +0530

    Setting remote description and SDP serialization, deserialization
---
 .../torproject/snowflake/MyPersistentService.java  | 31 ++++++++++++++-----
 .../org/torproject/snowflake/SDPSerializer.java    | 17 ++++++++++
 .../torproject/snowflake/SimpleSdpObserver.java    | 36 ++++++++++++++++++++++
 3 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
index 8a045a6..ecb39ee 100644
--- a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -266,6 +266,7 @@ public class MyPersistentService extends Service {
         return factory.createPeerConnection(rtcConfiguration, pcObserver);
     }
     /////////////// Network Calls ////////////////////////
+
     /**
      * Sending post request to get offer from the broker.
      */
@@ -280,24 +281,40 @@ public class MyPersistentService extends Service {
 
     /**
      * Fetching offer is a success.
+     *
      * @param sdpOfferResponse
      */
     public void offerRequestSuccess(SDPOfferResponse sdpOfferResponse) {
+        createPersistentNotification(true, "Fetching offer success. Creating Answer.");
         if (sdpOfferResponse.getStatus().equals(BrokerConstants.CLIENT_MATCH)) {
             Log.d(TAG, "requestSuccess: CLIENT MATCH");
-            //TODO:Serialize SDP, SetRemote Description, Send Answer.
-
+            try {
+                SessionDescription offer = SDPSerializer.deserializeOffer(sdpOfferResponse.getOffer());
+                Log.d(TAG, "requestSuccess: Remote Description (OFFER):\n" + offer.description);
+                mainPeerConnection.setRemoteDescription(new SimpleSdpObserver("Remote: Offer"), offer);
+                //TODO: Create Answer
+            } catch (JSONException e) {
+                Log.d(TAG, "requestSuccess: Serialization Failed:");
+                e.printStackTrace();
+            }
         } else {
             Log.d(TAG, "requestSuccess: NO CLIENT MATCH");
-//            if (isServiceStarted)
-            //fetchOffer(); //Sending request for offer again.
+            //TODO:Set a time out to resending offer.
+            if (isServiceStarted)
+                fetchOffer(); //Sending request for offer again.
         }
     }
 
-    public void offerRequestFailure(Throwable t){
+    /**
+     * Offer Request is a failure and handling the failure by resending the offer.
+     *
+     * @param t
+     */
+    public void offerRequestFailure(Throwable t) {
         Log.d(TAG, "requestFailure: " + t.getMessage());
-        createPersistentNotification(true,"Failed getting offer. Retrying.");
+        createPersistentNotification(true, "Failed getting offer. Retrying.");
         //TODO:Set a time out to resending offer.
-        fetchOffer(); //Sending request for offer again.
+        if (isServiceStarted)
+            fetchOffer(); //Sending request for offer again.
     }
 }
diff --git a/app/src/main/java/org/torproject/snowflake/SDPSerializer.java b/app/src/main/java/org/torproject/snowflake/SDPSerializer.java
new file mode 100644
index 0000000..60bb846
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/SDPSerializer.java
@@ -0,0 +1,17 @@
+package org.torproject.snowflake;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.webrtc.SessionDescription;
+
+public class SDPSerializer {
+
+    public static SessionDescription deserializeOffer(String SDP) throws JSONException {
+        return new SessionDescription(SessionDescription.Type.OFFER,
+                new JSONObject(SDP).get("sdp").toString());
+    }
+
+    public static String serializeAnswer(SessionDescription SDP){
+        return SDP.description;
+    }
+}
diff --git a/app/src/main/java/org/torproject/snowflake/SimpleSdpObserver.java b/app/src/main/java/org/torproject/snowflake/SimpleSdpObserver.java
new file mode 100644
index 0000000..0a42603
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/SimpleSdpObserver.java
@@ -0,0 +1,36 @@
+package org.torproject.snowflake;
+
+import android.util.Log;
+
+import org.webrtc.SdpObserver;
+import org.webrtc.SessionDescription;
+
+
+public class SimpleSdpObserver implements SdpObserver {
+    private final String TAG = "SimpleSdpObserver";
+    private final String location;
+
+    public SimpleSdpObserver(String loc) {
+        location = loc; //Remote or local
+    }
+
+    @Override
+    public void onCreateSuccess(SessionDescription sessionDescription) {
+        Log.d(TAG, "onCreateSuccess: " + location + ":\n" + sessionDescription.description);
+    }
+
+    @Override
+    public void onSetSuccess() {
+        Log.d(TAG, "onSetSuccess: " + location);
+    }
+
+    @Override
+    public void onCreateFailure(String s) {
+        Log.d(TAG, "onCreateFailure: " + location + ":" + s);
+    }
+
+    @Override
+    public void onSetFailure(String s) {
+        Log.d(TAG, "onSetFailure: " + location + ":" + s);
+    }
+}

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits