I think you are on the right track 
You may need to set the video source to null in addition to calling stop on the track object. Check out the following snippet:
function stop(e) {
var stream = video.srcObject;
var tracks = stream.getTracks();
for (var i = 0; i < tracks.length; i++) {
var track = tracks[i];
track.stop();
}
video.srcObject = null;
}
Here is a working example: https://www.kirupa.com/snippets/examples/stop_webcam_stream.htm
Does this help?
Cheers,
Kirupa