From e667be1bab57a052254a6c4e230d1140e75c4eb5 Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Sat, 14 Oct 2017 17:01:09 -0400 Subject: [PATCH] Use plain WebSockets, not SockJS --- server/src/main/java/lingo/server/WebSocketConfig.java | 3 ++- server/src/main/resources/static/client.js | 7 ++++++- server/src/main/resources/static/practice.js | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/lingo/server/WebSocketConfig.java b/server/src/main/java/lingo/server/WebSocketConfig.java index c956c73..701d7e3 100644 --- a/server/src/main/java/lingo/server/WebSocketConfig.java +++ b/server/src/main/java/lingo/server/WebSocketConfig.java @@ -32,7 +32,8 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/stomp").withSockJS(); + registry.addEndpoint("/sockjs").withSockJS(); + registry.addEndpoint("/stomp"); } } diff --git a/server/src/main/resources/static/client.js b/server/src/main/resources/static/client.js index 8e4dc9c..e844aeb 100644 --- a/server/src/main/resources/static/client.js +++ b/server/src/main/resources/static/client.js @@ -274,7 +274,12 @@ function afterConnected(stompConnectedFrame) { function main() { - client = Stomp.over(new SockJS('/stomp')); + let webSocketProtocol = 'ws'; + if (location.protocol.startsWith('https')) { + webSocketProtocol = 'wss'; + } + + client = Stomp.client(`${webSocketProtocol}://${location.host}/stomp`); client.connect({}, afterConnected, function(errorMessage) { addChatAnnouncement(errorMessage); addChatAnnouncement('Please reload the page!'); diff --git a/server/src/main/resources/static/practice.js b/server/src/main/resources/static/practice.js index 540d3c6..9aa6296 100644 --- a/server/src/main/resources/static/practice.js +++ b/server/src/main/resources/static/practice.js @@ -32,7 +32,12 @@ function start() { reset(); repaint(); - client = Stomp.over(new SockJS('/stomp')); + let webSocketProtocol = 'ws'; + if (location.protocol.startsWith('https')) { + webSocketProtocol = 'wss'; + } + + client = Stomp.client(`${webSocketProtocol}://${location.host}/stomp`); client.connect({}, function(frame) { subscribeToPracticeGame();