How to disable the video stream and make available the camera?

Good afternoon. There is a task in the app which broadcasts a stream with getUserMedia, to make a button that will stop the flow and make the camera available to other applications. In the myStream object returned by the function if successful, I found the stop () method, but it doesn't work. Please tell me the solution.

angular.module("App", [])
 .controller("defaultCtrl", function ($scope, $timeout) {
 navigator.getUserMedia = function (constraints, cb, errcb) {
navigator.mediaDevices.getUserMedia(constraints)
 .then(cb, errcb);
}.bind(navigator);
navigator.getUserMedia({
 video: true
 audio: true
 }, angular.bind(this, function (myStream) {
 const stream = document.querySelector('#localVideo');
 $scope.streamVideo = myStream.getTracks()[0]
 stream.srcObject = myStream;
 }), angular.bind(this, function (error) {
console.error(error);
}));
})
 .directive('ngStop', function(){
 return function(scope, element, attrs){
 const stream = document.querySelector('#localVideo');
 const button = document.getElementById('btn')
 button.addEventListener('click', function(){
scope.streamVideo.stop();
})
}
 })
March 23rd 20 at 19:21
1 answer
March 23rd 20 at 19:23
Solution
https://stackoverflow.com/questions/11642926/stop-...
stream.getTracks().forEach(track => track.stop())

Find more questions by tags HTMLAngularJavaScript