Skip to content

Commit

Permalink
Allow turning off device between recordings (#268)
Browse files Browse the repository at this point in the history
* add autoMuteDevice option
* update dev dependencies
  • Loading branch information
thijstriemstra authored Aug 2, 2018
1 parent cae1e62 commit ff3a618
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ videojs-record changelog
2.4.1 - unreleased
------------------

- `autoMuteDevice` option to turn off the device between recordings
(for privacy reasons) (#157)
- Fix lamejs plugin (#265)


Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ The available options for this plugin are:
| `debug` | boolean | `false` | Enables console log messages during recording for debugging purposes. |
| `maxLength` | float | `10` | Maximum length of the recorded clip. |
| `timeSlice` | float | `0` | Accepts numbers in milliseconds; use this to force intervals-based blobs and receive [timestamps](#timestamps) during recording by listening for the `timestamp` event. |
| `autoMuteDevice` | boolean | `false` | Turns off the camera/mic devices (and light) when audio and/or video recording stops, and turns them on again when recording resumes. |
| `frameWidth` | float | `320` | Width of the recorded video frames. Use [media constraints](#media-constraints) to change the camera resolution width. |
| `frameHeight` | float | `240` | Height of the recorded video frames. Use [media constraints](#media-constraints) to change the camera height. |
| `videoMimeType` | string | `'video/webm'` | The mime type for the video recorder. Use `video/mp4` (Firefox) or `video/webm;codecs=H264` (Chrome 52 and newer) for MP4. A full list of supported mime-types in the Chrome browser is listed [here](https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/fast/mediarecorder/MediaRecorder-isTypeSupported.html). |
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@
"webpack-cli": "^3.1.0",
"webpack-dev-middleware": "^3.1.3",
"webpack-dev-server": "^3.1.5",
"webpack-merge": "^4.1.3"
"webpack-merge": "^4.1.4"
}
}
3 changes: 3 additions & 0 deletions src/js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const pluginDefaultOptions = {
frameHeight: 240,
// Enables console logging for debugging purposes.
debug: false,
// Turn off the camera/mic (and light) when audio and/or video recording
// stops, and turns them on again when you resume recording.
autoMuteDevice: false,
// The mime type for the video recorder. Default to 'video/webm'.
// Use 'video/mp4' (Firefox) or 'video/webm;codecs=H264' (Chrome 52 and
// newer) for MP4.
Expand Down
27 changes: 27 additions & 0 deletions src/js/videojs.record.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Record extends Plugin {
this.maxLength = recordOptions.maxLength;
this.debug = recordOptions.debug;
this.recordTimeSlice = recordOptions.timeSlice;
this.autoMuteDevice = recordOptions.autoMuteDevice;

// video/canvas settings
this.videoFrameWidth = recordOptions.frameWidth;
Expand Down Expand Up @@ -611,6 +612,11 @@ class Record extends Plugin {
break;
}

if (this.autoMuteDevice) {
// unmute device
this.muteTracks(false);
}

// start recording
switch (this.getRecordType()) {
case IMAGE_ONLY:
Expand Down Expand Up @@ -684,6 +690,11 @@ class Record extends Plugin {
if (this.engine) {
this.engine.stop();
}

if (this.autoMuteDevice) {
// mute device
this.muteTracks(true);
}
} else {
if (this.player.recordedData) {
// notify listeners that image data is (already) available
Expand Down Expand Up @@ -1132,6 +1143,22 @@ class Record extends Plugin {
this.devices = [];
}

/**
* Mute LocalMediaStream audio and video tracks.
*/
muteTracks(mute) {
if ((this.getRecordType() === AUDIO_ONLY ||
this.getRecordType() === AUDIO_VIDEO) &&
this.stream.getAudioTracks().length > 0) {
this.stream.getAudioTracks()[0].enabled = !mute;
}

if (this.getRecordType() !== AUDIO_ONLY &&
this.stream.getVideoTracks().length > 0) {
this.stream.getVideoTracks()[0].enabled = !mute;
}
}

/**
* Get recorder type.
*/
Expand Down
1 change: 1 addition & 0 deletions test/defaults.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('pluginDefaultOptions', function() {
frameWidth: 320,
frameHeight: 240,
debug: false,
autoMuteDevice: false,
videoMimeType: 'video/webm',
videoRecorderType: 'auto',
audioEngine: 'recordrtc',
Expand Down

0 comments on commit ff3a618

Please sign in to comment.