Skip to content

Commit

Permalink
update signalingListener
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatim23 committed Apr 9, 2024
1 parent 5a297b1 commit acfa677
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ public abstract class SignalingListener implements Signaling {

private final Gson gson = new Gson();

private final WebSocketListener messageHandler = new WebSocketListener() {
private final WebSocketListener websocketListener = new WebSocketListener() {

@Override
public void onMessage(@NonNull WebSocket webSocket, String text) {
if (text.isEmpty()) {
public void onMessage(@NonNull WebSocket webSocket, String message) {
if (message.isEmpty()) {
return;
}

Log.d(TAG, "Received message: " + text);
Log.d(TAG, "Received message: " + message);

if (!text.contains("messagePayload")) {
if (!message.contains("messagePayload")) {
return;
}

final Event evt = gson.fromJson(text, Event.class);
final Event evt = gson.fromJson(message, Event.class);

if (evt == null || evt.getMessageType() == null || evt.getMessagePayload().isEmpty()) {
return;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void onMessage(@NonNull WebSocket webSocket, String text) {
}
};

public WebSocketListener getMessageHandler() {
return messageHandler;
public WebSocketListener getWebsocketListener() {
return websocketListener;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.amazonaws.kinesisvideo.signaling.okhttp;

import static org.awaitility.Awaitility.await;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import android.util.Log;
import androidx.annotation.NonNull;

import com.amazonaws.kinesisvideo.signaling.SignalingListener;
import com.amazonaws.kinesisvideo.utils.Constants;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;

/**
* An OkHttp based WebSocket client.
*/
Expand All @@ -37,28 +36,28 @@ class WebSocketClient {

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

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

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

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

0 comments on commit acfa677

Please sign in to comment.