jonashartmann/webcam-directive — pull request #2 by bmatsuo (2013-12-02 04:09:30+00:00)
Title: directive stops the video stream when its $scope is '$destroy'ed

I noticed an issue when the webcam directive is used in an app with multiple views. After switching views the webcam is still on (a green 'recording' light next to the webcam and an indicator in the browser).

The solution to this appears to be to call `stop()` on the video stream when the view is unloaded. I did this by hooking into the webcam $scope's $destroy event, which seemed the most appropriate place to put this logic. (Bug: Chrome on the desktop still displays an indicator in the omnibar, but the webcam recording indicator does turn off. I consider the indicator not going away to be Chrome's problem).

This seems like the kind of thing that could be testable. But it seems like there is a lot of mocking to do for that to be possible (having now looked at the tests I see they are not very thorough :frowning:). Instead I have put together two branches based off `gh-pages`.

- The problem can be seen on [this branch](https://github.com/bmatsuo/webcam-directive/tree/gh-pages-demos/scope-destroy/problem) (using the master webcam-directive js)
- The fix from this branch can be seen on [this branch](https://github.com/bmatsuo/webcam-directive/tree/gh-pages-demos/scope-destroy/fixed)

**Note**: you do have to be careful about `git submodule update` when you flip between those branches