xrfragment/dist/xrfragment.plugin.matrix.js

127 lines
8.9 MiB
JavaScript
Raw Normal View History

2024-01-03 15:23:34 +01:00
(function(){
/*! For license information please see matrix-crdt.js.LICENSE.txt */
!function(A,g){"object"==typeof exports&&"object"==typeof module?module.exports=g():"function"==typeof define&&define.amd?define([],g):"object"==typeof exports?exports.matrix=g():A.matrix=g()}(self,(()=>(()=>{var A={7746:(A,g,I)=>{A=I.nmd(A);let Q,B={};B.__wbindgen_placeholder__=A.exports;let C=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});C.decode();let E=null;function o(){return null!==E&&0!==E.byteLength||(E=new Uint8Array(Q.memory.buffer)),E}function n(A,g){return A>>>=0,C.decode(o().subarray(A,A+g))}const i=new Array(128).fill(void 0);i.push(void 0,null,!0,!1);let D=i.length;function a(A){D===i.length&&i.push(i.length+1);const g=D;return D=i[g],i[g]=A,g}function G(A){return i[A]}function c(A){const g=G(A);return function(A){A<132||(i[A]=D,D=A)}(A),g}function t(A){return null==A}let e=null;function s(){return null!==e&&0!==e.byteLength||(e=new Float64Array(Q.memory.buffer)),e}let N=null;function h(){return null!==N&&0!==N.byteLength||(N=new Int32Array(Q.memory.buffer)),N}let w=0,Y=new TextEncoder("utf-8");const y="function"==typeof Y.encodeInto?function(A,g){return Y.encodeInto(A,g)}:function(A,g){const I=Y.encode(A);return g.set(I),{read:A.length,written:I.length}};function M(A,g,I){if(void 0===I){const I=Y.encode(A),Q=g(I.length,1)>>>0;return o().subarray(Q,Q+I.length).set(I),w=I.length,Q}let Q=A.length,B=g(Q,1)>>>0;const C=o();let E=0;for(;E<Q;E++){const g=A.charCodeAt(E);if(g>127)break;C[B+E]=g}if(E!==Q){0!==E&&(A=A.slice(E)),B=I(B,Q,Q=E+3*A.length,1)>>>0;const g=o().subarray(B+E,B+Q);E+=y(A,g).written}return w=E,B}let k=null;function l(A){const g=typeof A;if("number"==g||"boolean"==g||null==A)return`${A}`;if("string"==g)return`"${A}"`;if("symbol"==g){const g=A.description;return null==g?"Symbol":`Symbol(${g})`}if("function"==g){const g=A.name;return"string"==typeof g&&g.length>0?`Function(${g})`:"Function"}if(Array.isArray(A)){const g=A.length;let I="[";g>0&&(I+=l(A[0]));for(let Q=1;Q<g;Q++)I+=", "+l(A[Q]);return I+="]",I}const I=/\[object ([^\]]+)\]/.exec(toString.call(A));let Q;if(!(I.length>1))return toString.call(A);if(Q=I[1],"Object"==Q)try{return"Object("+JSON.stringify(A)+")"}catch(A){return"Object"}return A instanceof Error?`${A.name}: ${A.message}\n${A.stack}`:Q}const R=new FinalizationRegistry((A=>{Q.__wbindgen_export_2.get(A.dtor)(A.a,A.b)}));function J(A,g,I,B){const C={a:A,b:g,cnt:1,dtor:I},E=(...A)=>{C.cnt++;const g=C.a;C.a=0;try{return B(g,C.b,...A)}finally{0==--C.cnt?(Q.__wbindgen_export_2.get(C.dtor)(g,C.b),R.unregister(C)):C.a=g}};return E.original=C,R.register(E,C,C),E}function F(A,g,I){try{const C=Q.__wbindgen_add_to_stack_pointer(-16);Q.wasm_bindgen__convert__closures__invoke1_mut__hbc098da5d2b7498e(C,A,g,a(I));var B=h()[C/4+0];if(h()[C/4+1])throw c(B)}finally{Q.__wbindgen_add_to_stack_pointer(16)}}function O(A,g,I,B){const C={a:A,b:g,cnt:1,dtor:I},E=(...A)=>{C.cnt++;try{return B(C.a,C.b,...A)}finally{0==--C.cnt&&(Q.__wbindgen_export_2.get(C.dtor)(C.a,C.b),C.a=0,R.unregister(C))}};return E.original=C,R.register(E,C,C),E}function Z(A,g){Q._dyn_core__ops__function__Fn_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbff97dce5937efeb(A,g)}function m(A,g,I){Q._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h6d3bd38ffc42664a(A,g,a(I))}function d(A,g,I){Q._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h8cef6383e8d1f614(A,g,a(I))}function U(A,g){Q._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4892df90e815ea9(A,g)}function j(A,g){if(!(A instanceof g))throw new Error(`expected instance of ${g.name}`);return A.ptr}let p=128;function r(A){if(1==p)throw new Error("out of js stack");return i[--p]=A,p}function b(A,g){const I=g(1*A.length,1)>>>0;return o().set(A,I/1),w=A.length,I}function L(A,g){return A>>>=0,o().subarray(A/1,A/1+g)}function S(A,g){try{return A.apply(this,g)}catch(A){Q.__wbindgen_exn_store(a(A))}}A.exports.getVersions=function(){const A=Q.getVersions();return Kg.__wrap(A)},A.exports.star
el: null, // HTML element
plugin:{
type: 'network',
name: '[Matrix]',
description: 'a standardized decentralized privacy-friendly protocol',
url: 'https://matrix.org',
protocol: 'matrix://',
video: false,
audio: false,
chat: true,
scene: true
},
html: {
generic: (opts) => `<div>
<a href="${opts.url}" target="_blank" class="badge ruler">matrix</a>
<table>
<tr>
<td>channel</td>
<td>
<input type="text" id="channel" placeholder="#xrfragment:matrix.org"/>
</td>
</tr>
<tr>
<td>server</td>
<td>
<input type="text" id="server" placeholder="https://matrix.org"/>
</td>
</tr>
<tr>
<td>user</td>
<td>
<input type="text" id="username" placeholder="@you:matrix.org"/>
</td>
</tr>
<tr>
<td>auth</td>
<td>
<select id="auth">
<option>via password</option>
<option>via access token</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="text" id="secret" placeholder="enter password"/>
</td>
</tr>
</table>
<small style="display:inline-block;float:right">Support for Oauth / OpenID is <a href="https://matrix.org/blog/#openid-connect" target="_blank">in progress</a></small>
<br>
</div>
`
},
init(){
frontend.plugin['matrix'] = this
$connections.chatnetwork = $connections.chatnetwork.concat([this])
$connections.scene = $connections.scene.concat([this])
this.reactToConnectionHrefs()
},
connect(opts){
console.log("connecting "+this.plugin.name)
console.dir(opts)
},
config(opts){
opts = {...opts, ...this.plugin }
this.el = document.createElement('div')
let html = this.html.generic(opts)
for( let i in opts ){
if( this.html[i] ) html += this.html[i](opts)
}
this.el.innerHTML = html
this.el.querySelector('#auth').addEventListener('change', (e) => {
this.el.querySelector('#secret').setAttribute('placeholder', `enter ${e.target.value.replace(/.* /,'')}`)
})
window.notify(`${opts.name} is ${opts.description}, it is the hottest internet technology available at this moment.<br>Read more about it <a href="${opts.url}" target="_blank">here</a>.<br>You can basically make up a new channelname or use an existing one`)
return this.el
},
reactToConnectionHrefs(){
xrf.addEventListener('href', (opts) => {
let {mesh} = opts
if( !opts.click ) return
if( mesh.userData.href.match(this.protocol) ){
let parts = mesh.userData.href.replace(this.plugin.protocol,'')
if( parts[0] == 'r' ){ // room
let server = parts.split("/")[1].replace(/:.*/,'')
let channel = parts.split("/")[1].replace(/.*:/,'')
$connections.show()
$connections.selectedChatnetwork = this.plugin.name
$connections.selectedScene = this.plugin.name
this.el.querySelector('#channel').value = `#${channel}:${server}`
this.el.querySelector('#server').value = server
console.log("configured matrix")
}
}else window.notify("malformed connection URI: "+mesh.userData.href)
})
}
},
{
// auto-trigger events on changes
get(data,k,receiver){ return data[k] },
set(data,k,v){
let from = data[k]
data[k] = v
//switch( k ){
// default: matrix.opts.scene.dispatchEvent({type:`matrix.${k}.change`, from, to:v})
//}
}
})
document.addEventListener('$connections:ready', (e) => {
matrix(e.detail).init()
})
}).apply({})