Skip to content

Commit

Permalink
Add timeslice parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierapivideo committed Aug 20, 2024
1 parent 26698b9 commit d70ab66
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [0.2.4] - 2024-08-20
- Add `timeslice` parameter

## [0.2.3] - 2023-07-20
- add effects alpha version

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,13 @@ Using delegated upload tokens for authentication is best options when uploading
###### Common options
| Option name | Mandatory | Type | Description |
| ----------: | --------- | ------ | ------------------------------------------------------------------- |
| videoName | no | string | the name of your recorded video (overrides the default "file" name) |
| apiHost | no | string | api.video host (default: ws.api.video) |
| retries | no | number | number of retries when an API call fails (default: 5) |
| Option name | Mandatory | Type | Description |
| ----------: | ------------------ | ------ | ------------------------------------------------------------------- |
| videoName | no | string | the name of your recorded video (overrides the default "file" name) |
| apiHost | no | string | api.video host (default: ws.api.video) |
| retries | no | number | number of retries when an API call fails (default: 5) |
| timeslice | no (default: 5000) | number | The number of milliseconds to record into each Blob. |
**Example**
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "@api.video/media-stream-composer",
"version": "0.2.3",
"version": "0.2.4",
"description": "api.video media stream composer",
"repository": {
"type": "git",
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ declare global {

export type MouseTool = "draw" | "move-resize";

type RecordingOptions = RecorderOptions & (ProgressiveUploaderOptionsWithUploadToken | ProgressiveUploaderOptionsWithAccessToken);
type RecordingOptions = RecorderOptions & (ProgressiveUploaderOptionsWithUploadToken | ProgressiveUploaderOptionsWithAccessToken) & {timeslice?: number};

const DEFAULT_TIMESLICE = 5000;

export class MediaStreamComposer {
private result: MediaStream | null = null;
Expand Down Expand Up @@ -170,7 +172,9 @@ export class MediaStreamComposer {

public startRecording(options: RecordingOptions) {
if(!this.started) this.init();


this._updateAudioDelay(Math.min(5000, options.timeslice || DEFAULT_TIMESLICE));

this.recorder = new ApiVideoMediaRecorder(this.result!, {
...options,
origin: {
Expand All @@ -187,7 +191,7 @@ export class MediaStreamComposer {
this.recorder?.addEventListener(event, (e) => this.eventTarget.dispatchEvent(Object.assign(new Event(event), { data: (e as any).data })));
});

this.recorder.start();
this.recorder.start({ timeslice: options.timeslice || DEFAULT_TIMESLICE });
}

public destroy() {
Expand Down

0 comments on commit d70ab66

Please sign in to comment.