Skip to content

Commit 09ed39a

Browse files
committed
(feature): option to record videos.
Add the record feature, which allows for a more "developed" capturing of a client's game.
1 parent 5e89d4a commit 09ed39a

File tree

4 files changed

+204
-80
lines changed

4 files changed

+204
-80
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,28 @@ exports['screenshot-basic']:requestClientScreenshot(GetPlayers()[1], {
8888
print('err', err)
8989
print('data', data)
9090
end)
91+
```
92+
93+
#### requestClientVideo(player: string | number, options: any, cb: (err: string | boolean, data: string) => void)
94+
Requests the specified client to record a video.
95+
96+
Arguments:
97+
* **player**: The target player's player index.
98+
* **options**: An object containing options.
99+
* **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.
100+
* **encoding**: 'webm' | 'mp4' - The target image encoding. Defaults to 'webm'.
101+
* **duration**: int? - The duration of the video recording (in ms). Defaults to 1000ms.
102+
* **cb**: A callback upon result.
103+
* **err**: `false`, or an error string.
104+
* **data**: The local file name the upload was saved to, or the data URI for the image.
105+
106+
107+
Example:
108+
```lua
109+
exports['screenshot-basic']:requestClientVideo(GetPlayers()[1], {
110+
fileName = 'cache/screenshot.webm'
111+
}, function(err, data)
112+
print('err', err)
113+
print('data', data)
114+
end)
91115
```

src/client/client.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,20 @@ onNet('screenshot_basic:requestScreenshot', (options: any, url: string) => {
7777
SendNuiMessage(JSON.stringify({
7878
request: options
7979
}));
80-
});
80+
});
81+
82+
onNet('screenshot_basic:requestVideo', (options: any, url: string) => {
83+
const realOptions = {
84+
isVideo: true,
85+
duration: options.duration || 1000,
86+
encoding: options.encoding || 'webm',
87+
targetURL: `http://${GetCurrentServerEndpoint()}${url}`,
88+
targetField: 'file',
89+
resultURL: false,
90+
correlation: registerCorrelation(() => { })
91+
};
92+
93+
SendNuiMessage(JSON.stringify({
94+
request: realOptions
95+
}));
96+
});

src/server/server.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,18 @@ exp('requestClientScreenshot', (player: string | number, options: any, cb: (err:
9393
};
9494

9595
emitNet('screenshot_basic:requestScreenshot', player, options, `/${GetCurrentResourceName()}/upload/${tkn}`);
96+
});
97+
98+
exp('requestClientVideo', (player: string | number, options: any, cb: (err: string | boolean, data: string) => void) => {
99+
const tkn = v4();
100+
101+
const fileName = options.fileName;
102+
delete options['fileName']; // so the client won't get to know this
103+
104+
uploads[tkn] = {
105+
fileName,
106+
cb
107+
};
108+
109+
emitNet('screenshot_basic:requestVideo', player, options, `/${GetCurrentResourceName()}/upload/${tkn}`);
96110
});

0 commit comments

Comments
 (0)