Skip to content

Instantly share code, notes, and snippets.

View Utopiah's full-sized avatar

Fabien Benetou Utopiah

View GitHub Profile
const express = require("express");
const app = express();
const fs = require('fs');
const fetch = require('node-fetch');
const tokenFile = './.ret.credentials'
const token = JSON.parse(fs.readFileSync(tokenFile, 'utf8')).token;
const accountURL = 'https://myhubsURL.com/api/v1/accounts'
app.use(express.json())
previousMeasures = JSON.parse( localStorage.getItem('hubs-measurements-positions') );
if (!previousMeasures) previousMeasures = []
//clearInterval(measuring)
let measuring = setInterval(addMeasure, 1*1000 )
function addMeasure(){
let moment = Date.now()
let connected = []
const watchedNode = document.querySelector("[class^=presence-log]")
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
for (var n of mutation.addedNodes){
console.log(+Date.now(), n.textContent)
}
}
})
})
var ui = document.querySelector("[title=Members]")
// requires the presence menu to be open (because React) but could be hidden via CSS
if ( !ui.className.match("selected") ) {
ui.dispatchEvent(new MouseEvent("click",{bubbles: true, cancellable: true}))
}
//ui.nextSibling.style.display = "none" // hides UI if you are streaming
previousMeasures = JSON.parse( localStorage.getItem('hubs-measurements') );
if (!previousMeasures) previousMeasures = []
// Get the URL of a Hubs room that is not empty nor at room capacity
// Warning: the proper API is being defined at https://github.com/mozilla/reticulum/pull/382
let getBestRoom = async () => {
// by https://twitter.com/jamesckane for @paracreative worked on the #ApartPosters show.
// let endpoint = "https://show.apartposters.com/api/v1/media/search?source=rooms&filter=public";
let endpoint = "/api/v1/media/search?source=rooms&filter=public";
let response = await fetch(endpoint);
let json = await response.json();
let rooms = json.entries;
let bestRoom = {};
var hubsProxy = "https://hubs-spatializedinternal-link-cors-proxy.vrtohubs.workers.dev/"
var playlist = [
"https://vrtovideostreaming.s3.us-east-2.amazonaws.com/Accessibility/CC+John+Avila+-+Designing+Accessible+Experiences+for+VR+and+AR+720p.mp4",
"https://vrtovideostreaming.s3.us-east-2.amazonaws.com/Accessibility/CC+VRTO2020+Wishplay+and+VR+-+David+Parker+-+Final.mp4"
]
var currentVideo = 0
function videoEnded(){
console.log('video ended')
if (currentVideo == playlist.length-1 ) {
// works on https://aframe.io/aframe/examples/boilerplate/hello-world/
// but not on https://hubs.mozilla.com/8vXHv5j/d435-realsense-scan
// cf https://twitter.com/utopiah/status/1269536076726706177
var scriptEl = document.createElement("script")
scriptEl.setAttribute("src", "https://fabien.benetou.fr/pub/home/depthkitjs-data0540-fabien-example/latest-depthkit.js")
// latest version of depthkit.js since the version in the AFrame component is oudated
scriptEl.classList.add('loadedscripts')
document.head.appendChild(scriptEl)
scriptEl.onload = readyScript
// clone ://github.com/MozillaReality/hubs-discord-bot/ then replace src/index.js
// check also the .env.defaults in order to target the right reticulum server
const myRoomId = "XXXXXXX"
// process.argv.forEach(function (val, index, array) { console.log(index + ': ' + val); });
// could be used for target Hubs and welcome message
// Variables in .env and .env.defaults will be added to process.env
const dotenv = require("dotenv");
dotenv.config({ path: ".env" });
var yourSceneURL = 'https://hubs.mozilla.com/LHzDxae/' // no trailing room name, only ID.
// Also works on Hubs Cloud servers but assets have to remain available (i.e no CORS, 404, etc)
// example of grabbing a local copy of assets hosted with the proxy
// curl https://hubs.mozilla.com/LHzDxae/objects.gltf | jq .nodes[].extensions.HUBS_components.media.src -r | grep uploads-prod.reticulum.io
function populateSceneFromMozGLTF(scene){
document.querySelector('*[networked-counter]').setAttribute('networked-counter', {max: 100})
for (var node of scene.nodes){
console.log(node)
// using el.children[1] to ignore the menu
// alt el.object3D.traverse(o=> {if (o.type=="Mesh") mesh_bg=o})
// has to be clarified on other objects e.g. media-image rather than glTF
var burger = getFirstElementFromHash('eke7')
var bbox_burger = new THREE.Box3().setFromObject( burger.children[1].object3D );
var helper = new THREE.Box3Helper( bbox_burger, 0xffff00 );
AFRAME.scenes[0].sceneEl.object3D.add( helper );
var aquarium = getFirstElementFromHash('2Rb9')