Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further synchronization #124

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/main/java/org/saltyrtc/client/signaling/Signaling.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,18 @@ private void initWebsocket() throws IOException {
WebSocketAdapter listener = new WebSocketAdapter() {
@Override
@SuppressWarnings("UnqualifiedMethodAccess")
public void onConnected(WebSocket websocket, Map<String, List<String>> 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<String, List<String>> headers) {
dbrgn marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -445,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) {
Expand Down Expand Up @@ -522,7 +520,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);
Expand Down