Kaynağa Gözat

Redo logic for websocket redirection

Now we just setup the websocket connection to the websocket enabled one,
but we use port 80 for everything else.
Thomas Dy 11 yıl önce
ebeveyn
işleme
5f178148ed

+ 6 - 1
public/javascripts/chatServices.js

@@ -50,7 +50,12 @@ angular.module('chatServices', [])
     if(service.status != 'disconnected') return;
     service.error = null;
     service.status = 'connecting';
-    chatSocket = new WS(jsRoutes.controllers.Application.chat(username, getRoom()).webSocketURL());
+
+    var url = jsRoutes.controllers.Application.chat(username, getRoom()).webSocketURL();
+    if(window.location.hostname == "gamenchat.pleasantprogrammer.com" && window.location.port == "") {
+      url = url.replace("gamenchat.pleasantprogrammer.com", "$&:8000");
+    }
+    chatSocket = new WS(url);
     chatSocket.onmessage = wrap(function(event) {
       var message = JSON.parse(event.data);
       if(message.error) {

+ 2 - 2
public/javascripts/main.js

@@ -1,5 +1,5 @@
-if(window.location.hostname == 'gamenchat.pleasantprogrammer.com' && window.location.port != 8000) {
-  window.location = 'http://gamenchat.pleasantprogrammer.com:8000';
+if(window.location.hostname == 'gamenchat.pleasantprogrammer.com' && window.location.port == "8000") {
+  window.location = 'http://gamenchat.pleasantprogrammer.com';
 }
 
 angular.module('taboo', ['chatServices', 'tabooServices'])