Skip to content

Commit

Permalink
update signalingListener and WebSocketClient
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatim23 committed Apr 9, 2024
1 parent acfa677 commit 0f75121
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ public void onMessage(@NonNull WebSocket webSocket, String message) {
case "SDP_OFFER":
Log.d(TAG, "Offer received: SenderClientId=" + evt.getSenderClientId());
Log.d(TAG, new String(Base64.decode(evt.getMessagePayload(), 0)));

onSdpOffer(evt);
break;

case "SDP_ANSWER":
Log.d(TAG, "Answer received: SenderClientId=" + evt.getSenderClientId());

onSdpAnswer(evt);
break;

case "ICE_CANDIDATE":
Log.d(TAG, "Ice Candidate received: SenderClientId=" + evt.getSenderClientId());
Log.d(TAG, new String(Base64.decode(evt.getMessagePayload(), 0)));

onIceCandidate(evt);
break;

default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,42 @@
class WebSocketClient {

private static final String TAG = "WebSocketClient";

private final WebSocket webSocket;
private volatile boolean isOpen = false;

WebSocketClient(final String uri, final SignalingListener signalingListener) {

OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
OkHttpClient client = clientBuilder.build();
OkHttpClient client = new OkHttpClient.Builder().build();

Request request = new Request.Builder()
.url(uri)
.addHeader("User-Agent", Constants.APP_NAME + "/" + Constants.VERSION + " " + System.getProperty("http.agent"))
.addHeader("User-Agent", Constants.APP_NAME + "/" + Constants.VERSION
+ " " + System.getProperty("http.agent"))
.build();

webSocket = client.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(@NonNull WebSocket webSocket, @NonNull Response response) {
Log.d(TAG, "WebSocket connection opened");
isOpen = true;
// Register message handler
signalingListener.getWebsocketListener().onOpen(webSocket, response);
}

@Override
public void onMessage(@NonNull WebSocket webSocket, @NonNull String text) {
Log.d(TAG, "Received message: " + text);
signalingListener.getWebsocketListener().onMessage(webSocket, text);
public void onMessage(@NonNull WebSocket webSocket, @NonNull String message) {
Log.d(TAG, "Websocket received a message: " + message);
signalingListener.getWebsocketListener().onMessage(webSocket, message);
}

@Override
public void onClosed(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
Log.d(TAG, "WebSocket connection closed: " + reason);
isOpen = false;
signalingListener.getWebsocketListener().onClosed(webSocket, code, reason);
}

@Override
public void onFailure(@NonNull WebSocket webSocket, @NonNull Throwable t, Response response) {
Log.e(TAG, "WebSocket connection failed", t);
isOpen = false;
// Handle failure
signalingListener.onException((Exception) t);
}
});
Expand Down

0 comments on commit 0f75121

Please sign in to comment.