Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destinationPath option to .startRecording() #11

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const fs = require('fs');
const path = require('path');
const delay = require('delay');
const aperture = require('.');

Expand All @@ -8,12 +8,13 @@ async function main() {
console.log('Screens:', await aperture.screens());
console.log('Audio devices:', await aperture.audioDevices());
console.log('Preparing to record for 5 seconds');
await recorder.startRecording();
await recorder.startRecording({
destinationPath: path.join(__dirname, 'test.mp4')
});
console.log('Recording started');
await delay(5000);
const fp = await recorder.stopRecording();
fs.renameSync(fp, 'recording.mp4');
console.log('Video saved in the current directory');
console.log('Video saved in the current directory', fp);
}

main().catch(console.error);
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Aperture {
}

startRecording({
destination = undefined,
fps = 30,
cropArea = undefined,
showCursor = true,
Expand All @@ -46,7 +47,12 @@ class Aperture {
return;
}

this.tmpPath = tempy.file({extension: 'mp4'});
this.tmpPath = destination ? destination : tempy.file({extension: 'mp4'});

if (destination && (typeof destination !== 'string' || !destination.includes('mp4'))) {
reject(new Error('Invalid `destination` option string'));
return;
}

if (highlightClicks === true) {
showCursor = true;
Expand Down
16 changes: 14 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do unrelated changes.

# aperture-node [![Build Status](https://travis-ci.org/wulkano/aperture-node.svg?branch=master)](https://travis-ci.org/wulkano/aperture-node)

> Record the screen on macOS from Node.js
Expand Down Expand Up @@ -32,7 +33,7 @@ const options = {
await aperture.startRecording(options);
await delay(3000);
console.log(await aperture.stopRecording());
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/cdf4f7df426c97880f8c10a1600879f7.mp4'
//=> '/private/var/folders/3x/jf5977fn79j/T/cdf4f7df426c97880f8c10a1600879f7.mp4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do unrelated changes.

})();
```

Expand Down Expand Up @@ -88,14 +89,25 @@ Map {

Returns a `Promise` for the path to the screen recording file.

Fullfills when the recording starts or rejects if the recording didn't start after 5 seconds.
Fulfills when the recording starts or rejects if the recording didn't start after 5 seconds.

#### recorder.stopRecording()

Returns a `Promise` for the path to the screen recording file.

## Options

#### destinationPath

Type: `string`<br>
Default: `undefined`

Destination of the output file. When `undefined`, destination will be generated using [tempy](https://github.com/sindresorhus/tempy) (default).

`destinationPath` can be useful when needing to store temporary data on a different external network or local drive, allowing for higher capacity file storage ([further discussion](https://github.com/wulkano/aperture-node/pull/7#issuecomment-533199701)).

This option should only be used when necessary. If `destinationPath` is not defined, then [tempy](https://github.com/sindresorhus/tempy) is used to generate an available filename and path in the user's temporary directory, eg. `/private/var/folders/3x/jf5977fn79j/T/vid.mp4`.

#### fps

Type: `number`<br>
Expand Down