Skip to content

Instantly share code, notes, and snippets.

@pearj
Last active February 19, 2022 09:12
Show Gist options
  • Save pearj/639d35b582fc3bf769a24a5c953701dd to your computer and use it in GitHub Desktop.
Save pearj/639d35b582fc3bf769a24a5c953701dd to your computer and use it in GitHub Desktop.
This is the beginnings of Google Meets integration with Jabra headsets.
// ==UserScript==
// @name Jabra - Google Meets
// @namespace Violentmonkey Scripts
// @match https://meet.google.com/*
// @grant none
// @version 1.0
// @author -
// @description 19/09/2021, 11:53:37
// @requireingore https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @requireignore https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@1
// @require https://raw.githubusercontent.com/gnaudio/jabra-browser-integration/master/src/JavaScriptLibrary/jabra.browser.integration-3.0.js
// @require https://raw.githubusercontent.com/f3oall/awesome-notifications/master/dist/index.var.js
// @run-at document-end
// ==/UserScript==
/**
* Requirements:
* You must install the following Jabra things first:
* * Jabra ChromeHost - https://developer.jabra.com/site/global/software/integration-components/browser/index.gsp
* * Jabra Browser Integration Extension - https://chrome.google.com/webstore/detail/jabra-browser-integration/okpeabepajdgiepelmhkfhkjlhhmofma
*
* Jabra have some documentation about the browser extension here: https://developer.jabra.com/site/global/software/integration-components/browser/documentation.gsp
* and they have a sample Javascript page you can use to test out that the extension is working correctly: https://gnaudio.github.io/jabra-browser-integration/release/development/
*/
// var newCSS = GM_getResourceText ("awesomeCss");
// GM_addStyle (newCSS);
// debugger;
function addCss(cssUrl) {
let link = document.createElement("link")
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = cssUrl;
link.media = 'all';
document.head.appendChild(link);
}
addCss('https://f3oall.github.io/awesome-notifications/assets/css/style.css?v=8a1d3104c509964ebd7ff91202b41c936df37f48')
var toastr = {
info: (msg) => {
// Awesome notifications isn't working anymore due to some TrustedHtml error, I guess google meets changed.
// new AWN().info(msg, {icons: {enabled: false}})
console.log(msg);
}
}
// console.log("Jabra should be here now");
function showError(err) {
let msg;
if (err.name === "CommandError" && err.errmessage === "Unknown cmd" && err.command === "getinstallinfo") {
msg = "Could not lookup installation info - Your installation is incomplete, out of date or corrupted.";
} else if (err instanceof Error) {
msg = err.toString();
} else if ((typeof err === 'string') || (err instanceof String)) {
msg = err;
} else {
msg = JSON.stringify(err);
}
// Add nodes to show the error message
// var div = document.createElement("div");
// var att = document.createAttribute("class");
// att.value = "wrapper";
// div.setAttributeNode(att);
// div.innerHTML = msg;
// var br = document.createElement("br");
// var list = document.getElementById("section");
// list.insertBefore(br, list.childNodes[0]);
// list.insertBefore(div, list.childNodes[0]);
toastr.info(msg);
}
function setupDevices() {
jabra.getDevices().then((devices) => {
console.log(devices);
});
}
// Refresh device list automatically when devices are inserted/removed:
jabra.addEventListener(["device attached", "device detached"], (event) => {
setupDevices();
});
var micNode = undefined;
window.addEventListener('beforeunload', () => {
jabra.onHook();
})
jabra.addEventListener("mute", (event) => {
console.log("mute button clicked")
if (micNode) {
let isMicMuted = micNode.getAttribute('data-is-muted').toLowerCase().indexOf('true') !== -1
if (!isMicMuted) {
micNode.click();
}
}
});
jabra.addEventListener("unmute", (event) => {
console.log("unmute button clicked")
if (micNode) {
let isMicMuted = micNode.getAttribute('data-is-muted').toLowerCase().indexOf('true') !== -1
if (isMicMuted) {
micNode.click();
}
}
});
// Use the Jabra library - to be sure of the installation we also check it and report errors
// This installation check is optional but is there to reduce support issues.
jabra.init().then(() => jabra.getInstallInfo()).then((installInfo) => {
if (installInfo.installationOk) {
toastr.info("Jabra library initialized successfully");
setupDevices();
VM.observe(document.body, () => {
// Find the target node
const node = document.querySelector('[data-is-muted][role=button]')
if (node) {
micNode = node;
jabra.offHook();
VM.observe(node, () => {
console.log("Mic button changed")
let isMicMuted = node.getAttribute('data-is-muted').toLowerCase().indexOf('true') !== -1
if (isMicMuted) {
jabra.mute();
} else {
jabra.unmute();
}
}, {
childList: false,
subTree: false,
attributes: true,
attributeFilter: ['data-is-muted']
})
// disconnect observer
return true;
}
});
} else { // Installation not ok:
showError("Installation not ok - Your installation is incomplete, out of date or corrupted.");
}
}).catch((err) => {
showError(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment