Skip to content

Commit

Permalink
Fix: Renamed maxRecordTimeMs to maxRecordTimeMinutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirdock committed Nov 25, 2023
1 parent 26d24b9 commit cbf4d3f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.6
- Fix: Renamed `maxRecordTimeMs` to `maxRecordTimeMinutes` and accept minutes instead of ms.

# 1.0.5
- Fix: `maxRecordTimeMs` was actually taken as minutes instead of ms.
- Doc: The description for the record time and length were switched.
Expand Down
2 changes: 1 addition & 1 deletion models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type RecordOptions = {
/**
* Keep last x minutes for recording. Older voice chunks will be deleted. Default 10.
*/
maxRecordTimeMs: number;
maxRecordTimeMinutes: number;
/**
* Target sample rate of the recorded stream. Default 16,000.
*/
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": "@kirdock/discordjs-voice-recorder",
"version": "1.0.5",
"version": "1.0.6",
"license": "MIT",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/voice-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class VoiceRecorder {
constructor(options: Partial<RecordOptions> = {}, private discordClient?: DiscordClientInterface) {
this.options = {
maxUserRecordingLength: (options.maxUserRecordingLength ?? 100) * 1_024 * 1_024,
maxRecordTimeMs: options.maxRecordTimeMs ?? 10 * 60 * 1_000,
maxRecordTimeMinutes: (options.maxRecordTimeMinutes ?? 10) * 60 * 1_000,
sampleRate: (options.sampleRate ?? 16_000),
channelCount: (options.channelCount ?? 2)
};
Expand Down Expand Up @@ -61,14 +61,14 @@ export class VoiceRecorder {
return;
}

const recordStream = new ReplayReadable(this.options.maxRecordTimeMs, this.options.sampleRate, this.options.channelCount, ()=> connection.receiver.speaking.users.get(userId), {
const recordStream = new ReplayReadable(this.options.maxRecordTimeMinutes, this.options.sampleRate, this.options.channelCount, ()=> connection.receiver.speaking.users.get(userId), {
highWaterMark: this.options.maxUserRecordingLength,
length: this.options.maxUserRecordingLength
});
const opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: this.options.maxRecordTimeMs,
duration: this.options.maxRecordTimeMinutes,
},
});

Expand Down Expand Up @@ -137,7 +137,7 @@ export class VoiceRecorder {
return false;
}

const recordDurationMs = Math.min(Math.abs(minutes) * 60 * 1_000, this.options.maxRecordTimeMs);
const recordDurationMs = Math.min(Math.abs(minutes) * 60 * 1_000, this.options.maxRecordTimeMinutes);
const endTimeMs = Date.now();
const maxRecordTime = endTimeMs - recordDurationMs;
const startRecordTime = Math.max(minStartTimeMs, maxRecordTime);
Expand Down

0 comments on commit cbf4d3f

Please sign in to comment.