Some considerations:
- Any JS
xxxxx.yyyyyClosed()
method is equivalent to the corresponding C++~Xxxxx()
destructor. They both silently destroy things without generating any internal notifications/events.- NOTE: Yes, the JS
xxxxx.yyyyyClosed()
produces public JS eventxxxxx.on('yyyyyclose')
, but that's not internal stuff.
- NOTE: Yes, the JS
- Public API.
- Kills the mediasoup-worker process (if not already died) via signal.
- Iterates all JS Routers and calls
router.workerClosed()
.
- The JS Worker emits public JS
worker.on('died')
. - Iterates all JS Routers and calls
router.workerClosed()
.
- Called when the mediasoup-worker process is killed.
- Iterates all C++ Routers and calls
delete router
.
- Private API.
- Emits public JS
router.on('workerclose')
.
- Public API.
- Sends channel request
ROUTER_CLOSE
:- Processed by the C++ Worker.
- It removes the C++ Router from its map.
- It calls C++
delete router
.
- Iterates all JS Transports and calls
transport.routerClosed()
. - Emits private JS
router.on('@close')
(so the JS Worker cleans its map).
- Iterates all C++ Transports and calls
delete transport
.
- Private API.
- Iterates all JS Producers and calls
producer.transportClosed()
. - Iterates all JS Consumers and calls
consumer.transportClosed()
. - Emits public JS
transport.on('routerclose')
.
- Public API.
- Sends channel request
TRANSPORT_CLOSE
.- Processed by the C++ Router.
- It calls C++
transport->Close()
(so the C++ Transport will notify the C++ Router about closed Producers and Consumers in that Transport). - It removes the C++ Transport from its map.
- It calls C++
delete transport
.
- Iterates all JS Producers and calls
producer.transportClosed()
. - For each JS Producer, the JS Transport emits private JS
transport.on('@producerclose')
(so the JS Router cleans its maps). - Iterates all JS Consumers and calls
consumer.transportClosed()
. - Emits private JS
transport.on('@close')
(so the JS Router cleans its map).
- Iterates all C++ Producers and calls
delete producer
. - Iterates all C++ Consumer and calls
delete consumer
.
- Iterates all C++ Producers. For each Producer:
- Removes it from its map of Producers.
- Calls its
listener->OnTransportProducerClosed(this, producer)
(so the C++ Router cleans its maps and callsconsumer->ProducerClosed()
on its associated Consumers). - Calls
delete producer
.
- It clears its map of C++ Producers.
- Iterates all C++ Consumer. For each Consumer:
- Removes it from its map of Consumers.
- Call its
listener->OnTransportConsumerClosed(this, consumer)
(so the C++ Router cleans its maps). - Calls
delete consumer
.
- It clears its map of C++ Consumers.
NOTE: If a Transport holds a Producer and a Consumer associated to that Producer, ugly things may happen when calling Transport::Close()
:
- While iterating the C++ Producers as above, the C++ Consumer would be deleted (via
Consumer::ProducerClosed()
).- As far as it's properly removed from the
Transport::mapConsumers
everything would be ok when later iterating the map of Consumers.
- As far as it's properly removed from the
- Must ensure that, in this scenario, the JS event
consumer.on('producerclose')
is not called sinceconsumer.on('transportclose')
is supposed to happen before.- This won't happen since the JS
Consumer
has removed its channel notifications within itstransportClosed()
method.
- This won't happen since the JS
- Gets the set of C++ Consumers associated to the closed Producer in its
mapProducerConsumers
. For each Consumer:- Calls
consumer->ProducerClosed()
.
- Calls
- Deletes the entry in
mapProducerConsumers
with keyproducer
. - Deletes the entry in
mapProducers
with keyproducer->id
.
- Get the associated C++ Producer from
mapConsumerProducer
. - Remove the closed C++ Consumer from the set of Consumers in the corresponding
mapProducerConsumers
entry for the given Producer. - Deletes the entry in
mapConsumerProducer
with keyconsumer
.
- Private API.
- Emits public JS
producer.on('transportclose')
.
- Public API.
- Sends channel request
PRODUCER_CLOSE
.- Processed by the C++ Transport.
- Removes it from its map of Producers.
- Calls its
listener->OnTransportProducerClosed(this, producer)
(so the C++ Router cleans its maps and callsconsumer->ProducerClose()
on its associated Consumers). - Calls
delete producer
.
- Emits private JS
producer.on('@close')
(so the JS Transport cleans its map and will also emit private JStransport.on('@producerclose')
so the JS Router cleans its map).
- Destroys its stuff.
- Private API.
- Emits public JS
consumer.on('transportclose')
.
- Public API.
- Sends channel request
CONSUMER_CLOSE
.- Processed by the C++ Transport.
- Removes it from its map of Consumers.
- Calls its
listener->OnTransportConsumerClosed(this, consumer)
(so the C++ Router cleans its maps). - Calls
delete consumer
.
- Emits private JS
consumer.on('@close')
(so the JS Transport cleans its map).
- Destroys its stuff.
- Called from the C++ Router within the
Router::OnTransportProducerClosed()
listener. - Send a channel notification
producerclose
to the JS Consumer.- The JS Consumer emits private JS
consumer.on('@produceclose')
(so the JS Transport cleans its map). - The JS Consumer emits public JS
consumer.on('produceclose')
.
- The JS Consumer emits private JS
- Notifies its C++ Transport via
listener->onConsumerProducerClosed()
which:- cleans its map of Consumers,
- notifies the Router via
listener->OnTransportConsumerClosed()
), and - deletes the Consumer.