@@ -10,6 +10,8 @@ import {
1010 setTracksEnabled ,
1111} from './utils' ;
1212
13+ const POLITE_DEFAULT_VALUE = true ;
14+
1315export default class Peer {
1416 private peerConn : RTCPeerConnection ;
1517
@@ -19,7 +21,7 @@ export default class Peer {
1921
2022 private readonly emitter = new EventEmitter ( ) as TypedEmitter < PeerEvents > ;
2123
22- private polite = true ;
24+ private polite = POLITE_DEFAULT_VALUE ;
2325
2426 private makingOffer = false ;
2527
@@ -165,8 +167,12 @@ export default class Peer {
165167 return this . peerConn ;
166168 }
167169
168- public start ( { polite = false } : { polite ?: boolean } = { } ) {
170+ public start ( { polite = POLITE_DEFAULT_VALUE } : { polite ?: boolean } = { } ) {
169171 try {
172+ // reset peer if only local offer is set
173+ if ( this . peerConn ?. signalingState === 'have-local-offer' ) {
174+ this . destroy ( ) ;
175+ }
170176 if ( this . isClosed ( ) ) {
171177 this . init ( ) ;
172178 }
@@ -209,7 +215,7 @@ export default class Peer {
209215 this . emit ( 'signal' , this . peerConn . localDescription ) ;
210216 }
211217 }
212- this . polite = true ;
218+ this . polite = POLITE_DEFAULT_VALUE ;
213219 } catch ( err ) {
214220 this . error ( 'Failed to set local/remote descriptions' , err ) ;
215221 }
@@ -282,7 +288,7 @@ export default class Peer {
282288 /** Closes any active peer connection */
283289 public destroy ( ) {
284290 if ( ! this . isClosed ( ) ) {
285- this . polite = true ;
291+ this . polite = POLITE_DEFAULT_VALUE ;
286292 this . makingOffer = false ;
287293 this . ignoreOffer = false ;
288294 this . peerConn . close ( ) ;
0 commit comments