From 3a8e730a1aa654494d5d0bb2fe509be24b4a41f8 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Mon, 24 Sep 2018 21:31:54 +0200 Subject: [PATCH] Add query param to automatically upload avatar E.g. to automatically use Matrix avatar when embedded as a Matrix widget --- app/index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/index.js b/app/index.js index 1b149ef..1eed3ad 100644 --- a/app/index.js +++ b/app/index.js @@ -800,6 +800,33 @@ window.onload = function () { if (queryParams.password) { ui.connectDialog.password(queryParams.password) } + if (queryParams.avatarurl) { + // Download the avatar and upload it to the mumble server when connected + let url = queryParams.avatarurl + console.log('Fetching avatar from', url) + let req = new window.XMLHttpRequest() + req.open('GET', url, true) + req.responseType = 'arraybuffer' + req.onload = () => { + let upload = (avatar) => { + if (req.response) { + console.log('Uploading user avatar to server') + ui.client.setSelfTexture(req.response) + } + } + // On any future connections + ui.thisUser.subscribe((thisUser) => { + if (thisUser) { + upload() + } + }) + // And the current one (if already connected) + if (ui.thisUser()) { + upload() + } + } + req.send() + } ui.connectDialog.joinOnly(useJoinDialog) ko.applyBindings(ui) }