publiclab / infragram

A minimal core of the Infragram.org project in JavaScript
https://infragram.org/sandbox/
GNU General Public License v2.0
44 stars 166 forks source link

Image files are unable to load after camera stream. #441

Open Forchapeatl opened 2 years ago

Forchapeatl commented 2 years ago

Image files are unable to load after camera stream.

@jywarren , please i can't seem to diagnose the source of this unexpected behavior. Could you help me please?

https://user-images.githubusercontent.com/24577149/181921156-3801abe2-c445-4903-855a-f1611257ceef.mp4

_Originally posted by @Forchapeatl in https://github.com/publiclab/infragram/pull/439#discussion_r933833059_

jywarren commented 2 years ago

OK, so i think when we start video mode, we begin a loop to fetch images from the video element. When we try to go back to upload mode, we need to find and halt that loop. Let me look...

Yes, we do it in this function:

https://github.com/publiclab/infragram/blob/f15add6ae6057bd99b4b1b930449f75ca974270e/src/Infragram.js#L34-L45

And that function is called from here:

https://github.com/publiclab/infragram/blob/577ff122edd6918891a84ea9d9df221585fdc901/src/ui/interface.js#L89-L97

So we have to save the setInterval object and stop it with clearInterval(). Intervals are a little weird but they are just repeated timers. You can read how they work here! https://developer.mozilla.org/en-US/docs/Web/API/setInterval#return_value There are good examples lower on that page that you can model to use here. But, I think we could also solve this in a separate PR - i don't think it's your code that's causing it, it's already the case in the main branch!

And, solving it may be a little more complex, we have to think carefully about where we store the interval return value so that we can make a stopVideo() function, probably? I can help you figure that out too but we might as well move this whole comment thread to its own issue, what do you think?

ojninja16 commented 2 years ago

HI @Forchapeatl I would like to try ...if no one else is