| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 private TCPChannelClient tcpClient; | 57 private TCPChannelClient tcpClient; |
| 58 private RoomConnectionParameters connectionParameters; | 58 private RoomConnectionParameters connectionParameters; |
| 59 | 59 |
| 60 private enum ConnectionState { | 60 private enum ConnectionState { |
| 61 NEW, CONNECTED, CLOSED, ERROR | 61 NEW, CONNECTED, CLOSED, ERROR |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // All alterations of the room state should be done from inside the looper thr
ead. | 64 // All alterations of the room state should be done from inside the looper thr
ead. |
| 65 private ConnectionState roomState; | 65 private ConnectionState roomState; |
| 66 | 66 |
| 67 public DirectRTCClient(SignalingEvents events) { | 67 public DirectRTCClient(SignalingEvents events, LooperExecutor looperExecutor)
{ |
| 68 this.events = events; | 68 this.events = events; |
| 69 executor = new LooperExecutor(); | 69 executor = looperExecutor; |
| 70 | 70 |
| 71 executor.requestStart(); | 71 executor.requestStart(); |
| 72 roomState = ConnectionState.NEW; | 72 roomState = ConnectionState.NEW; |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Connects to the room, roomId in connectionsParameters is required. roomId m
ust be a valid | 76 * Connects to the room, roomId in connectionsParameters is required. roomId m
ust be a valid |
| 77 * IP address matching IP_PATTERN. | 77 * IP address matching IP_PATTERN. |
| 78 */ | 78 */ |
| 79 @Override | 79 @Override |
| (...skipping 13 matching lines...) Expand all Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 @Override | 95 @Override |
| 96 public void disconnectFromRoom() { | 96 public void disconnectFromRoom() { |
| 97 executor.execute(new Runnable() { | 97 executor.execute(new Runnable() { |
| 98 @Override | 98 @Override |
| 99 public void run() { | 99 public void run() { |
| 100 disconnectFromRoomInternal(); | 100 disconnectFromRoomInternal(); |
| 101 } | 101 } |
| 102 }); | 102 }); |
| 103 executor.requestStop(); | |
| 104 } | 103 } |
| 105 | 104 |
| 106 /** | 105 /** |
| 107 * Connects to the room. | 106 * Connects to the room. |
| 108 * | 107 * |
| 109 * Runs on the looper thread. | 108 * Runs on the looper thread. |
| 110 */ | 109 */ |
| 111 private void connectToRoomInternal() { | 110 private void connectToRoomInternal() { |
| 112 this.roomState = ConnectionState.NEW; | 111 this.roomState = ConnectionState.NEW; |
| 113 | 112 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 reportError("Unexpected TCP message: " + msg); | 288 reportError("Unexpected TCP message: " + msg); |
| 290 } | 289 } |
| 291 } catch (JSONException e) { | 290 } catch (JSONException e) { |
| 292 reportError("TCP message JSON parsing error: " + e.toString()); | 291 reportError("TCP message JSON parsing error: " + e.toString()); |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 | 294 |
| 296 @Override | 295 @Override |
| 297 public void onTCPError(String description) { | 296 public void onTCPError(String description) { |
| 298 reportError("TCP connection error: " + description); | 297 reportError("TCP connection error: " + description); |
| 298 executor.requestStop(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 @Override | 301 @Override |
| 302 public void onTCPClose() { | 302 public void onTCPClose() { |
| 303 events.onChannelClose(); | 303 events.onChannelClose(); |
| 304 executor.requestStop(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 // -------------------------------------------------------------------- | 307 // -------------------------------------------------------------------- |
| 307 // Helper functions. | 308 // Helper functions. |
| 308 private void reportError(final String errorMessage) { | 309 private void reportError(final String errorMessage) { |
| 309 Log.e(TAG, errorMessage); | 310 Log.e(TAG, errorMessage); |
| 310 executor.execute(new Runnable() { | 311 executor.execute(new Runnable() { |
| 311 @Override | 312 @Override |
| 312 public void run() { | 313 public void run() { |
| 313 if (roomState != ConnectionState.ERROR) { | 314 if (roomState != ConnectionState.ERROR) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 return json; | 346 return json; |
| 346 } | 347 } |
| 347 | 348 |
| 348 // Converts a JSON candidate to a Java object. | 349 // Converts a JSON candidate to a Java object. |
| 349 private static IceCandidate toJavaCandidate(JSONObject json) throws JSONExcept
ion { | 350 private static IceCandidate toJavaCandidate(JSONObject json) throws JSONExcept
ion { |
| 350 return new IceCandidate(json.getString("id"), | 351 return new IceCandidate(json.getString("id"), |
| 351 json.getInt("label"), | 352 json.getInt("label"), |
| 352 json.getString("candidate")); | 353 json.getString("candidate")); |
| 353 } | 354 } |
| 354 } | 355 } |
| OLD | NEW |