Hey @Andreas Møller
yep, the custom-action path worked quiet well, seems like a good design decision to run arbitrary code while expanding features.
For anyone that think its useful, here is a very prototype but working custom action.
/**
* @param {Args} args
* @param {Ctx} ctx
*/
function captureAudio (args, ctx) {
console.log('Initializing Audio ... ')
let mediaRecorder;
let audioChunks = [];
let audioBlob;
const stopButton = ctx.root.getElementById('stopbutton');
const audioplayer = ctx.root.getElementById('audioplayer');
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();
console.log('Recording started');
// When data is available, push it to audioChunks
mediaRecorder.ondataavailable = event => {
audioChunks.push(event.data);
};
// Once recording stops, create an audio blob and set it as the source for playback
mediaRecorder.onstop = () => {
console.log("data available after MediaRecorder.stop() called.");
audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
console.log(audioBlob)
const audioUrl = URL.createObjectURL(audioBlob);
console.log(audioUrl)
audioplayer.src = audioUrl
ctx.triggerActionEvent('onRecordingFinished',null)
};
stopButton.onclick = () => {
console.log('stop recording')
mediaRecorder.stop();
};
})
.catch(error => {
console.error('Microphone access denied or error: ', error);
});
}
Oh and @Andreas Møller congrats on the funding - awesome job, all the best with scaling the platform, enjoy lots of the design principles you put it.