There were two solutions, and I found the 2nd and the best by doing some time in the API documentation .
First decision: work with subscription and publication
Anywhere on the controller side / front-end you must subscribe to the collection
# in coffee @subscribe('allTargets')
After that, you just need to publish and add the onStop listener. In this example, the Targets collection that I already defined somewhere earlier just gets all the records.
# in coffee Meteor.publish 'allTargets', -> @onStop ->
You must be careful not to return Targets.find() before you set the onStop . I do not think this is the ideal solution, since you are not listening to the connection itself, but to the collection changes.
Second solution: working with a DDP connection
I understood through the Meteor API Documentation we can directly listen to the connection and see if someone is disconnecting from the server side.
To stay well organized and clean as part of the Meteor Iron project, I added a new file to app/server/connection.coffee and wrote this code
# in coffee Meteor.onConnection (connection) -> connection.onClose ->
You can manage data using connection.id , which is the unique identifier for your browser tab. Both solutions work well for me.
If you use Meteor.userId through your account system, you cannot use it outside the method on the server side, so I had to find a workaround with connection.id .
If someone has the best solution for managing connections when receiving this kind of client data, feel free to give your data.