Webcam and microphone handling thru Javascript

Hi friends,
I’m trying to access webcam and mic thru getUserMedia function. But I’m not able to pause and resume it. After stopping recorder, it still shows webcam on and mic status on. I’ve tried to pause the stream using stream.getTrack.stop(). Also Tried pausing the stream using for each loop, still no success. Kindly guide. Thanks in advance.
Good day