Comments (21)
We are also running into this issue. Can we please reopen this and investigate? How can I help?
from ngx-webcam.
Hi, so i was struggling throughout the day to make the webcam stop record after an ngIf="false" was triggered somewhere over the component and i got this solution:
- keep the reference of the track after the output "cameraSwitched" emits the event;
public cameraWasSwitched(deviceId: string): void {
this.deviceId = deviceId;
let constraints = {
deviceId: deviceId,
width: this.videoOptions.width,
height: this.videoOptions.height
};
navigator.mediaDevices.getUserMedia({ video: constraints }).then(stream => {
this.onTransmission.emit(stream);
this.tracks = stream.getVideoTracks();
})}
- add a method that stop said tracks on the ngOnDestroy hook
this.showWebcam = false;
this.tracks.forEach(track => {
track.stop();
})
im using the "showWebcam " as inner flag of a component that uses the ngx-webcam, its for hide/show element purposes. Anyway this might seem kinda obvious but it took me five good hours of my time, so i hope someone else can benefit from it.
from ngx-webcam.
Hi @u77171,
there's no explicit way to turn off the camera through the component. But you can always remove the component from your page after you're done. Would that work for you?
Cheers
from ngx-webcam.
Same issue. Can you add a button that will call something like this?
stream.getTracks().forEach(track => track.stop())
^Scratch all that. I guess the problem is that some users still see the camera after the widget has been destroyed. Trying to find out which browsers, etc.
from ngx-webcam.
Hi @queejie,
Could you elaborate what issue you‘re experiencing? The camera and all active tracks are shut down and closed once the element is removed from the page (i.e. render it with an ng-if).
Let me know if that helps.
Thanks!
from ngx-webcam.
Closing since no response from requestor.
from ngx-webcam.
I am seeing this same thing. Users are reporting that after they leave the route that has the webcam component, their camera is still recording, indicated by the little red flashing icon on the tab in chrome.
The view that uses the camera is super simple:
`import { Component, OnInit, HostListener, ViewChild, ElementRef } from '@angular/core';
import { MsalService } from '@azure/msal-angular';
import { Router } from '@angular/router';
@component({
selector: 'app-webcam-check',
templateUrl: './webcam-check.component.html',
styleUrls: ['./webcam-check.component.scss']
})
export class WebcamCheckComponent implements OnInit {
@ViewChild('webcam-checker-container') webcamContainer: ElementRef;
public profileName: string;
width: number;
height: number;
constructor(
private authService: MsalService,
private router: Router) {
this.onResize();
}
ngOnInit() {
this.profileName = this.authService.getUser().name;
}
onSubmit = (): void => {
this.router.navigateByUrl('/call-queue');
}
@HostListener('window:resize', ['$event'])
onResize(event?: Event) {
const win = !!event ? (event.target as Window) : window;
if (this.webcamContainer && this.webcamContainer.nativeElement) {
this.width = (this.webcamContainer.nativeElement as HTMLElement).offsetWidth;
this.height = (this.webcamContainer.nativeElement as HTMLElement).offsetHeight;
} else {
this.width = win.innerWidth;
this.height = win.innerHeight;
}
}
}`
from ngx-webcam.
Hey @sstriano,
Do you have a minimal demo that shows this behaviour? I‘m having troubles reproducing. The camera should turn itself off after the component is destroyed (shutdown code is present in the component‘s onDestroy() method).
A minimal reproducible example would be great.
Do you know if the behaviour is specific to a browser? Does it only affect some of your users? Are they all using the same app?
Thanks for your help in finding the issue.
from ngx-webcam.
@basst314 I'am facing the same issue, i'am using a modal from ngx-bootstrap with ngx-webcam.
When user user close the modal, it is destroyed, but webcam still recording and chrome continues showing the red icon on tab. I'll investigate more, to try to get whats is going wrong.
It seems that the behavior occurrs on some specific condition, i can't reproduce it anymore.
from ngx-webcam.
Same here
from ngx-webcam.
Hi @bobbydowling can you provide more details about what you‘re experiencing and how you integrate with the webcam component?
Do you have a minimal demo that showcases the experience?
Does it happen in all browsers or only a specific one? Are all users affected? Does it happen always?
Have you tried adding an ng-if to the webcam component and set it to false if you want the webcam to disappear?
A modal could just get hidden if closed but maybe it‘s not destroyed completely.
Thanks
from ngx-webcam.
I created an "ImageUpload" component that I load with the Material Dialog component.
In that component, I merely copied the code from your demo, so it is already using ng-if on your component.
When the Dialog is closed and also on Destroy, which happens when the dialog is closed, I set ng-if to falsey. I also unsubscribe from the Trigger subject, just in case.
This happens using the Safari browser on an iPhone.
Within the loaded component, when the webcam is visible, I get a red camera in the title bar.
When the Dialog is closed and the component is destroyed (assuming), I get a red camera with a diagonal line down the middle, indicating the camera is still loaded, but the webcam is not visible.
My concern is that this will eat the battery. Only option is for the user to reload the app.
Happens always with all users.
from ngx-webcam.
It's this:
There appears to be nothing I can do to manually kill the inner Component.
I would need a way to manually kill your component... and ngif is not working.
from ngx-webcam.
I provided more info... what do you think?
from ngx-webcam.
Hi @bobbydowling,
it seems like Safari still indicates if the active page has permissions or was using WebRTC, even if the camera is no longer active.
I found that the experience is the same when testing this official WebRTC demo on iPhone+Safari.
https://webrtc.github.io/samples/src/content/getusermedia/resolution/
First try selecting a resolution that the iPhone camera can support (e.g. HD), then select something too high, e.g. 8K. The camera stream closes, however the red camera icon with diagonal line is still shown in the Safari browser bar. Other browsers like Chrome on Desktop will also indicate permissions have been granted even if the camera is no longer active (red circle on tab title when active, greyed out camera symbol in browser bar when not active but permissions granted).
This seems to align with the official WebRTC/UserMedia API documentation around privacy requirements that states:
Browsers are required to display an indicator that shows that a camera or microphone is in use, above and beyond any hardware indicator that may exist. They must also show an indicator that permission has been granted to use a device for input, even if the device is not actively recording at the moment.
Seems like this is what the camera symbol with diagonal line indicates.
Hope this helps to clarify things.
from ngx-webcam.
@basst314 here's an example that reproduces the problem
https://stackblitz.com/edit/ngx-webcam-non-turned-off-camera-demo?file=src/app/app.component.ts
Steps to reproduce: see on the below animation
Most likely you will have to repeat actions several times to reporoduce it
ngx-webcam: 0.3.2
browser: Google Chrome 89
from ngx-webcam.
@basst314 I think there's a sense to reopen this issue because there's a reproducable example above
from ngx-webcam.
I have the exact same problem of the example above! I've tried to apply the ngIf on wrapper div of the camera component, but the camera keeps open after the ngIf goes false and the dialog is closed.
from ngx-webcam.
Hi, so i was struggling throughout the day to make the webcam stop record after an ngIf="false" was triggered somewhere over the component and i got this solution:
- keep the reference of the track after the output "cameraSwitched" emits the event;
public cameraWasSwitched(deviceId: string): void { this.deviceId = deviceId; let constraints = { deviceId: deviceId, width: this.videoOptions.width, height: this.videoOptions.height }; navigator.mediaDevices.getUserMedia({ video: constraints }).then(stream => { this.onTransmission.emit(stream); this.tracks = stream.getVideoTracks(); })}
- add a method that stop said tracks on the ngOnDestroy hook
this.showWebcam = false;
this.tracks.forEach(track => {
track.stop();
})im using the "showWebcam " as inner flag of a component that uses the ngx-webcam, its for hide/show element purposes. Anyway this might seem kinda obvious but it took me five good hours of my time, so i hope someone else can benefit from it.
Thanks! It helped me a lot!
My camera component is inside a modal, so I prevented the user to close the modal before the camera finish initializing or throwing an error. I emitted an event when the tracks are added (or an error had happened), to enable the modal to be closed. For me it worked!
I wrote it like this:
this.tracks = stream.getVideoTracks();
this.enableDialogClose.emit();
And the handleInitError would look like:
handleInitError(error: WebcamInitError): void {
//some error handlings
this.enableDialogClose.emit();
}
I've been working with Angular for a few weeks now, so I'm not fully familiarized with the language, but that was the solution I was able to do.
from ngx-webcam.
What worked in my case is to apply fix to the webcam component itself (muhammad-usman-anwar@20c6dc6) and in addition to this close the subject by calling:
this.nextWebcam.complete();
(I triggered it when closing modal window using this webcam).
Looks like it is a missing part of releasing resources when using webcam.
from ngx-webcam.
I encountered the same problem, has anyone found a solution?
from ngx-webcam.
Related Issues (20)
- Is this project maintained or dead? HOT 2
- Not all code paths return a value HOT 2
- After unsubscribe, seems camera is still active HOT 3
- Portrait mode HOT 2
- Camera view finder does not show up in ios HOT 1
- Can't set default camera to rear camera HOT 1
- It's possible to zoom in this plugin?
- No source names in Firefox
- Is it possible to ignore wide angle camaras? HOT 1
- Video Record Not available!
- Camera does not stop even after component is destroyed HOT 2
- Error while try to flip between camera on android device on Firefox browser HOT 1
- Angular 16 support
- Green screen HOT 1
- Angular Not Recognizing Webcam Element
- Uncaught (in promise) DOMException: The play() request was interrupted by a new load request
- Full width and height camera HOT 2
- Angular 14.2.8: Cannot find module '@angular/core' or its corresponding type declarations HOT 1
- Camera switch issues and black screen
- Camera Not Working on Samsung Phone HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-webcam.