Due to its design, the Node.js application is responsible of creating and managing mediasoup objects such as workers, routers, transports, producers and consumers. In summary this means that the application must keep references to those objects, call methods on them, listen for events on them and remove those references when the corresponding object has been closed.
The mediasoup API describes all those actions and events. Here just a summary of them.
A Worker is closed when:
worker.close()
is called, orworker.on("died")
event is fired (emitted when the worker process unexpectedly).A Router is closed when:
router.close()
is called, orrouter.on("workerclose")
event is fired (emitted when the worker this router belongs to is closed for whatever reason).A Transport is closed when:
transport.close()
is called, ortransport.on("routerclose")
event is fired (emitted when the router this transport belongs to is closed for whatever reason).A Producer is closed when:
producer.close()
is called, orproducer.on("transportclose")
event is fired (emitted when the transport this producer belongs to is closed for whatever reason).A Consumer is closed when:
consumer.close()
is called, orconsumer.on("transportclose")
event is fired (emitted when the transport this consumer belongs to is closed for whatever reason), orconsumer.on("producerclose")
event is fired (emitted when the associated producer is closed for whatever reason).A DataProducer is closed when:
dataProducer.close()
is called, ordataProducer.on("transportclose")
event is fired (emitted when the transport this data producer belongs to is closed for whatever reason).A DataConsumer is closed when:
dataConsumer.close()
is called, ordataConsumer.on("transportclose")
event is fired (emitted when the transport this data consumer belongs to is closed for whatever reason), orconsumer.on("dataproducerclose")
event is fired (emitted when the associated data producer is closed for whatever reason).A RtpObserver is closed when:
rtpObserver.close()
is called, orrtpObserver.on("routerclose")
event is fired (emitted when the router this RTP observer belongs to is closed for whatever reason).When any of these close()
methods is called or “xxxxxclose” event is emitted, the corresponding mediasoup object becomes “closed” (its closed
property is true
from now on) and the application should clean the reference to that object.