Skip to content

Instantly share code, notes, and snippets.

@chrisns
Last active January 24, 2022 12:48
Show Gist options
  • Save chrisns/74ac58aa38ee3b3d5d5600cc1f52ba6b to your computer and use it in GitHub Desktop.
Save chrisns/74ac58aa38ee3b3d5d5600cc1f52ba6b to your computer and use it in GitHub Desktop.
google meet jabra button mapping
// ==UserScript==
// @name Jabra google meet mute button
// @namespace http://tampermonkey.net/
// @version 0.6
// @description google meet jabra mute button
// @author Chris Nesbitt-Smith
// @match https://meet.google.com/*
// @require https://code.jquery.com/jquery-3.6.0.slim.min.js
// @require https://cdn.jsdelivr.net/npm/@gnaudio/[email protected]/browser-umd/index.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js
// ==/UserScript==
(async function() {
$('<link>')
.appendTo('head')
.attr({
type: 'text/css',
rel: 'stylesheet',
href: 'https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css'
});
const config = {
transport: jabra.RequestedBrowserTransport.WEB_HID,
partnerKey: '8712-7a1aa32f-44df-4806-a077-40eb2e065f43',
appId: 'chromemeetme',
appName: 'Google Meet jabra integration'
};
const api = await jabra.init(config);
const callControlFactory = new jabra.CallControlFactory(api);
let deviceFound = false
async function deviceHandle(device, deviceCallControl) {
console.log(`Handling device ${device.name} ${device.serialNumber}`)
console.log(device)
// debugger;
const gotLock = await deviceCallControl.takeCallLock();
if (gotLock)
console.log("Got the lock")
else {
alert("Unable to get the lock, maybe you've got another window open? Close that and reload this one")
return
}
// bind to put the device back on the hook after the call
$(window).bind("beforeunload", () => deviceCallControl.offHook(false))
deviceCallControl.offHook(true)
setInterval(() => {
if(jQuery('button[data-is-muted="false"][aria-label*="micro"]').length === 0) {
jQuery("body>div").first().css("border", "25px solid red").css("box-sizing", "border-box")
deviceCallControl.mute(true)
} else {
jQuery("body>div").first().css("border", "").css("box-sizing", "")
deviceCallControl.mute(false)
}
}, 100)
// let muteState = false
// deviceCallControl.muteState.subscribe(newMuteState => muteState = newMuteState)
deviceCallControl.deviceSignals.subscribe(
(signal) => {
console.log("received", jabra.SignalType[signal.type], signal)
if(jabra.SignalType[signal.type] === "HOOK_SWITCH")
jQuery('button[aria-label^="Leave call"]').click()
if(jabra.SignalType[signal.type] === "FLASH")
jQuery("[role=button]:contains('Join now'),button:contains('Rejoin')").click()
if(jabra.SignalType[signal.type] === "PHONE_MUTE")
document.querySelector('button[aria-label*="microphone"]').click() }
// document.querySelector(`button[data-is-muted="${muteState}"][aria-label*="microphone"]`).click() }
);
}
api.deviceAdded.subscribe(async (device) => {
if (!callControlFactory.supportsCallControl(device))
return
deviceFound = true;
const deviceCallControl = await callControlFactory.createCallControl(device)
deviceHandle(device, deviceCallControl)
});
setTimeout(() => {
if (!deviceFound) {
$.confirm({
title: 'Get HID pairing',
content: 'Not paired with any devices, would you like to?',
buttons: {
confirm: window.jabra.webHidPairing,
no: () => {}
}
})
}
}, 2000)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment