Skip to content

Instantly share code, notes, and snippets.

@Utopiah
Last active February 2, 2022 03:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Utopiah/9e8c4fa996831859a1c099a9906f84e9 to your computer and use it in GitHub Desktop.
Save Utopiah/9e8c4fa996831859a1c099a9906f84e9 to your computer and use it in GitHub Desktop.
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 = []
//clearInterval(measuring)
let measuring = setInterval(addMeasure, 60*1000 )
function addMeasure(){
let moment = Date.now()
let connected = []
for (let r of document.querySelectorAll("[class^=presence-list__row__]")){
let nick = hashCode( r.querySelector("[class*=item__]").innerText.replace("★","") )
let presence = r.querySelector("[class*=presence__]").innerText
connected.push( {hash:nick, presence:presence} )
}
// ignored as it is only for persons in the room
// for (let a of document.querySelectorAll("[networked-avatar]"))
// connected.push( a.getAttribute("networked").networkId )
previousMeasures.push( {now:moment, connected:connected} )
localStorage.setItem('hubs-measurements', JSON.stringify(previousMeasures));
// Alternatively the data could be posted periodically to a micro-service
// then allowing live analytics e.g. https://observablehq.com/@utopiah/mozilla-hubs-event-stats
}
// to log chat see also https://gist.github.com/Utopiah/44d38c33dc9ab38f123530e4db1c49b8
const hashCode = s => s.split('').reduce((a,b) => (((a << 5) - a) + b.charCodeAt(0))|0, 0)
// via https://stackoverflow.com/a/34842797
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment