I have a function that returns a promise, resolving three values, but these values are constructed, and resolved, in a nested function. In chrome this works and the correct values are resolved, however in Firefox and safari the function returns without resolving the promise. I have put a breakpoint in the callback function, and in chrome it hits every time, but passes over it in Firefox. my suspicion is that chrome is executing the code-block until it reaches the resolve but in Firefox it is returning early.
const getConsumer = (
socket,
consumerTransport,
device,
producerId
) => {
return new Promise((resolve) => {
const message = {
rtpCapabilities,
producerId,
consumerTransportId
};
const callback = async function (consumeData) {
const { id, kind, rtpParameters } = consumeData;
const consumer = await consumerTransport.consume({
id,
producerId,
kind,
rtpParameters,
appData: {}
});
const stream = new MediaStream();
stream.addTrack(consumer.track);
resolve({
consumer,
stream,
kind
});
};
socket.emit('consume', message, callback);
});
I've attempted to re order the function so the promise is inside the callback function but this means I can't call 'then' where the getConsumer function is invoked, I have also tried nesting a second promise in the callback function, but to no avail.