I added a javascript page that would allow the user to record voice using their microphone.
I want to send the recording to a SignalR hub
Here is the javascript code that does the recording and then when the sendButton
is called, the byte array is send to the signalR hub using the upload
function.
const connection = new signalR.HubConnectionBuilder().withUrl("/hub").build();let audioRecorder;let data = [];navigator.mediaDevices.getUserMedia({ audio: true }) .then(stream => { audioRecorder = new MediaRecorder(stream); audioRecorder.addEventListener('dataavailable', e => { data.push(e.data); }); startButton.addEventListener('click', () => { audioRecorder.start(); }); stopButton.addEventListener('click', () => { audioRecorder.stop(); }); sendButton.addEventListener('click', async () => { const blobObj = new Blob(audioChunks, { type: 'audio/webm' }); var bytes = await blobObj.arrayBuffer(); const subject = new signalR.Subject(); subject.next(bytes) connection.invoke('upload', 'filename', subject); subject.complete(); }); })
The SignalR hub I added this code
public partial class MyHub : Hub<IMyHub>{ public Task Upload(string filename, IAsyncEnumerable<byte[]> content) { return Task.CompletedTask; }}
The Upload
method gets hit as expected, but the Current
property on content
is always null.
How can I upload the recording byte array to the SignalR hub?