@@ -5,10 +5,11 @@ import {
55 filterIceServers ,
66} from './utils/helpers'
77import {
8- sdpStereoHack ,
98 sdpBitrateHack ,
109 sdpMediaOrderHack ,
1110 sdpHasValidCandidates ,
11+ useAudioCodecs ,
12+ sdpStereoHack ,
1213} from './utils/sdpHelpers'
1314import { BaseConnection } from './BaseConnection'
1415import {
@@ -71,6 +72,8 @@ export default class RTCPeer<EventTypes extends EventEmitter.ValidEventTypes> {
7172 this . options
7273 )
7374
75+ this . _validateOptions ( )
76+
7477 this . _onIce = this . _onIce . bind ( this )
7578 this . _onEndedTrackHandler = this . _onEndedTrackHandler . bind ( this )
7679
@@ -86,6 +89,16 @@ export default class RTCPeer<EventTypes extends EventEmitter.ValidEventTypes> {
8689 this . rtcConfigPolyfill = this . config
8790 }
8891
92+ private _validateOptions ( ) {
93+ if (
94+ this . options . useStereo === true &&
95+ typeof this . options . audio === 'object' &&
96+ ( this . options . audio . channelCount ?? 2 ) !== 2
97+ ) {
98+ throw new Error ( 'Mismatch params: useStereo, audio.channelCount' )
99+ }
100+ }
101+
89102 get options ( ) {
90103 return this . call . options
91104 }
@@ -820,6 +833,7 @@ export default class RTCPeer<EventTypes extends EventEmitter.ValidEventTypes> {
820833 googleMaxBitrate,
821834 googleMinBitrate,
822835 googleStartBitrate,
836+ audioCodecs,
823837 } = this . options
824838 if ( localDescription . sdp && useStereo ) {
825839 localDescription . sdp = sdpStereoHack ( localDescription . sdp )
@@ -837,17 +851,15 @@ export default class RTCPeer<EventTypes extends EventEmitter.ValidEventTypes> {
837851 googleStartBitrate
838852 )
839853 }
840- // this.logger.debug(
841- // 'LOCAL SDP \n',
842- // `Type: ${localDescription.type}`,
843- // '\n\n',
844- // localDescription.sdp
845- // )
854+ if ( localDescription . sdp && audioCodecs ) {
855+ localDescription . sdp = useAudioCodecs ( localDescription . sdp , audioCodecs )
856+ }
846857 return this . instance . setLocalDescription ( localDescription )
847858 }
848859
849860 private _setRemoteDescription ( remoteDescription : RTCSessionDescriptionInit ) {
850- if ( remoteDescription . sdp && this . options . useStereo ) {
861+ const { useStereo } = this . options
862+ if ( remoteDescription . sdp && useStereo ) {
851863 remoteDescription . sdp = sdpStereoHack ( remoteDescription . sdp )
852864 }
853865 if ( remoteDescription . sdp && this . instance . localDescription ) {
0 commit comments