Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - pauseHard Camera #24

Closed
monsdroid opened this issue Mar 14, 2018 · 5 comments
Closed

Feature Request - pauseHard Camera #24

monsdroid opened this issue Mar 14, 2018 · 5 comments

Comments

@monsdroid
Copy link

monsdroid commented Mar 14, 2018

Hi,
first of all: Works like a Charm and a very nice piece of Code!

Im using this in Browsers on mobile devices and as long as the component is mounted Chrome displays a Notification that there is an 'Access to Video Camera from domain'. Even if the Browser is in background or switched to an different Tab.

Would it be possible for your to expose a pauseHard() function which disconnects the Camera but keeps the last image in the canvas?

Calling stopCamera() works but kills the canvas or blacks it out

@gruhn
Copy link
Owner

gruhn commented Mar 15, 2018

Thanks 😀

Could you split this issue so we can handle your suggestions separately. Just open another issue and rename this one.

@monsdroid monsdroid changed the title Feature Request - pauseHard Camera / uploadImage to decode Feature Request - pauseHard Camera Mar 16, 2018
@gruhn
Copy link
Owner

gruhn commented Mar 16, 2018

You should know: At the moment, there isn't really a canvas element. The camera stream is displayed via a video element. When you pause the component, we simply call pause() on the video. The camera is still streaming in the background and that's why Chrome displays the notification. When you call stopCamera the stream is closed and I guess video elements need the stream to be active to display anything. As a result the last captured frame is lost.

We could continuously paint the streams frames to an actual canvas. This should look exactly like a video element but when the stream is closed the last painted frame will persist. I assume you had something like this in mind too, right?

I'd like to keep this components API as simple as possible, so I always hesitate to expose new events, props and so on. However, I think your suggestion is totally valid. It makes sense to release the camera when it seems to be not in use. I'm thinking about making this the default when pause is set to false. Un-pausing might cause perceivably more delay though, because the stream has to be loaded again.

Those are my thoughts so far. What do you think?

PS: don't forget to open the drag-and-drop related issue. I like that idea too 😉

@monsdroid
Copy link
Author

Maybe handle it transparent for the user of your component. The https://caniuse.com/#feat=pagevisibility API should work on all devices which support camera streams. if (document.visibilityState == "visible") do a soft pause otherwise disconnect the stream.
Another turn down beside the notificaton that a stream is open is that the stream is open :-)
Which means it uses battery. My Phone (Galaxy S7) heats up quite fast with the connected stream running in background

gruhn added a commit that referenced this issue Aug 26, 2018
The `video` element is tightly bound to the camera stream. If the
stream ends the `video` is stopped too. By using the `video` as
a mediator and painting it's frames to a visible canvas, the last
frame of a camera stream can be preserved even when the stream
ends.

Close #24
@gruhn
Copy link
Owner

gruhn commented Aug 26, 2018

I finally started to work on this one too. I think I found a nice solution but performance might have suffered. On desktop it's fine but my old-ass phone has a hard time. If you want, you can checkout the demo page – especially validation (hard) demo – and tell me how it performs on your device.

gruhn added a commit that referenced this issue Sep 2, 2018
Use additional canvas overlaying the camera stream to paint the
last frame before pausing the component. In contrast to calling
`video.pause()` the painted frame also persists when the stream
is killed completely.

Close #24
@gruhn gruhn closed this as completed in 8aa5eab Sep 2, 2018
@gruhn
Copy link
Owner

gruhn commented Sep 2, 2018

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants