Parcourir la source

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 il y a 11 ans
Parent
commit
5f178148ed
2 fichiers modifiés avec 8 ajouts et 3 suppressions
  1. 6 1
      public/javascripts/chatServices.js
  2. 2 2
      public/javascripts/main.js

+ 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'])