diff --git a/examples/androidapp/src/org/appspot/apprtc/WebSocketChannelClient.java b/examples/androidapp/src/org/appspot/apprtc/WebSocketChannelClient.java index bf241fe8cb..c013c76f0d 100644 --- a/examples/androidapp/src/org/appspot/apprtc/WebSocketChannelClient.java +++ b/examples/androidapp/src/org/appspot/apprtc/WebSocketChannelClient.java @@ -10,22 +10,18 @@ package org.appspot.apprtc; -import org.appspot.apprtc.util.AsyncHttpURLConnection; -import org.appspot.apprtc.util.AsyncHttpURLConnection.AsyncHttpEvents; - import android.os.Handler; import android.util.Log; - import de.tavendo.autobahn.WebSocket.WebSocketConnectionObserver; import de.tavendo.autobahn.WebSocketConnection; import de.tavendo.autobahn.WebSocketException; - -import org.json.JSONException; -import org.json.JSONObject; - import java.net.URI; import java.net.URISyntaxException; import java.util.LinkedList; +import org.appspot.apprtc.util.AsyncHttpURLConnection; +import org.appspot.apprtc.util.AsyncHttpURLConnection.AsyncHttpEvents; +import org.json.JSONException; +import org.json.JSONObject; /** * WebSocket client implementation. @@ -34,7 +30,6 @@ import java.util.LinkedList; * passed in a constructor, otherwise exception will be thrown. * All events are dispatched on the same thread. */ - public class WebSocketChannelClient { private static final String TAG = "WSChannelRTCClient"; private static final int CLOSE_TIMEOUT = 1000; @@ -46,6 +41,9 @@ public class WebSocketChannelClient { private String roomID; private String clientID; private WebSocketConnectionState state; + // Do not remove this member variable. If this is removed, the observer gets garbage collected and + // this causes test breakages. + private WebSocketObserver wsObserver; private final Object closeEventLock = new Object(); private boolean closeEvent; // WebSocket send queue. Messages are added to the queue when WebSocket @@ -92,7 +90,7 @@ public class WebSocketChannelClient { Log.d(TAG, "Connecting WebSocket to: " + wsUrl + ". Post URL: " + postUrl); ws = new WebSocketConnection(); - WebSocketObserver wsObserver = new WebSocketObserver(); + wsObserver = new WebSocketObserver(); try { ws.connect(new URI(wsServerUrl), wsObserver); } catch (URISyntaxException e) {