# Detect when flow editor is closed

**URL:** https://discourse.nodered.org/t/detect-when-flow-editor-is-closed/18357
**Category:** Developing Nodes
**Created:** [24 November 2019 16:15 UTC](https://discourse.nodered.org/t/detect-when-flow-editor-is-closed/18357 "2019-11-24T16:15:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 November 2019 16:15 UTC](https://discourse.nodered.org/t/detect-when-flow-editor-is-closed/18357/1 "2019-11-24T16:15:03Z")

</div>

Hi folks,

Is there any way (on the server side) to detect when a flow editor has client been closed?

For my new node-red-contrib-xterm node, a separate pseudo-terminal is started (on the server) for each flow editor that is started. I can easily trigger that from the client startup code. But as soon as a flow editor is closed, I need to stop the corresponding pseudo-terminal on the server.

But I cannot find a server-side event to accomplish this. Only found a client-side code snippet, and it doesn't work for me (e.g. when I close the tabsheet in Chrome where my flow is being displayed):  
`RED.events.on("editor:close",function() { .... })`

P.S. A side question: does anybody know whether there is (somewhere) a unique workspace id available, which I could use to unique identify the flow editors (to use as a key in the map where I store my pseudo-terminal instances)?

Thanks a lot!!  
Bart

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [24 November 2019 20:21 UTC](https://discourse.nodered.org/t/detect-when-flow-editor-is-closed/18357/2 "2019-11-24T20:21:14Z")

</div>

No, none of the features you are asking about are available.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 November 2019 20:44 UTC](https://discourse.nodered.org/t/detect-when-flow-editor-is-closed/18357/3 "2019-11-24T20:44:29Z")

</div>

Ah that is a pitty. Had hoped that the Node-RED core also had to do some cleanup somewhere if a client disconnects from the server. And that I could listen somehow to those events to do my stuff ...

So then I have to look for a workaround:

- Had first thought to kill my pseudoterminal process automatically (when the user has no new command entered in the last x seconds) and spawn a new process when a new command is entered. However suppose a command is executed to **tail** a file, then I cannot simply interrupt that process just because the user is not entering new commands in the terminal.
- So I assume my only option is that my client side should send a **heartbeat** (every x seconds) to keep the pseudo-terminal available.

If anybody has a better workaround or something that I should be aware of, please let me know!
