To add microphone recording to the existing screen recording functionality without breaking it, you'll need to make a few changes to the code. Here's a step-by-step guide on how to achieve this:
1. Update manifest.json to request microphone permission:
Add "audioCapture" to the permissions array in manifest.json:
2. Update content.js to handle microphone recording:
First, create a new variable to store the microphone stream:
javascript
var microphoneStream;
Next, update the recordTab function to request microphone access and create a new MediaStream that combines both the screen and microphone streams:
javascript
async function recordTab(streamId, tabId) {
// ... (rest of the code remains the same)
// Request microphone access
navigator.mediaDevices.getUserMedia({ audio: true })
.then((microphone) => {
microphoneStream = microphone;
// Create a new MediaStream that combines both screen and microphone streams
var combinedStream = new MediaStream();
combinedStream.addTrack(desktop.getVideoTracks()[0]);
combinedStream.addTrack(microphone.getAudioTracks()[0]);
// Update the MediaRecorder to use the combined stream
mediaRecorder = new MediaRecorder(combinedStream, {
mimeType: 'video/webm;codecs=h264',
});
// ... (rest of the code remains the same)
})
.catch((error) => {
console.error('Error accessing microphone:', error);
});
}
3. Update stopRecord function to stop the microphone stream:
Add the following line to stop the microphone stream when recording is stopped:
javascript
function stopRecord(recordedChunks) {
// ... (rest of the code remains the same)
if (microphoneStream) {
microphoneStream.getTracks().forEach((track) => track.stop());
}
}
4. Update mediaRecorder.onstop event handler:
Add the following line to stop the microphone stream when the MediaRecorder is stopped:
javascript
mediaRecorder.onstop = function() {
// ... (rest of the code remains the same)
if (microphoneStream) {
microphoneStream.getTracks().forEach((track) => track.stop());
}
}
With these changes, the extension should now be able to record both the screen and microphone audio simultaneously. Please note that you may need to adjust the MediaRecorder settings (e.g., mimeType) to accommodate the combined stream.
As for recording Teams meetings, you may need to ensure that the extension is configured to record the correct audio source (e.g., the Teams meeting audio). You can do this by updating the getUserMedia call to specify the audio constraint:
This will allow the extension to access the audio from the Teams meeting. However, please note that this may require additional permissions or configuration, depending on your specific use case.