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

(feature): option to record videos. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,28 @@ exports['screenshot-basic']:requestClientScreenshot(GetPlayers()[1], {
print('err', err)
print('data', data)
end)
```

#### requestClientVideo(player: string | number, options: any, cb: (err: string | boolean, data: string) => void)
Requests the specified client to record a video.

Arguments:
* **player**: The target player's player index.
* **options**: An object containing options.
* **fileName**: string? - The file name on the server to save the video to. If not passed, the callback will get a data URI for the video data.
* **encoding**: 'webm' | 'mp4' - The target image encoding. Defaults to 'webm'.
* **duration**: int? - The duration of the video recording (in ms). Defaults to 1000ms.
* **cb**: A callback upon result.
* **err**: `false`, or an error string.
* **data**: The local file name the upload was saved to, or the data URI for the image.


Example:
```lua
exports['screenshot-basic']:requestClientVideo(GetPlayers()[1], {
fileName = 'cache/screenshot.webm'
}, function(err, data)
print('err', err)
print('data', data)
end)
```
18 changes: 17 additions & 1 deletion src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,20 @@ onNet('screenshot_basic:requestScreenshot', (options: any, url: string) => {
SendNuiMessage(JSON.stringify({
request: options
}));
});
});

onNet('screenshot_basic:requestVideo', (options: any, url: string) => {
const realOptions = {
isVideo: true,
duration: options.duration || 1000,
encoding: options.encoding || 'webm',
targetURL: `http://${GetCurrentServerEndpoint()}${url}`,
targetField: 'file',
resultURL: false,
correlation: registerCorrelation(() => { })
};

SendNuiMessage(JSON.stringify({
request: realOptions
}));
});
14 changes: 14 additions & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,18 @@ exp('requestClientScreenshot', (player: string | number, options: any, cb: (err:
};

emitNet('screenshot_basic:requestScreenshot', player, options, `/${GetCurrentResourceName()}/upload/${tkn}`);
});

exp('requestClientVideo', (player: string | number, options: any, cb: (err: string | boolean, data: string) => void) => {
const tkn = v4();

const fileName = options.fileName;
delete options['fileName']; // so the client won't get to know this

uploads[tkn] = {
fileName,
cb
};

emitNet('screenshot_basic:requestVideo', player, options, `/${GetCurrentResourceName()}/upload/${tkn}`);
});
Loading