Last active
March 23, 2018 18:50
-
-
Save ztl8702/d3b586697b91836e190983b46cc768bf to your computer and use it in GitHub Desktop.
Greasemonkey script: Record Local Audio in Jitsi Meet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Record local audio in Jitsi Meet | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://meet.jit.si/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
var myAudioStream = null; | |
var mediaRecorder = null; | |
navigator.getUserMedia( | |
// constraints - only audio needed for this app | |
{ | |
audioBitsPerSecond: 256000, //256 kbps | |
audio: true, | |
mimeType: 'audio/wav' // is it really wav? need to figure out | |
}, | |
// Success callback | |
(stream) => { | |
myAudioStream = stream; | |
mediaRecorder = new MediaRecorder(stream); | |
mediaRecorder.ondataavailable = e => { | |
console.log("data available"); | |
var audioURL = window.URL.createObjectURL(e.data); | |
console.log("Audio URL:", audioURL); | |
// auto save audio | |
var a = document.createElement("a"); | |
document.body.appendChild(a); | |
a.style = "display: none"; | |
a.href = audioURL; | |
a.download = "recording.wav"; | |
a.click(); | |
}; | |
}, | |
// Error callback | |
(err) => { | |
console.log('The following gUM error occurred: ' + err); | |
} | |
); | |
// set up UI | |
var toggleButton = document.createElement("div"); | |
toggleButton.innerText = "Record"; | |
toggleButton.style = "background: gray; width: 100px; height: 50; position: absolute; top: 10px; right: 10px; z-index: 10000;"; | |
var state = 'idle'; | |
toggleButton.onclick = (e) => { | |
switch (state) { | |
case 'idle': | |
toggleButton.innerText = 'Stop'; | |
toggleButton.style.backgroundColor = 'red'; | |
mediaRecorder.start(); | |
state = 'recording'; | |
break; | |
case 'recording': | |
toggleButton.innerText = 'Record'; | |
toggleButton.style.backgroundColor = 'gray'; | |
mediaRecorder.stop(); | |
state = 'idle'; | |
break; | |
default: | |
break; | |
} | |
}; | |
document.body.appendChild(toggleButton); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment