Skip to content

Commit 3d6cac8

Browse files
committed
Add new function setLimitSeconds
1 parent ef154c3 commit 3d6cac8

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Looking at the examples in the `/src/stories` folder should give you some ideas
8383
- <a href="#isBuilt">`videomailClient.isBuilt()`</a>
8484
- <a href="#submit">`videomailClient.submit()`</a>
8585
- <a href="#getLogLines">`videomailClient.getLogLines()`</a>
86+
- <a href="#setLimitSeconds">`videomailClient.setLimitSeconds()`</a>
8687

8788
<a name="constructor"></a>
8889

@@ -201,6 +202,12 @@ Calling this function will manually trigger a submission of the recorded videoma
201202

202203
For advanced use only: returns you a collection of log lines that show what code has been covered recently. Useful if you want to debug something tricky.
203204

205+
<a name="setLimitSeconds"></a>
206+
207+
### videomailClient.setLimitSeconds()
208+
209+
For advanced use only: sets the recording time limit in seconds. Useful if you want to dynamically change the recording duration.
210+
204211
<a name="whatisstored"></a>
205212

206213
## What gets stored on the videomail server?

src/client.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ class VideomailClient extends Despot {
7777
this.container.startOver(params);
7878
}
7979

80+
// Useful for altering limit when user has changed options in real-time like
81+
// enabling/disabling audio etc
82+
public setLimitSeconds(limitSeconds: number) {
83+
if (this.options.video.limitSeconds === limitSeconds) {
84+
this.options.logger.debug(
85+
`Client: setLimitSeconds called but limitSeconds is already ${limitSeconds}, doing nothing.`,
86+
);
87+
88+
return;
89+
}
90+
91+
this.options.video.limitSeconds = limitSeconds;
92+
93+
this.options.logger.debug(`Client: setLimitSeconds (limitSeconds = ${limitSeconds})`);
94+
95+
this.container.setLimitSeconds(limitSeconds);
96+
}
97+
8098
public unload(startingOver = false) {
8199
this.container.unload({ startingOver });
82100
}

src/stories/Record.stories.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,43 @@ export const Audio: Story = {
7979
},
8080
};
8181

82+
export const ChangingLimit: Story = {
83+
name: "Changing limit on the fly",
84+
args: {
85+
enableAutoPause: false,
86+
audio: {
87+
enabled: false,
88+
switch: true,
89+
},
90+
image: {
91+
quality: 0.4,
92+
},
93+
video: {
94+
limitSeconds: 30,
95+
countdown: false,
96+
width: 320,
97+
},
98+
text: {
99+
buttons: {
100+
preview: "Stop",
101+
},
102+
},
103+
},
104+
render: (args) => {
105+
const videomailClient = new VideomailClient(args);
106+
107+
videomailClient.on("ENABLING_AUDIO", function () {
108+
videomailClient.setLimitSeconds(15);
109+
});
110+
111+
videomailClient.on("DISABLING_AUDIO", function () {
112+
videomailClient.setLimitSeconds(30);
113+
});
114+
115+
return videomailClient.show();
116+
},
117+
};
118+
82119
// High quality: High FPS, near HD quality, short duration and without auto-pause
83120
//
84121
// This example shows that your browser cannot meet the FPS requirements due to

src/wrappers/container.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,11 @@ class Container extends Despot {
899899
public recordAgain() {
900900
this.visuals.recordAgain();
901901
}
902+
903+
public setLimitSeconds(limitSeconds: number) {
904+
this.options.video.limitSeconds = limitSeconds;
905+
this.visuals.setLimitSeconds(limitSeconds);
906+
}
902907
}
903908

904909
export default Container;

src/wrappers/visuals.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ class Visuals extends Despot {
480480
}
481481
}
482482

483+
public setLimitSeconds(limitSeconds: number) {
484+
this.options.video.limitSeconds = limitSeconds;
485+
this.recorderInsides.setLimitSeconds(limitSeconds);
486+
}
487+
483488
public getElement() {
484489
return this.visualsElement;
485490
}

src/wrappers/visuals/inside/recorder/recordTimer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class RecordTimer {
121121
return this.options.video.limitSeconds;
122122
}
123123

124+
public setLimitSeconds(limitSeconds: number) {
125+
this.options.video.limitSeconds = limitSeconds;
126+
}
127+
124128
public start() {
125129
this.countdown = this.getStartSeconds();
126130
this.nearComputed = this.endNighComputed = false;

src/wrappers/visuals/inside/recorderInsides.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ class RecorderInsides extends Despot {
153153
public checkTimer(elapsedTime: number) {
154154
this.recordTimer.check(elapsedTime);
155155
}
156+
157+
public setLimitSeconds(limitSeconds: number) {
158+
this.options.video.limitSeconds = limitSeconds;
159+
this.recordTimer.setLimitSeconds(limitSeconds);
160+
}
156161
}
157162

158163
export default RecorderInsides;

0 commit comments

Comments
 (0)