const PeertubeTranslatorBaseURL = document.currentScript.src.replace("/translator.js","") elation.require([], function() { elation.component.add('janusweb.translators.peertube', function() { this.init = function() { this.description = "peertube website to 3D translator" } this.exec = function(args) { return new Promise(elation.bind(this, function(resolve, reject) { var room = this.room = args.room; reject() // for now this.setupEvents() var datapath = elation.config.get('janusweb.datapath', '/media/janusweb'); var roomdata = { assets: { assetlist: [ // {assettype: 'model', name: 'scene', src: args.url}, ] }, room: { pos: [0,0,0], xdir: "1 0 0", zdir: "0 0 1", }, object: [ // {id: 'scene', js_id: 0, pos: "0 0 0", xdir: "-1 0 0", zdir: "0 0 -1", lighting: "false"} ], link: [] }; resolve(roomdata); })); } // translate XR Fragments microformat into JML this.parseSource = async function(sourcecode, room){ this.room = room const isJML = /[\s\S]*?<\/fireboxroom>/si; const isPeertube = /]*property=['"]og:platform['"]\s+[^>]*content=['"]peertube['"][^>]*\/?>/si; const isPeertubeVideo = /]*property=['"]og:type['"]\s+[^>]*content=['"]video['"][^>]*\/?>/si; const isPeertubeInstance = /]*property=['"]og:type['"]\s+[^>]*content=['"]website['"][^>]*\/?>/si; const is = { JML: sourcecode.match(isJML), peertube: sourcecode.match(isPeertube), peertubeVideo: sourcecode.match(isPeertubeVideo), peertubeInstance: sourcecode.match(isPeertubeInstance), } if( is.JML || !is.peertube ) return // JML takes precedence over microformats if( !is.peertubeVideo && !is.peertubeInstance ) return // ok..peertube time: get domtree let el = document.createElement("div") el.innerHTML = sourcecode // try to fetch title + cover const title = el.querySelector("title") let logo = el.querySelector("meta[property='og:image']")?.getAttribute("content") logo = logo ? logo : el.querySelector("meta[property='og:image:url']")?.getAttribute("content") let url = new URL( String(room.url) ) let instance = url?.origin let search = url?.search ? new URLSearchParams(url.search).get("search") : "" room.corsproxy = '' // return JML let parsed = room.parseSource(` ${ title ? title.innerText.replace(/\n.*/g,'') : room.baseurl.split("/").pop() } ${ logo ? ` ${ is.peertubeInstance ? `` : `` } ${ logo ? `` : ''} `) return parsed } // peertube microformat heuristic: this.parseSource.regex = /]*property=['"]og:platform['"]\s+[^>]*content=['"]peertube['"][^>]*\/?>/si; }); }); elation.events.add(null, 'room_translator_register', function(e){ const room = e.element const translators = e.data.translators // prepend translator e.data.translators = {} e.data.translators['!peertube'] = elation.janusweb.translators.peertube({janus: janus}) for( let i in translators ){ e.data.translators[i] = translators[i] } })