Fix WebSocketObserver getting garbage collected.
Apparently WebSocketObserver gets garbage collected if it is not stored by us. This caused some external tests to break. Bug: None Change-Id: If62786e84f84a5a63172d67962bb4de8ae3e8479 Reviewed-on: https://webrtc-review.googlesource.com/16100 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20449}
This commit is contained in:
committed by
Commit Bot
parent
92b1ffd0f6
commit
ef5df1ae52
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user