From f59842e7a9d66260493630033806014ea4ec61e3 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 16 Apr 2024 18:40:49 +0200 Subject: [PATCH] handle relative uri's better --- src/3rd/js/plugin/frontend/$chat.js | 4 ++-- src/3rd/js/plugin/frontend/$connections.js | 2 +- src/3rd/js/plugin/frontend/frontend.js | 6 +++--- src/3rd/js/plugin/matrix/matrix.js | 3 +-- src/3rd/js/plugin/p2p/trystero.js | 12 +++--------- src/3rd/js/three/navigator.js | 12 ++++++++++-- src/xrfragment/URI.hx | 3 +++ 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/3rd/js/plugin/frontend/$chat.js b/src/3rd/js/plugin/frontend/$chat.js index 296eac8..5e7c884 100644 --- a/src/3rd/js/plugin/frontend/$chat.js +++ b/src/3rd/js/plugin/frontend/$chat.js @@ -105,7 +105,7 @@ chatComponent = { br.classList.add.apply(br.classList, opts.class) div.classList.add.apply(div.classList, opts.class.concat(["envelope"])) } - if( !msg.className.match(/(info|guide|ui)/) ){ + if( msg.className.match(/(info|guide|ui)/) || !opts.from ){ let frag = xrf.URI.parse(document.location.hash).XRF opts.from = 'you' if( frag.pos ) opts.pos = frag.pos.string @@ -187,7 +187,7 @@ chatComponent.css = ` bottom: 0; right: 0; margin: 15px; - z-index:1500; + z-index:1000; } #videos > video{ border-radius:7px; diff --git a/src/3rd/js/plugin/frontend/$connections.js b/src/3rd/js/plugin/frontend/$connections.js index 7adb842..13c5f2c 100644 --- a/src/3rd/js/plugin/frontend/$connections.js +++ b/src/3rd/js/plugin/frontend/$connections.js @@ -269,7 +269,7 @@ connectionsComponent = { } // reactify component! -document.addEventListener('$menu:ready', (opts) => { +document.addEventListener('$chat:ready', (opts) => { opts = opts.detail document.head.innerHTML += connectionsComponent.css window.$connections = document.createElement('div') diff --git a/src/3rd/js/plugin/frontend/frontend.js b/src/3rd/js/plugin/frontend/frontend.js index 199cc84..b40df29 100644 --- a/src/3rd/js/plugin/frontend/frontend.js +++ b/src/3rd/js/plugin/frontend/frontend.js @@ -301,10 +301,10 @@ window.frontend = (opts) => new Proxy({ share(opts){ opts = opts || {notify:true,qr:true,share:true,linkonly:false} - if( network.meetingLink && !document.location.hash.match(/meet=/) ){ - document.location.hash += `&meet=${network.meetingLink}` + if( network.meetingLink && !xrf.navigator.URI.hash.meet ){ + xrf.navigator.URI.hash.meet = network.meetingLink } - if( !document.location.hash.match(/pos=/) && (network.posName || network.pos) ){ + if( !xrf.navigator.URI.hash.pos && (network.posName || network.pos) ){ xrf.navigator.URI.hash.pos = network.posName || network.pos }else frontend.updateHashPosition() diff --git a/src/3rd/js/plugin/matrix/matrix.js b/src/3rd/js/plugin/matrix/matrix.js index 487f492..9da5921 100644 --- a/src/3rd/js/plugin/matrix/matrix.js +++ b/src/3rd/js/plugin/matrix/matrix.js @@ -293,12 +293,11 @@ window.matrix = (opts) => new Proxy({ }, createLink(opts){ - let hash = document.location.hash if( !this.link ){ const meeting = network.getMeetingFromUrl(document.location.href) this.link = network.meetingLink = meeting.match("matrix://") ? meeting : '' } - if( !hash.match('meet=') ) document.location.hash += `${hash.length > 1 ? '&' : '#'}meet=${this.link}` + if( !xrf.navigator.URI.hash.meet ) xrf.navigator.URI.hash.meet = this.link }, reactToConnectionHrefs(){ diff --git a/src/3rd/js/plugin/p2p/trystero.js b/src/3rd/js/plugin/p2p/trystero.js index 36c3baf..73b7ab4 100644 --- a/src/3rd/js/plugin/p2p/trystero.js +++ b/src/3rd/js/plugin/p2p/trystero.js @@ -51,14 +51,10 @@ window.trystero = (opts) => new Proxy({ $connections.webcam = $connections.webcam.concat([this]) $connections.chatnetwork = $connections.chatnetwork.concat([this]) $connections.scene = $connections.scene.concat([this]) - if( localStorage.getItem("selfId") ){ - this.selfId = localStorage.getItem("selfId") - }else{ - this.selfId = String(Math.random()).substr(2) - localStorage.setItem("selfId",this.selfId) - } + this.selfId = selfId // selfId is a trystero global (unique per session) this.reactToConnectionHrefs() this.nickname = localStorage.getItem("nickname") || `human${String(Math.random()).substr(5,4)}` + this.names[ this.selfId ] = this.nickname document.addEventListener('network.connect', (e) => this.connect(e.detail) ) document.addEventListener('network.init', () => { let meeting = network.getMeetingFromUrl(document.location.href) @@ -72,7 +68,6 @@ window.trystero = (opts) => new Proxy({ if( !this.connected ){ this.connected = true frontend.emit('network.connected',{plugin:this,username: this.nickname}) - this.names[ this.selfId ] = this.nickname } }, @@ -208,12 +203,11 @@ window.trystero = (opts) => new Proxy({ send(opts){ $chat.send({...opts, source: 'trystero'}) }, createLink(opts){ - let hash = document.location.hash if( !this.link ){ const meeting = network.getMeetingFromUrl(document.location.href) this.link = network.meetingLink = meeting.match("trystero://") ? meeting : `trystero://r/${network.randomRoom()}:bittorrent` } - if( !hash.match('meet=') ) document.location.hash += `${hash.length > 1 ? '&' : '#'}meet=${this.link}` + if( !xrf.navigator.URI.hash.meet ) xrf.navigator.URI.hash.meet = this.link }, config(opts){ diff --git a/src/3rd/js/three/navigator.js b/src/3rd/js/three/navigator.js index 2abca7c..319a1c4 100644 --- a/src/3rd/js/three/navigator.js +++ b/src/3rd/js/three/navigator.js @@ -1,4 +1,12 @@ -xrf.navigator = {URI:{}} +xrf.navigator = { + URI:{ + scheme: document.location.protocol.replace(/:$/,''), + directory: document.location.pathname, + host: document.location.hostname, + port: document.location.port, + file: 'index.glb' + } +} xrf.navigator.to = (url,flags,loader,data) => { if( !url ) throw 'xrf.navigator.to(..) no url given' @@ -181,7 +189,7 @@ xrf.navigator.reactifyHash = ( obj ) => { toString(me){ let parts = [] Object.keys(me).map( (k) => { - parts.push( me[k] ? `${k}=${encodeURIComponent(me[k])}` : k ) + parts.push( me[k] ? `${k}=${me[k]}` : k ) }) return parts.join('&') } diff --git a/src/xrfragment/URI.hx b/src/xrfragment/URI.hx index c570dc0..ac4ad2c 100644 --- a/src/xrfragment/URI.hx +++ b/src/xrfragment/URI.hx @@ -147,6 +147,7 @@ class URI { { url.file = url.host; } + url.host = ""; } url.hash = {}; @@ -442,6 +443,8 @@ class URI { if (newURI.file != null) { resultURI.file = newURI.file; + }else{ + resultURI.file = url.file; } resultURI.path = resultURI.directory + resultURI.file;