From f0061ae770a746dd91d5f610c52c55cbe7d68c6b Mon Sep 17 00:00:00 2001 From: ovalseven8 <8258609+ovalseven8@users.noreply.github.com> Date: Wed, 17 Jul 2019 13:27:57 +0200 Subject: [PATCH 1/2] Further synchronization --- .../saltyrtc/client/signaling/Signaling.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/saltyrtc/client/signaling/Signaling.java b/src/main/java/org/saltyrtc/client/signaling/Signaling.java index 3e0d6d9..ce908aa 100644 --- a/src/main/java/org/saltyrtc/client/signaling/Signaling.java +++ b/src/main/java/org/saltyrtc/client/signaling/Signaling.java @@ -294,20 +294,18 @@ private void initWebsocket() throws IOException { WebSocketAdapter listener = new WebSocketAdapter() { @Override @SuppressWarnings("UnqualifiedMethodAccess") - public void onConnected(WebSocket websocket, Map> headers) { - synchronized (this) { - if (getState() == SignalingState.WS_CONNECTING) { - getLogger().info("WebSocket connection established"); - setState(SignalingState.SERVER_HANDSHAKE); - } else { - getLogger().warn("Got onConnected event, but WebSocket connection already open"); - } + public synchronized void onConnected(WebSocket websocket, Map> headers) { + if (getState() == SignalingState.WS_CONNECTING) { + getLogger().info("WebSocket connection established"); + setState(SignalingState.SERVER_HANDSHAKE); + } else { + getLogger().warn("Got onConnected event, but WebSocket connection already open"); } } @Override @SuppressWarnings("UnqualifiedMethodAccess") - public void onConnectError(WebSocket websocket, WebSocketException ex) throws Exception { + public synchronized void onConnectError(WebSocket websocket, WebSocketException ex) throws Exception { getLogger().error("Could not connect to websocket (" + ex.getError().toString() + "): " + ex.getMessage()); if (Signaling.this.wsConnectAttemptsMax <= 0 || Signaling.this.wsConnectAttempt < Signaling.this.wsConnectAttemptsMax) { // Increase #attempts (and timeout if needed) @@ -336,7 +334,7 @@ public void onConnectError(WebSocket websocket, WebSocketException ex) throws Ex @Override @SuppressWarnings("UnqualifiedMethodAccess") - public void onTextMessage(WebSocket websocket, String text) { + public synchronized void onTextMessage(WebSocket websocket, String text) { getLogger().debug("New string message: " + text); getLogger().error("Protocol error: Received string message, but only binary messages are valid."); Signaling.this.resetConnection(CloseCode.PROTOCOL_ERROR); @@ -502,9 +500,11 @@ public void onDisconnected(WebSocket websocket, } } // Note: Don't check for signaling state here, it will already have been resetted. - if (closeCode != CloseCode.HANDOVER) { - Signaling.this.salty.events.close.notifyHandlers(new CloseEvent(closeCode)); - setState(SignalingState.CLOSED); + synchronized (this) { + if (closeCode != CloseCode.HANDOVER) { + Signaling.this.salty.events.close.notifyHandlers(new CloseEvent(closeCode)); + setState(SignalingState.CLOSED); + } } } @@ -522,7 +522,7 @@ public void onError(WebSocket websocket, WebSocketException cause) { @Override @SuppressWarnings("UnqualifiedMethodAccess") - public void handleCallbackError(WebSocket websocket, Throwable cause) { + public synchronized void handleCallbackError(WebSocket websocket, Throwable cause) { getLogger().error("WebSocket callback error: " + cause); cause.printStackTrace(); Signaling.this.resetConnection(CloseCode.INTERNAL_ERROR); From 4779c6d0621ca12ea6b1132db3753e71061a7160 Mon Sep 17 00:00:00 2001 From: ovalseven8 <8258609+ovalseven8@users.noreply.github.com> Date: Thu, 18 Jul 2019 11:27:08 +0200 Subject: [PATCH 2/2] fixup! Further synchronization --- .../java/org/saltyrtc/client/signaling/Signaling.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/saltyrtc/client/signaling/Signaling.java b/src/main/java/org/saltyrtc/client/signaling/Signaling.java index ce908aa..1e6b25b 100644 --- a/src/main/java/org/saltyrtc/client/signaling/Signaling.java +++ b/src/main/java/org/saltyrtc/client/signaling/Signaling.java @@ -443,7 +443,7 @@ public synchronized void onBinaryMessage(WebSocket websocket, byte[] binary) { @Override @SuppressWarnings("UnqualifiedMethodAccess") - public void onDisconnected(WebSocket websocket, + public synchronized void onDisconnected(WebSocket websocket, @Nullable WebSocketFrame serverCloseFrame, @Nullable WebSocketFrame clientCloseFrame, boolean closedByServer) { @@ -500,11 +500,9 @@ public void onDisconnected(WebSocket websocket, } } // Note: Don't check for signaling state here, it will already have been resetted. - synchronized (this) { - if (closeCode != CloseCode.HANDOVER) { - Signaling.this.salty.events.close.notifyHandlers(new CloseEvent(closeCode)); - setState(SignalingState.CLOSED); - } + if (closeCode != CloseCode.HANDOVER) { + Signaling.this.salty.events.close.notifyHandlers(new CloseEvent(closeCode)); + setState(SignalingState.CLOSED); } }