Browse Source

allow to choose reflector address

Nikolay Suslov 7 years ago
parent
commit
3719f5aab0
3 changed files with 53 additions and 7 deletions
  1. 7 0
      public/index.html
  2. 34 3
      public/web/lib/app.js
  3. 12 4
      support/client/lib/vwf.js

+ 7 - 0
public/index.html

@@ -107,6 +107,13 @@
       <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-12">
           <div id="worldInfo">
             </div>
+            <div id="reflectorMenu">
+                <div id="reflectorSelect" class="mdc-text-field mdc-text-field--upgraded">
+                    <input id="currentReflector" type="text" class="mdc-text-field__input" id="my-text-field" aria-controls="my-text-field-helper-text">
+                    <label for="my-text-field" class="mdc-text-field__label">Reflector</label>
+                    <div class="mdc-text-field__bottom-line"></div>
+                  </div>
+            </div>
       </div>
     </div>
   </div>

+ 34 - 3
public/web/lib/app.js

@@ -15,8 +15,10 @@ class WebApp {
 
         this.lang = new Lang;
         this.language = this.prepareLang();
+        this.initReflectorServer();
 
-        var socket = io.connect(window.location.protocol + "//" + window.location.host, this.options);
+        //window.location.host
+        var socket = io.connect(window.location.protocol + "//" + this.currentReflector, this.options);
 
         var self = this;
 
@@ -26,6 +28,15 @@ class WebApp {
         });
     }
 
+
+    initReflectorServer() {
+        this.currentReflector = localStorage.getItem('lcs_reflector');
+        if (!this.currentReflector) {
+            localStorage.setItem('lcs_reflector', 'livecoding.space');
+            this.currentReflector = localStorage.getItem('lcs_reflector');
+        }
+    }
+
     prepareLang() {
         let phrases = this.lang.langPhrases;
         return new this.lang.polyglot({ phrases });
@@ -44,6 +55,26 @@ class WebApp {
             let textEl = document.querySelector("#" + el);
             textEl.innerHTML = this.lang.getTranslationFor(el);
         })
+
+        this.initReflectorSelector();
+    }
+
+
+    initReflectorSelector() {
+
+        const ref = document.querySelector('#currentReflector'); 
+        ref.value = this.currentReflector;
+        //let currentItem = Array.from(items).filter(el => el.textContent == this.currentReflector);
+
+        const reflectorSelect = document.querySelector('#reflectorSelect');
+        mdc.textField.MDCTextField.attachTo(reflectorSelect);
+        reflectorSelect.addEventListener('change', function(e) {
+            console.log(e.target.value); 
+            localStorage.setItem('lcs_reflector', e.target.value);  
+           window.location.reload(true);
+
+            });
+
     }
 
     parseAppInstancesData(data) {
@@ -245,9 +276,9 @@ class WebApp {
                                                     $components: [
                                                         {
                                                             $type: "a",
-                                                            $text: m[1].instance,
+                                                            $text: m[0],
                                                             target: "_blank",
-                                                            href: window.location.protocol + "//" + m[1].instance,
+                                                            href: window.location.protocol + "//" + window.location.host + m[0],
                                                             onclick: function (e) {
                                                                 self.refresh();
                                                             }

+ 12 - 4
support/client/lib/vwf.js

@@ -827,11 +827,16 @@
                     // resource: window.location.pathname.slice( 1,
                     //      window.location.pathname.lastIndexOf("/") ),
 
-                    query: 'pathname=' + window.location.pathname.slice( 1,
-                        window.location.pathname.lastIndexOf("/") ),
+                    query: {
+                        pathname: window.location.pathname.slice( 1,
+                            window.location.pathname.lastIndexOf("/") ),
+                        appRoot: "./public"
+                      },
+                    // query: 'pathname=' + window.location.pathname.slice( 1,
+                    //     window.location.pathname.lastIndexOf("/") ),
 
                     // Use a secure connection when the application comes from https.
-
+                    
                     secure: window.location.protocol === "https:",
 
                     // Don't attempt to reestablish lost connections. The client reloads after a
@@ -845,7 +850,10 @@
 
                 if ( isSocketIO07() ) {
 
-            socket = io.connect( window.location.protocol + "//" + window.location.host,options );
+                    //window.location.host
+            var host = localStorage.getItem('lcs_reflector'); 
+            if(!host) host = window.location.host;       
+            socket = io.connect( window.location.protocol + "//" + host, options );
                     
 
                 } else {  // Ruby Server -- only supports socket.io 0.6