Skip to content

Commit

Permalink
feat: option to set audio preset, default: music e.g Bitrate 32000
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Nov 24, 2023
1 parent 562c141 commit 43078fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/assets/config_sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ window.DEFAULT_WEBCAM_RESOLUTION = 'h720';
// Default: h1080fps15
window.DEFAULT_SCREEN_SHARE_RESOLUTION = 'h1080fps15';

// Available options: 'telephone' | 'speech' | 'music' | 'musicStereo' | 'musicHighQuality' | 'musicHighQualityStereo'.
// Default: music
window.DEFAULT_AUDIO_PRESET = 'music';

//For local tracks, stop the underlying MediaStreamTrack when the track is muted (or paused) on some platforms, this option is necessary to disable the microphone recording indicator. Note: when this is enabled, and BT devices are connected, they will transition between profiles (e.g. HFP to A2DP) and there will be an audible difference in playback.
window.STOP_MIC_TRACK_ON_MUTE = true;

Expand Down
5 changes: 4 additions & 1 deletion src/components/footer/icons/microphone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
AnalyticsEventType,
AnalyticsStatus,
} from '../../../helpers/proto/plugnmeet_analytics_pb';
import { getAudioPreset } from '../../../helpers/utils';

interface IMicrophoneIconProps {
currentRoom: Room;
Expand Down Expand Up @@ -239,7 +240,9 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {
for (let i = 0; i < localTracks.length; i++) {
const track = localTracks[i];
if (track.kind === Track.Kind.Audio) {
await currentRoom?.localParticipant.publishTrack(track);
await currentRoom?.localParticipant.publishTrack(track, {
audioPreset: getAudioPreset(),
});
dispatch(updateIsActiveMicrophone(true));
}
}
Expand Down
30 changes: 29 additions & 1 deletion src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScreenSharePresets, VideoPresets } from 'livekit-client';
import { AudioPresets, ScreenSharePresets, VideoPresets } from 'livekit-client';

export async function getDevices(kind: MediaDeviceKind) {
let constraints: MediaStreamConstraints = {
Expand Down Expand Up @@ -117,6 +117,34 @@ export const getScreenShareResolution = () => {
return resolution;
};

export const getAudioPreset = () => {
const selected = (window as any).DEFAULT_AUDIO_PRESET ?? 'music';
let preset = AudioPresets.music;

switch (selected) {
case 'telephone':
preset = AudioPresets.telephone;
break;
case 'speech':
preset = AudioPresets.speech;
break;
case 'music':
preset = AudioPresets.music;
break;
case 'musicStereo':
preset = AudioPresets.musicStereo;
break;
case 'musicHighQuality':
preset = AudioPresets.musicHighQuality;
break;
case 'musicHighQualityStereo':
preset = AudioPresets.musicHighQualityStereo;
break;
}

return preset;
};

/**
* getAccessToken will try to get token by the following:
* from `access_token` GET/Search parameter from URL OR
Expand Down

0 comments on commit 43078fe

Please sign in to comment.