Skip to content

Commit

Permalink
Add option to prevent automatic device switch on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
geekuillaume committed Sep 17, 2020
1 parent 455c9fd commit 4c410b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/audiostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ AudioStream::AudioStream(
_params.prefs = CUBEB_STREAM_PREF_LOOPBACK;
}

if (!opts.Get("disableSwitching").IsNull() && !opts.Get("disableSwitching").IsUndefined()) {
if (opts.Get("disableSwitching").As<Napi::Boolean>().Value()) {
_params.prefs = (cubeb_stream_prefs)(_params.prefs & CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING);
}
}

if (!opts.Get("format").IsNull() && !opts.Get("format").IsUndefined()) {
_params.format = (cubeb_sample_format)opts.Get("format").As<Napi::Number>().Int32Value();
if (device->format & _params.format == 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ interface StreamParams {

/** size of the buffer in frames */
latencyFrames?: number;

/** prevent device switch by OS on disconnect */
disableSwitching?: boolean;
}

export declare class AudioServer {
Expand Down

0 comments on commit 4c410b4

Please sign in to comment.