瀏覽代碼

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 年之前
父節點
當前提交
5f178148ed
共有 2 個文件被更改,包括 8 次插入3 次删除
  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'])