@@ -264,7 +264,7 @@ export class RTCPeerConnection extends EventTarget {
264264 if ( iceRestart || this . needRestart ) {
265265 this . needRestart = false ;
266266 for ( const t of this . iceTransports ) {
267- await t . restart ( ) ;
267+ t . restart ( ) ;
268268 }
269269 }
270270
@@ -919,100 +919,95 @@ export class RTCPeerConnection extends EventTarget {
919919 transceiver . kind === media . kind &&
920920 [ undefined , media . rtp . muxId ] . includes ( transceiver . mid ) ;
921921
922- let transports = ( await Promise . all (
923- remoteSdp . media . map ( async ( remoteMedia , i ) => {
924- let dtlsTransport : RTCDtlsTransport ;
922+ let transports = remoteSdp . media . map ( ( remoteMedia , i ) => {
923+ let dtlsTransport : RTCDtlsTransport ;
925924
926- if ( [ "audio" , "video" ] . includes ( remoteMedia . kind ) ) {
927- let transceiver = this . transceivers . find ( ( t ) =>
928- matchTransceiverWithMedia ( t , remoteMedia ) ,
929- ) ;
930- if ( ! transceiver ) {
931- // create remote transceiver
932- transceiver = this . _addTransceiver ( remoteMedia . kind , {
933- direction : "recvonly" ,
934- } ) ;
935- transceiver . mid = remoteMedia . rtp . muxId ;
936- this . onRemoteTransceiverAdded . execute ( transceiver ) ;
937- } else {
938- if ( transceiver . direction === "inactive" && transceiver . stopping ) {
939- transceiver . stopped = true ;
925+ if ( [ "audio" , "video" ] . includes ( remoteMedia . kind ) ) {
926+ let transceiver = this . transceivers . find ( ( t ) =>
927+ matchTransceiverWithMedia ( t , remoteMedia ) ,
928+ ) ;
929+ if ( ! transceiver ) {
930+ // create remote transceiver
931+ transceiver = this . _addTransceiver ( remoteMedia . kind , {
932+ direction : "recvonly" ,
933+ } ) ;
934+ transceiver . mid = remoteMedia . rtp . muxId ;
935+ this . onRemoteTransceiverAdded . execute ( transceiver ) ;
936+ } else {
937+ if ( transceiver . direction === "inactive" && transceiver . stopping ) {
938+ transceiver . stopped = true ;
940939
941- if ( sessionDescription . type === "answer" ) {
942- transceiver . setCurrentDirection ( "inactive" ) ;
943- }
944- return ;
940+ if ( sessionDescription . type === "answer" ) {
941+ transceiver . setCurrentDirection ( "inactive" ) ;
945942 }
943+ return ;
946944 }
945+ }
947946
948- if ( this . remoteIsBundled ) {
949- if ( ! bundleTransport ) {
950- bundleTransport = transceiver . dtlsTransport ;
951- } else {
952- transceiver . setDtlsTransport ( bundleTransport ) ;
953- }
947+ if ( this . remoteIsBundled ) {
948+ if ( ! bundleTransport ) {
949+ bundleTransport = transceiver . dtlsTransport ;
950+ } else {
951+ transceiver . setDtlsTransport ( bundleTransport ) ;
954952 }
953+ }
955954
956- dtlsTransport = transceiver . dtlsTransport ;
955+ dtlsTransport = transceiver . dtlsTransport ;
957956
958- this . setRemoteRTP ( transceiver , remoteMedia , remoteSdp . type , i ) ;
959- } else if ( remoteMedia . kind === "application" ) {
960- if ( ! this . sctpTransport ) {
961- this . sctpTransport = this . createSctpTransport ( ) ;
962- this . sctpTransport . mid = remoteMedia . rtp . muxId ;
963- }
957+ this . setRemoteRTP ( transceiver , remoteMedia , remoteSdp . type , i ) ;
958+ } else if ( remoteMedia . kind === "application" ) {
959+ if ( ! this . sctpTransport ) {
960+ this . sctpTransport = this . createSctpTransport ( ) ;
961+ this . sctpTransport . mid = remoteMedia . rtp . muxId ;
962+ }
964963
965- if ( this . remoteIsBundled ) {
966- if ( ! bundleTransport ) {
967- bundleTransport = this . sctpTransport . dtlsTransport ;
968- } else {
969- this . sctpTransport . setDtlsTransport ( bundleTransport ) ;
970- }
964+ if ( this . remoteIsBundled ) {
965+ if ( ! bundleTransport ) {
966+ bundleTransport = this . sctpTransport . dtlsTransport ;
967+ } else {
968+ this . sctpTransport . setDtlsTransport ( bundleTransport ) ;
971969 }
970+ }
972971
973- dtlsTransport = this . sctpTransport . dtlsTransport ;
972+ dtlsTransport = this . sctpTransport . dtlsTransport ;
974973
975- this . setRemoteSCTP ( remoteMedia , this . sctpTransport , i ) ;
976- } else {
977- throw new Error ( "invalid media kind" ) ;
978- }
974+ this . setRemoteSCTP ( remoteMedia , this . sctpTransport , i ) ;
975+ } else {
976+ throw new Error ( "invalid media kind" ) ;
977+ }
979978
980- const iceTransport = dtlsTransport . iceTransport ;
979+ const iceTransport = dtlsTransport . iceTransport ;
981980
982- if ( remoteMedia . iceParams ) {
983- const renomination = ! ! remoteSdp . media . find (
984- ( m ) => m . direction === "inactive" ,
985- ) ;
986- await iceTransport . setRemoteParams (
987- remoteMedia . iceParams ,
988- renomination ,
989- ) ;
981+ if ( remoteMedia . iceParams ) {
982+ const renomination = ! ! remoteSdp . media . find (
983+ ( m ) => m . direction === "inactive" ,
984+ ) ;
985+ iceTransport . setRemoteParams ( remoteMedia . iceParams , renomination ) ;
990986
991- // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role
992- // RFC 8445 S6.1.1
993- if ( remoteMedia . iceParams ?. iceLite ) {
994- iceTransport . connection . iceControlling = true ;
995- }
996- }
997- if ( remoteMedia . dtlsParams ) {
998- dtlsTransport . setRemoteParams ( remoteMedia . dtlsParams ) ;
987+ // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role
988+ // RFC 8445 S6.1.1
989+ if ( remoteMedia . iceParams ?. iceLite ) {
990+ iceTransport . connection . iceControlling = true ;
999991 }
992+ }
993+ if ( remoteMedia . dtlsParams ) {
994+ dtlsTransport . setRemoteParams ( remoteMedia . dtlsParams ) ;
995+ }
1000996
1001- // # add ICE candidates
1002- remoteMedia . iceCandidates . forEach ( iceTransport . addRemoteCandidate ) ;
997+ // # add ICE candidates
998+ remoteMedia . iceCandidates . forEach ( iceTransport . addRemoteCandidate ) ;
1003999
1004- if ( remoteMedia . iceCandidatesComplete ) {
1005- iceTransport . addRemoteCandidate ( undefined ) ;
1006- }
1000+ if ( remoteMedia . iceCandidatesComplete ) {
1001+ iceTransport . addRemoteCandidate ( undefined ) ;
1002+ }
10071003
1008- // # set DTLS role
1009- if ( remoteSdp . type === "answer" && remoteMedia . dtlsParams ?. role ) {
1010- dtlsTransport . role =
1011- remoteMedia . dtlsParams . role === "client" ? "server" : "client" ;
1012- }
1013- return iceTransport ;
1014- } ) ,
1015- ) ) as RTCIceTransport [ ] ;
1004+ // # set DTLS role
1005+ if ( remoteSdp . type === "answer" && remoteMedia . dtlsParams ?. role ) {
1006+ dtlsTransport . role =
1007+ remoteMedia . dtlsParams . role === "client" ? "server" : "client" ;
1008+ }
1009+ return iceTransport ;
1010+ } ) as RTCIceTransport [ ] ;
10161011
10171012 // filter out inactive transports
10181013 transports = transports . filter ( ( iceTransport ) => ! ! iceTransport ) ;
0 commit comments