illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.9k stars 1.51k forks source link

How to work asynchronously ? #539

Open eric72 opened 1 year ago

eric72 commented 1 year ago

Hi,

I wanted to know how to work asynchronously with the lib, i tried to use promise in preConnect event, but if i use promise other event like prePublish or prePlay or whatever is executed. How to solve that ?

Thanks for your answer.

gregmsanderson commented 1 year ago

I've just been looking at this too. From what I can see the events fire independently. So if you use a Promise/async/await etc in the main app.js file, that won't stop anything else happening. As those are simply in response to events, to let you know they've happened. I found if you look in the code where the event is fired (e.g look for emit('prePublish'), that's where you can take alternative action. For example to modify how the prePublish authentication is done. That's just after that event is emitted.