node-camera icon indicating copy to clipboard operation
node-camera copied to clipboard

Camera state IsOpen always true

Open pjnovas opened this issue 10 years ago • 1 comments

Hey there!, thanks for this awesome code, I'm trying it out and what is happening to me is:

IsOpen() == false

  1. Open(); - IsOpen() == true
  2. Close(); - IsOpen() == false
  3. Open(); - IsOpen() == true
  4. Close(); - IsOpen() == true

And from then I that state won't change, it will be always true. Any ideas what could be?

Thanks in advance!

pjnovas avatar Nov 23 '15 21:11 pjnovas

The scenario you have listed shouldn't happen if only one client connects and then disconnects. IsOpen just returns m_brk flag, which if is false; the running capture loop must be terminated, which is enabled here and disabled here.

Opening and closing of capture is controlled by connectClient and disconnectClient, and to support broadcasting ( more like one-to-many multicasting ) a few checks are made.

  1. Only open device/stream capture if one/more clients are connected otherwise close it.
  2. When new client connects through websocket, open the capture if its not already, and then add client to clients index.
  3. When client websocket disconnects, remove it from clients index and close capture if index is empty.

So if multiple clients are connected, and one of them disconnects, it will still return true for IsOpen.

Hope this helps, tell me if I'm missing something.

kiriapurv avatar Nov 24 '15 04:11 kiriapurv