I’m trying to publish (produce) two media tracks in a single request. This is useful when you need to handle audio and video tracks of a stream in the consumer side at the same time. However this is hard with current API that uses callback for producing. Consider the following sample code:
const audioProducer = await transport.produce({ track: audioTrack });
const videoProducer = await transport.produce({ track: videoTrack });
transport.on('produce', (data, callback) => {
// no way to handle producers at the same time
const id = await sendRequestToServer(data);
callback({ id });
});
But I wish I had some thing like this instead (Promise approach):
What’s the problem? You can wait for both “produce” events and send a single request to the server. This is just cosmetic and we won’t change the API just for that.
We won’t create a new API for this. It’s just cosmetic and you can get the desired behaviour in your app code. Anyway nothing wrong happens for sending two requests to your server instead of one. And still you can wait and collect both “produce” events and send a single request to your server with both (yes, it would require some JS magic).
I said I need to handle them together in the consumer side, so I have to produce them at the same time in the server, so have to send in one request or I have to handle the two requests in the server.
I personally prefer Promise over Callback as much as possible which leads to easier code structure and logic.
Never mind I’ll find a way for that, just a sympathy. Thank you.