@@ -441,7 +441,7 @@ module.exports = function (spec, on_status, on_track) {
441441 // Check Media MID with saved operation
442442 if ( ! operationMap . has ( mid ) ) {
443443 log . warn ( `MID ${ mid } in offer has no mapped operations (disabled)` ) ;
444- remoteSdp . setMediaPort ( mid , 0 ) ;
444+ remoteSdp . closeMedia ( mid ) ;
445445 return ;
446446 }
447447 if ( operationMap . get ( mid ) . sdpDirection !== remoteSdp . mediaDirection ( mid ) ) {
@@ -452,9 +452,10 @@ module.exports = function (spec, on_status, on_track) {
452452 log . warn ( `MID ${ mid } in offer has conflict media type with operation` ) ;
453453 return ;
454454 }
455- if ( operationMap . get ( mid ) . enabled && ( remoteSdp . getMediaPort ( mid ) === 0 ) ) {
456- log . warn ( `MID ${ mid } in offer has conflict port with operation (disabled)` ) ;
455+ if ( operationMap . get ( mid ) . enabled && remoteSdp . isMediaClosed ( mid ) ) {
456+ log . warn ( `MID ${ mid } in offer has conflict closed state (disabled)` ) ;
457457 operationMap . get ( mid ) . enabled = false ;
458+ return ;
458459 }
459460
460461 // Determine media format in offer
@@ -501,34 +502,28 @@ module.exports = function (spec, on_status, on_track) {
501502 const addedMids = [ ] ;
502503 const removedMids = [ ] ;
503504
504- for ( let cmid of changedMids ) {
505+ for ( let cmid of laterSdp . mids ( ) ) {
505506 const oldMedia = remoteSdp . media ( cmid ) ;
506507 if ( ! oldMedia ) {
507508 // Add media
508509 const tempSdp = laterSdp . singleMediaSdp ( cmid ) ;
509510 remoteSdp . mergeMedia ( tempSdp ) ;
510511 addedMids . push ( cmid ) ;
511- } else if ( laterSdp . getMediaPort ( cmid ) === 0 ) {
512+ } else if ( laterSdp . isMediaClosed ( cmid ) ) {
512513 // Remove media
513- remoteSdp . setMediaPort ( cmid , 0 ) ;
514- localSdp . setMediaPort ( cmid , 0 ) ;
515- removedMids . push ( cmid ) ;
516- } else if ( laterSdp . mediaDirection ( cmid ) === 'inactive' ) {
517- // Disable media
518- remoteSdp . media ( cmid ) . direction = 'inactive' ;
519- localSdp . media ( cmid ) . direction = 'inactive' ;
514+ remoteSdp . closeMedia ( cmid ) ;
520515 removedMids . push ( cmid ) ;
521516 } else {
522- // May be port or direction change
523- log . debug ( `MID ${ cmid } port or direction change` ) ;
517+ // Treat as no change
518+ log . debug ( `MID ${ cmid } no change` ) ;
524519 }
525520 }
526521
527522 let opId = null ;
528523 for ( let mid of addedMids ) {
529524 processOfferMedia ( mid ) ;
530525 localSdp . mergeMedia ( remoteSdp . singleMediaSdp ( mid ) . answer ( ) ) ;
531- if ( remoteSdp . getMediaPort ( mid ) !== 0 ) {
526+ if ( ! remoteSdp . isMediaClosed ( mid ) ) {
532527 opId = setupTransport ( mid ) ;
533528 }
534529 }
@@ -540,10 +535,11 @@ module.exports = function (spec, on_status, on_track) {
540535 }
541536
542537 for ( let mid of removedMids ) {
543- // processOfferMedia(mid);
538+ localSdp . closeMedia ( mid ) ;
539+ // Should already be destroyed by 'removeTrackOperation'
544540 // destroyTransport(mid);
545541 }
546-
542+ localSdp . setBundleMids ( remoteSdp . bundleMids ( ) ) ;
547543 // Produce answer
548544 const message = localSdp . toString ( ) ;
549545 log . debug ( 'Answer SDP' , message ) ;
0 commit comments