I'm testing the video capabilities of HTML5. With a directive userMedia
, I'm able to switch on my camera on my MacBook via navigator.getUserMedia()
(actually via an adapter to make it cross browser - at least those who support it).
But when I change my $route
, I don't see myself anymore (hurray), but the camera does not switch off (the green light stays on). Only refreshing the page resets everything (which is normal).
I was hoping that watching for a change in $location.path()
would do the trick:
link: function(scope, elm, attrs, ctrl) {
...
var path = $location.path();
scope.$watch(function() {
return $location.path();
}, function(value) {
if (value && value !== path) {
$log.info('Location changed, switching off camera');
webRTCAdapter.detachMediaStream(elm[0]);
}
}, true);
}
detachMediaStream (Chrome):
webRTCAdapter.detachMediaStream = function(element) {
console.log("Detaching media stream");
element.pause();
element.src = '';
element.parentNode.removeChild(element);
};
Html:
<video id="localVideo" width="100%" autoplay="autoplay" user-media="user-media"></video>
detachMediaStream
gets executed (I see the necessary logs in console.log
), but the camera does not switch off.
Any idea how to solve this? Should I unload the element somehow?