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

Tracking on created streams #73

Merged
merged 2 commits into from
Nov 7, 2021
Merged

Conversation

lazoapostolovski
Copy link

@lazoapostolovski lazoapostolovski commented Oct 28, 2021

Fix for zxing-js/ngx-scanner#425

  • Fetching camera stream is moved in common method who will also track all opened stream.
  • All created streams can be released at once when needed.
  • One unised report is removed.

…all opened stream. All streams created by this object can be released ar once when wanted.
* @param constraints constraints the media stream constraints to get s valid media stream to decode from.
* @private For private use.
*/
private async getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach. However, I have 2 scenarios to discuss.
Scenario #1.
Let's imagine a situation when I call to getUserMedia with one set of constraints. It's a first call, so the streamTracker cache is empty and I receive the correct results directly from the navigator.mediaDevices. Then after some time I make another call to getUserMedia with a different set of constraints. In this case my new constraints are ignored and getUserMedia will return cached results that are not valid for the new constraints. Do you agree with that?

Scenario #2.
How to handle situations when user media may change from time to time? For example, when a USB web camera is being connected or disconnected from PC? As far as I understand, currently all media results are cached and cache update is not available?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are completely right, i didn't take this scenario in my mind because i only had one device. I will provide better fix for it. Maybe always returning new stream and closing streams thats are not in use anymore to prevent memory leak. I will have some time this weekend hopefuly i will be able to take a look in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! What you are doing is very welcome and valuable for the community! Perhaps always returning a new stream is a good approach. Maybe you will have better ideas. I don't )) But maybe we need some time to think over about it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main issue is because we have a bunch of promise and await. I didn't want to make big changes in code so this solution was looking the simplest to me without touching everywhere. There is better solution for sure. This is kind of quick fix because is releasing all streams when component get destroyed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like your approach and it looks simple. I'm afraid that this may break existing users who depend on multi camera setups.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream is not cached anymore after creating. It is only tracked so we can close all of them later. It does not differ much from previous functionality.

…acks on all created streams, allowing us to release all of them when needed.
Copy link
Contributor

@rvalitov rvalitov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks good now, thank you so much!

@rvalitov
Copy link
Contributor

rvalitov commented Nov 7, 2021

@werthdavid Can you please approve and merge this PR?

@werthdavid werthdavid merged commit 4a9a020 into zxing-js:master Nov 7, 2021
@rvalitov
Copy link
Contributor

rvalitov commented Nov 7, 2021

@werthdavid thank you so much. Will you publish a new release yourself or should we make a PR to package.json?

@werthdavid
Copy link
Member

PR would be much appreciated, thank you!!

@rvalitov
Copy link
Contributor

@werthdavid Sorry, the PR will not work. Because package.json is in .gitignore. It seems you need to run npm pack yourself and make a release appropriately. Or do you think we should allow contributors to edit the package.json and commit it?

P.S. I reviewed the following PRs that can also be merged:

Also added a couple PRs of mine:

Please, have a look when you have time for that. Thank you!

sweetenr added a commit to sweetenr/browser that referenced this pull request Nov 14, 2021
@werthdavid
Copy link
Member

Can you check if v0.0.10 works as expected? Thanks for all the work!

@rvalitov
Copy link
Contributor

Thank you so much! I started to test. I will inform about the results.

@rvalitov
Copy link
Contributor

@werthdavid I made the tests. I could successfully run the zxing-js/ngx-scanner with browser v.0.0.10 and Angular 12.2.3.:
image
However, I had to fix a few things, see the PR zxing-js/ngx-scanner#447

Also, I found out, that latest version of https://github.com/zxing-js/library is v0.19.0, however it has not been published at npm. Is there any reason for that? So, I made the tests with v0.18.0. If you publish v.0.19.0, then I can test it, too.

I also linked the locally built ngx-scanner to my own project, instead of the npm package that I used previously. It also works without any issues.

I believe you may merge the PR above, and then publish a new ngx-scanner version to npm. Thank you!

@werthdavid
Copy link
Member

  • PR is merged, again thank you very much
  • looked into v0.19.0, I thought the github action would publish it but there seem to be some problems with failed unit-tests
  • I'll make a new release for ngx-scanner

@rvalitov
Copy link
Contributor

Thank you so much! The ngx-scanner version 3.3.0 from npm works like a charm!

@werthdavid
Copy link
Member

Good stuff!

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

Successfully merging this pull request may close these issues.

3 participants