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)
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;

View File

@ -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')

View File

@ -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()

View File

@ -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(){

View File

@ -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){

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) => {
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('&')
}

View File

@ -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;