handle relative uri's better

This commit is contained in:
Leon van Kammen 2024-04-16 18:40:49 +02:00
parent 45b46f788c
commit f59842e7a9
7 changed files with 23 additions and 19 deletions

View file

@ -105,7 +105,7 @@ chatComponent = {
br.classList.add.apply(br.classList, opts.class) br.classList.add.apply(br.classList, opts.class)
div.classList.add.apply(div.classList, opts.class.concat(["envelope"])) 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 let frag = xrf.URI.parse(document.location.hash).XRF
opts.from = 'you' opts.from = 'you'
if( frag.pos ) opts.pos = frag.pos.string if( frag.pos ) opts.pos = frag.pos.string
@ -187,7 +187,7 @@ chatComponent.css = `
bottom: 0; bottom: 0;
right: 0; right: 0;
margin: 15px; margin: 15px;
z-index:1500; z-index:1000;
} }
#videos > video{ #videos > video{
border-radius:7px; border-radius:7px;

View file

@ -269,7 +269,7 @@ connectionsComponent = {
} }
// reactify component! // reactify component!
document.addEventListener('$menu:ready', (opts) => { document.addEventListener('$chat:ready', (opts) => {
opts = opts.detail opts = opts.detail
document.head.innerHTML += connectionsComponent.css document.head.innerHTML += connectionsComponent.css
window.$connections = document.createElement('div') window.$connections = document.createElement('div')

View file

@ -301,10 +301,10 @@ window.frontend = (opts) => new Proxy({
share(opts){ share(opts){
opts = opts || {notify:true,qr:true,share:true,linkonly:false} opts = opts || {notify:true,qr:true,share:true,linkonly:false}
if( network.meetingLink && !document.location.hash.match(/meet=/) ){ if( network.meetingLink && !xrf.navigator.URI.hash.meet ){
document.location.hash += `&meet=${network.meetingLink}` 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 xrf.navigator.URI.hash.pos = network.posName || network.pos
}else frontend.updateHashPosition() }else frontend.updateHashPosition()

View file

@ -293,12 +293,11 @@ window.matrix = (opts) => new Proxy({
}, },
createLink(opts){ createLink(opts){
let hash = document.location.hash
if( !this.link ){ if( !this.link ){
const meeting = network.getMeetingFromUrl(document.location.href) const meeting = network.getMeetingFromUrl(document.location.href)
this.link = network.meetingLink = meeting.match("matrix://") ? meeting : '' 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(){ reactToConnectionHrefs(){

View file

@ -51,14 +51,10 @@ window.trystero = (opts) => new Proxy({
$connections.webcam = $connections.webcam.concat([this]) $connections.webcam = $connections.webcam.concat([this])
$connections.chatnetwork = $connections.chatnetwork.concat([this]) $connections.chatnetwork = $connections.chatnetwork.concat([this])
$connections.scene = $connections.scene.concat([this]) $connections.scene = $connections.scene.concat([this])
if( localStorage.getItem("selfId") ){ this.selfId = selfId // selfId is a trystero global (unique per session)
this.selfId = localStorage.getItem("selfId")
}else{
this.selfId = String(Math.random()).substr(2)
localStorage.setItem("selfId",this.selfId)
}
this.reactToConnectionHrefs() this.reactToConnectionHrefs()
this.nickname = localStorage.getItem("nickname") || `human${String(Math.random()).substr(5,4)}` 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.connect', (e) => this.connect(e.detail) )
document.addEventListener('network.init', () => { document.addEventListener('network.init', () => {
let meeting = network.getMeetingFromUrl(document.location.href) let meeting = network.getMeetingFromUrl(document.location.href)
@ -72,7 +68,6 @@ window.trystero = (opts) => new Proxy({
if( !this.connected ){ if( !this.connected ){
this.connected = true this.connected = true
frontend.emit('network.connected',{plugin:this,username: this.nickname}) 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'}) }, send(opts){ $chat.send({...opts, source: 'trystero'}) },
createLink(opts){ createLink(opts){
let hash = document.location.hash
if( !this.link ){ if( !this.link ){
const meeting = network.getMeetingFromUrl(document.location.href) const meeting = network.getMeetingFromUrl(document.location.href)
this.link = network.meetingLink = meeting.match("trystero://") ? meeting : `trystero://r/${network.randomRoom()}:bittorrent` 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){ config(opts){

View file

@ -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) => { xrf.navigator.to = (url,flags,loader,data) => {
if( !url ) throw 'xrf.navigator.to(..) no url given' if( !url ) throw 'xrf.navigator.to(..) no url given'
@ -181,7 +189,7 @@ xrf.navigator.reactifyHash = ( obj ) => {
toString(me){ toString(me){
let parts = [] let parts = []
Object.keys(me).map( (k) => { 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('&') return parts.join('&')
} }

View file

@ -147,6 +147,7 @@ class URI {
{ {
url.file = url.host; url.file = url.host;
} }
url.host = "";
} }
url.hash = {}; url.hash = {};
@ -442,6 +443,8 @@ class URI {
if (newURI.file != null) if (newURI.file != null)
{ {
resultURI.file = newURI.file; resultURI.file = newURI.file;
}else{
resultURI.file = url.file;
} }
resultURI.path = resultURI.directory + resultURI.file; resultURI.path = resultURI.directory + resultURI.file;