Kaynağa Gözat

add gundb WebRTC connection settings

Nikolay Suslov 4 yıl önce
ebeveyn
işleme
391e5b7d8a

+ 15 - 1
public/app.js

@@ -87,6 +87,7 @@ class App {
         'luminaryGlobalHB': false,
         'dbhost': window.location.origin + '/gun', // 'https://' + window.location.hostname + ':8080/gun', //'http://localhost:8080/gun',
         'reflector': 'https://' + window.location.hostname + ':3002',
+        'webrtc': false,
         'language': 'en'
       }
       localStorage.setItem('lcs_config', JSON.stringify(config));
@@ -107,9 +108,16 @@ class App {
       localStorage.setItem('lcs_config', JSON.stringify(config));
     }
 
+    if (!config.webrtc) {
+      config.webrtc = false;
+      localStorage.setItem('lcs_config', JSON.stringify(config));
+    }
+
     this.config = config;
 
-    const opt = { peers: this.dbHost, localStorage: false, RTCPeerConnection: false, axe: false }
+    let webrtcConnection = this.config.webrtc;
+
+    const opt = { peers: this.dbHost, localStorage: false, RTCPeerConnection: webrtcConnection, axe: false }
     //const opt = { peers: this.dbHost, localStorage: false, until: 1000, chunk: 5, axe: false} //until: 5000, chunk: 5
     //opt.store = RindexedDB(opt);
     this.db = Gun(opt);
@@ -197,6 +205,12 @@ class App {
 
   }
 
+  get isWebRTC() {
+
+    return this.config.webrtc;
+
+  }
+
   get luminaryGlobalHBPath() {
 
     var res = "";

+ 54 - 0
public/lib/widgets.js

@@ -675,6 +675,54 @@ Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contribu
 
         reflectorGUI() {
 
+            let webrtcConnection = {
+                $cell: true,
+                $components: [
+                  {
+                    $type: "p",
+                    class: "mdc-typography--headline5",
+                    $text: "Use WebRTC for connection"
+                  },
+                  {
+                    $type: 'p'
+                  },
+                  _app.widgets.switch({
+                    'id': 'forceWebRTC',
+                    'init': function () {
+                      this._switch = new mdc.switchControl.MDCSwitch(this);
+                      let config = localStorage.getItem('lcs_config');
+                      this._switch.checked = JSON.parse(config).webrtc;
+                      
+                     // this._replaceSwitch = this._switch;
+                      
+                    },
+                    'onchange': function (e) {
+    
+                        if (this._switch) {
+                            let chkAttr = this._switch.checked;//this.getAttribute('checked');
+                            if (chkAttr) {
+                                let config = JSON.parse(localStorage.getItem('lcs_config'));
+                                config.webrtc = true;
+                                localStorage.setItem('lcs_config', JSON.stringify(config));
+                                //this._switch.checked = false;
+                            } else {
+                                let config = JSON.parse(localStorage.getItem('lcs_config'));
+                                config.webrtc = false;
+                                localStorage.setItem('lcs_config', JSON.stringify(config));
+                            }
+                        }
+                    }
+                  }
+                  ),
+                  {
+                    $type: 'label',
+                    for: 'input-forceWebRTC',
+                    $text: 'On / Off'
+                  }
+    
+                ]
+              }
+
             let luminaryGlobalHB = {
                 $cell: true,
                 _luminarySwitch: null,
@@ -757,6 +805,7 @@ Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contribu
                     if (config.luminaryGlobalHBPath) {
                         this._hbpath = config.luminaryGlobalHBPath
                     }
+
                 },
                 $init: function () {
                     this._initData();
@@ -832,6 +881,11 @@ Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contribu
                                         }),
                                     ]
                                 },
+                                { 
+                                    $type: "div",
+                                    class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
+                                    $components: [webrtcConnection ]
+                                   },
                                 {
                                     $type: "div",
                                     class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",

+ 2 - 2
public/luminary.js

@@ -3,12 +3,12 @@ The MIT License (MIT)
 Copyright (c) 2014-2019 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
 */
 
-import { Helpers } from '/helpers.js';
+//import { Helpers } from '/helpers.js';
 
 class Luminary {
     constructor() {
         console.log("luminary constructor");
-        this.helpers = new Helpers;
+        this.helpers = _app.helpers; //new Helpers;
         this.info = {};
         this.pendingList = [];
         this.status = { pending: true, initialized: false, trials: 3 };

+ 2 - 2
public/reflector-client.js

@@ -5,12 +5,12 @@ Copyright (c) 2014-2019 Nikolai Suslov and the Krestianstvo.org project contribu
 Virtual World Framework Apache 2.0 license  (https://github.com/NikolaySuslov/livecodingspace/blob/master/licenses/LICENSE_VWF.md)
 */
 
-import { Helpers } from '/helpers.js';
+//import { Helpers } from '/helpers.js';
 
 class ReflectorClient {
     constructor() {
         console.log("reflector client constructor");
-        this.helpers = new Helpers;
+        this.helpers = _app.helpers; //new Helpers;
         this.socket = undefined;
     }
 

+ 2 - 2
public/web/header.js

@@ -3,11 +3,11 @@ The MIT License (MIT)
 Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
 */
 
-import page from '/lib/page.mjs';
+//import page from '/lib/page.mjs';
 
 class Header {
     constructor() {
-        console.log("app constructor");
+        console.log("header constructor");
         this.language = _LangManager.language;
 
     }

+ 1 - 1
public/web/index-app.js

@@ -9,7 +9,7 @@ import { Header } from '/web/header.js';
 
 class IndexApp {
     constructor() {
-        console.log("app constructor");
+        console.log("index app constructor");
 
 
         this.worlds = {};

+ 1 - 1
public/web/world-app.js

@@ -7,7 +7,7 @@ Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contribu
 
 class WorldApp {
     constructor(userAlias, worldName, saveName) {
-        console.log("app constructor");
+        console.log("world app constructor");
 
         this.userAlias = userAlias;
         this.worldName = worldName;