Skip to content

Commit

Permalink
(feature): option to record videos.
Browse files Browse the repository at this point in the history
Add the record feature, which allows for a more "developed" capturing of a client's game.
  • Loading branch information
spoty123 committed Sep 18, 2022
1 parent 5e89d4a commit 09ed39a
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 80 deletions.
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

0 comments on commit 09ed39a

Please sign in to comment.