werift 0.25.2 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/lib/common/src/asn1.d.ts +42 -0
  2. package/lib/common/src/asn1.js +163 -0
  3. package/lib/common/src/asn1.js.map +1 -0
  4. package/lib/common/src/binaryData.js.map +1 -1
  5. package/lib/common/src/index.d.ts +6 -5
  6. package/lib/common/src/index.js +6 -5
  7. package/lib/common/src/index.js.map +1 -1
  8. package/lib/common/src/log.d.ts +12 -1
  9. package/lib/common/src/log.js +137 -5
  10. package/lib/common/src/log.js.map +1 -1
  11. package/lib/common/src/network.js.map +1 -1
  12. package/lib/common/src/queue.d.ts +41 -0
  13. package/lib/common/src/queue.js +146 -0
  14. package/lib/common/src/queue.js.map +1 -0
  15. package/lib/common/src/transport.d.ts +15 -2
  16. package/lib/common/src/transport.js +98 -14
  17. package/lib/common/src/transport.js.map +1 -1
  18. package/lib/dtls/src/cipher/create.js.map +1 -1
  19. package/lib/dtls/src/cipher/ec.js +8 -8
  20. package/lib/dtls/src/cipher/ec.js.map +1 -1
  21. package/lib/dtls/src/cipher/namedCurve.js +6 -7
  22. package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
  23. package/lib/dtls/src/cipher/prf.d.ts +2 -2
  24. package/lib/dtls/src/cipher/prf.js +29 -8
  25. package/lib/dtls/src/cipher/prf.js.map +1 -1
  26. package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
  27. package/lib/dtls/src/context/certificate.d.ts +32 -0
  28. package/lib/dtls/src/context/certificate.js +54 -0
  29. package/lib/dtls/src/context/certificate.js.map +1 -0
  30. package/lib/dtls/src/context/cipher.d.ts +12 -6
  31. package/lib/dtls/src/context/cipher.js +52 -103
  32. package/lib/dtls/src/context/cipher.js.map +1 -1
  33. package/lib/dtls/src/context/transport.d.ts +4 -0
  34. package/lib/dtls/src/context/transport.js +14 -0
  35. package/lib/dtls/src/context/transport.js.map +1 -1
  36. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  37. package/lib/dtls/src/flight/flight.js +8 -1
  38. package/lib/dtls/src/flight/flight.js.map +1 -1
  39. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  40. package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
  41. package/lib/dtls/src/flight/server/flight4.js +8 -2
  42. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  43. package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
  44. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  45. package/lib/dtls/src/handshake/message/alert.js +1 -1
  46. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  47. package/lib/dtls/src/handshake/message/certificate.js +1 -1
  48. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  49. package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -3
  50. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  51. package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
  52. package/lib/dtls/src/handshake/message/client/certificateVerify.js +1 -1
  53. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  54. package/lib/dtls/src/handshake/message/client/hello.js +1 -1
  55. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  56. package/lib/dtls/src/handshake/message/client/keyExchange.js +1 -1
  57. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  58. package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
  59. package/lib/dtls/src/handshake/message/server/certificateRequest.js +1 -1
  60. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  61. package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
  62. package/lib/dtls/src/handshake/message/server/hello.js +2 -2
  63. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
  65. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +1 -1
  67. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
  69. package/lib/dtls/src/handshake/message/server/keyExchange.js +1 -1
  70. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  71. package/lib/dtls/src/handshake/random.d.ts +2 -2
  72. package/lib/dtls/src/handshake/random.js +2 -2
  73. package/lib/dtls/src/handshake/random.js.map +1 -1
  74. package/lib/dtls/src/imports/common.d.ts +1 -0
  75. package/lib/dtls/src/imports/common.js +1 -0
  76. package/lib/dtls/src/imports/common.js.map +1 -1
  77. package/lib/dtls/src/index.d.ts +2 -2
  78. package/lib/dtls/src/index.js +2 -2
  79. package/lib/dtls/src/index.js.map +1 -1
  80. package/lib/dtls/src/record/message/fragment.d.ts +1 -1
  81. package/lib/dtls/src/record/message/fragment.js +3 -3
  82. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  83. package/lib/dtls/src/record/message/header.js +2 -2
  84. package/lib/dtls/src/record/message/header.js.map +1 -1
  85. package/lib/dtls/src/server.js +1 -1
  86. package/lib/dtls/src/server.js.map +1 -1
  87. package/lib/dtls/src/socket.d.ts +2 -2
  88. package/lib/dtls/src/socket.js +2 -2
  89. package/lib/dtls/src/socket.js.map +1 -1
  90. package/lib/ice/src/exceptions.d.ts +30 -0
  91. package/lib/ice/src/exceptions.js +43 -1
  92. package/lib/ice/src/exceptions.js.map +1 -1
  93. package/lib/ice/src/helper.d.ts +1 -1
  94. package/lib/ice/src/ice.d.ts +142 -0
  95. package/lib/ice/src/ice.js +809 -53
  96. package/lib/ice/src/ice.js.map +1 -1
  97. package/lib/ice/src/iceBase.d.ts +49 -0
  98. package/lib/ice/src/iceBase.js.map +1 -1
  99. package/lib/ice/src/index.d.ts +5 -5
  100. package/lib/ice/src/index.js +5 -5
  101. package/lib/ice/src/index.js.map +1 -1
  102. package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
  103. package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
  104. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
  105. package/lib/ice/src/stun/protocol.d.ts +3 -1
  106. package/lib/ice/src/stun/protocol.js +16 -0
  107. package/lib/ice/src/stun/protocol.js.map +1 -1
  108. package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
  109. package/lib/ice/src/stun/tcpProtocol.js +16 -1
  110. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  111. package/lib/ice/src/stun/transaction.d.ts +5 -0
  112. package/lib/ice/src/stun/transaction.js +7 -1
  113. package/lib/ice/src/stun/transaction.js.map +1 -1
  114. package/lib/ice/src/turn/protocol.d.ts +73 -4
  115. package/lib/ice/src/turn/protocol.js +241 -12
  116. package/lib/ice/src/turn/protocol.js.map +1 -1
  117. package/lib/ice/src/utils.js.map +1 -1
  118. package/lib/ice-server/src/stun/message.d.ts +5 -1
  119. package/lib/ice-server/src/stun/message.js +33 -2
  120. package/lib/ice-server/src/stun/message.js.map +1 -1
  121. package/lib/ice-server/src/turn/auth.d.ts +1 -1
  122. package/lib/index.mjs +16273 -10807
  123. package/lib/nonstandard/index.mjs +8644 -7911
  124. package/lib/polyfill/dom.mjs +22435 -16965
  125. package/lib/polyfill/index.mjs +22435 -16965
  126. package/lib/rtp/src/codec/h264.d.ts +1 -1
  127. package/lib/rtp/src/codec/h264.js.map +1 -1
  128. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  129. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  130. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +20 -1
  131. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  132. package/lib/rtp/src/extra/processor/depacketizer.d.ts +1 -1
  133. package/lib/rtp/src/extra/processor/depacketizer.js +1 -1
  134. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  135. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  136. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  137. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  138. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  139. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  140. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  141. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  142. package/lib/rtp/src/extra/processor/mp4.js +1 -1
  143. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  144. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  145. package/lib/rtp/src/extra/processor/nack.js +1 -1
  146. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  147. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  148. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  149. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  150. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  151. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  152. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  153. package/lib/rtp/src/extra/processor/rtpCallback.js +1 -1
  154. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  155. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  156. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  157. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  158. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  159. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  160. package/lib/rtp/src/extra/processor/webm.js +43 -16
  161. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  162. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  163. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  164. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  165. package/lib/rtp/src/helper.d.ts +2 -2
  166. package/lib/rtp/src/helper.js +2 -6
  167. package/lib/rtp/src/helper.js.map +1 -1
  168. package/lib/rtp/src/index.d.ts +3 -2
  169. package/lib/rtp/src/index.js +3 -2
  170. package/lib/rtp/src/index.js.map +1 -1
  171. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +2 -1
  172. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  173. package/lib/rtp/src/rtcp/rtcp.js +2 -1
  174. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  175. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  176. package/lib/rtp/src/rtcp/sr.js +3 -2
  177. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  178. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  179. package/lib/rtp/src/srtp/cipher/ctr.js +1 -1
  180. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  181. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  182. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  183. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  184. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  185. package/lib/rtp/src/srtp/context/context.js +78 -24
  186. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  187. package/lib/rtp/src/srtp/context/srtp.js +23 -15
  188. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  189. package/lib/sctp/src/index.d.ts +4 -3
  190. package/lib/sctp/src/index.js +10 -8
  191. package/lib/sctp/src/index.js.map +1 -1
  192. package/lib/sctp/src/sctp.d.ts +11 -2
  193. package/lib/sctp/src/sctp.js +47 -28
  194. package/lib/sctp/src/sctp.js.map +1 -1
  195. package/lib/webrtc/src/api/peerConfig.d.ts +264 -0
  196. package/lib/webrtc/src/api/peerConfig.js +250 -0
  197. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  198. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  199. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  200. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  201. package/lib/webrtc/src/dataChannel.d.ts +1 -1
  202. package/lib/webrtc/src/dataChannel.js +1 -1
  203. package/lib/webrtc/src/dataChannel.js.map +1 -1
  204. package/lib/webrtc/src/index.d.ts +2 -2
  205. package/lib/webrtc/src/index.js +2 -2
  206. package/lib/webrtc/src/index.js.map +1 -1
  207. package/lib/webrtc/src/media/index.d.ts +1 -1
  208. package/lib/webrtc/src/media/index.js +1 -1
  209. package/lib/webrtc/src/media/index.js.map +1 -1
  210. package/lib/webrtc/src/media/receiver/nack.js +3 -4
  211. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  212. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  213. package/lib/webrtc/src/media/router.d.ts +116 -5
  214. package/lib/webrtc/src/media/router.js +281 -29
  215. package/lib/webrtc/src/media/router.js.map +1 -1
  216. package/lib/webrtc/src/media/rtpReceiver.d.ts +107 -12
  217. package/lib/webrtc/src/media/rtpReceiver.js +255 -28
  218. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  219. package/lib/webrtc/src/media/rtpSender.d.ts +56 -3
  220. package/lib/webrtc/src/media/rtpSender.js +180 -21
  221. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  222. package/lib/webrtc/src/media/rtpTransceiver.d.ts +94 -1
  223. package/lib/webrtc/src/media/rtpTransceiver.js +111 -2
  224. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  225. package/lib/webrtc/src/media/sender/senderBWE.d.ts +2 -1
  226. package/lib/webrtc/src/media/sender/senderBWE.js +22 -10
  227. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  228. package/lib/webrtc/src/media/track.d.ts +1 -1
  229. package/lib/webrtc/src/media/track.js +1 -1
  230. package/lib/webrtc/src/media/track.js.map +1 -1
  231. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +107 -0
  232. package/lib/webrtc/src/negotiation/bundleTopology.js +380 -0
  233. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  234. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  235. package/lib/webrtc/src/negotiation/descriptionValidation.js +261 -0
  236. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  237. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  238. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  239. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  240. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  241. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  242. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  243. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  244. package/lib/webrtc/src/negotiation/negotiationNeeded.js +118 -0
  245. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  246. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  247. package/lib/webrtc/src/negotiation/remoteCandidates.js +344 -0
  248. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  249. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  250. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +398 -0
  251. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  252. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  253. package/lib/webrtc/src/negotiation/transportActivation.js +345 -0
  254. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  255. package/lib/webrtc/src/negotiationTransaction.d.ts +233 -0
  256. package/lib/webrtc/src/negotiationTransaction.js +591 -0
  257. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  258. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  259. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  260. package/lib/webrtc/src/nonstandard/index.js +1 -1
  261. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  262. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  263. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +1 -1
  264. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  265. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  266. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +2 -2
  267. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  268. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  269. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  270. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
  271. package/lib/webrtc/src/nonstandard/userMedia.js +2 -2
  272. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  273. package/lib/webrtc/src/peerConnection.d.ts +132 -237
  274. package/lib/webrtc/src/peerConnection.js +971 -908
  275. package/lib/webrtc/src/peerConnection.js.map +1 -1
  276. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  277. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  278. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  279. package/lib/webrtc/src/polyfill/install.js +1 -1
  280. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  281. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  282. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  283. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  284. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  285. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  286. package/lib/webrtc/src/sctpManager.d.ts +66 -2
  287. package/lib/webrtc/src/sctpManager.js +122 -5
  288. package/lib/webrtc/src/sctpManager.js.map +1 -1
  289. package/lib/webrtc/src/sdp.js.map +1 -1
  290. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  291. package/lib/webrtc/src/sdpManager.js +364 -87
  292. package/lib/webrtc/src/sdpManager.js.map +1 -1
  293. package/lib/webrtc/src/secureTransportManager.d.ts +38 -25
  294. package/lib/webrtc/src/secureTransportManager.js +130 -34
  295. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  296. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  297. package/lib/webrtc/src/transceiverManager.js +264 -104
  298. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  299. package/lib/webrtc/src/transport/dtls.d.ts +11 -2
  300. package/lib/webrtc/src/transport/dtls.js +37 -13
  301. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  302. package/lib/webrtc/src/transport/ice.d.ts +254 -7
  303. package/lib/webrtc/src/transport/ice.js +608 -52
  304. package/lib/webrtc/src/transport/ice.js.map +1 -1
  305. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  306. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  307. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  308. package/lib/webrtc/src/transport/sctp.d.ts +4 -1
  309. package/lib/webrtc/src/transport/sctp.js +83 -17
  310. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  311. package/lib/webrtc/src/utils.d.ts +3 -3
  312. package/lib/webrtc/src/utils.js +1 -1
  313. package/lib/webrtc/src/utils.js.map +1 -1
  314. package/package.json +13 -14
@@ -1,9 +1,10 @@
1
+ import type { PeerConfig } from "../api/peerConfig";
1
2
  import { Event } from "../imports/common";
2
3
  import { type Extensions, type RtcpPacket, type RtpPacket } from "../imports/rtp";
3
- import type { PeerConfig } from "../peerConnection";
4
+ import type { ReceiverNegotiationState } from "../negotiation/internalState";
4
5
  import type { RTCDtlsTransport } from "../transport/dtls";
5
6
  import type { Kind } from "../types/domain";
6
- import type { RTCRtpReceiveParameters } from "./parameters";
7
+ import type { RTCRtpCodecParameters, RTCRtpReceiveParameters } from "./parameters";
7
8
  import { ReceiverTWCC } from "./receiver/receiverTwcc";
8
9
  import { type RTCStats, type RTCStatsReport } from "./stats";
9
10
  import { MediaStreamTrack } from "./track";
@@ -15,6 +16,10 @@ export declare class RTCRtpReceiver {
15
16
  private readonly defaultTrack;
16
17
  private get codecArray();
17
18
  private readonly ssrcByRtx;
19
+ private readonly stagedCodecs;
20
+ private readonly stagedSsrcByRtx;
21
+ /** SSRCs of `trackBySSRC` learned from RID packets rather than SDP. */
22
+ readonly learnedTrackSsrcs: Set<number>;
18
23
  private readonly nack;
19
24
  private readonly audioRedHandler;
20
25
  readonly type = "receiver";
@@ -26,6 +31,12 @@ export declare class RTCRtpReceiver {
26
31
  readonly trackByRID: {
27
32
  [rid: string]: MediaStreamTrack;
28
33
  };
34
+ /**
35
+ * Tracks whose SSRC a later pranswer / answer of the same offer replaced.
36
+ * The next SSRC a description gives this receiver takes one over, so the
37
+ * application keeps receiving on the same track object.
38
+ */
39
+ private unboundTracks;
29
40
  /**last sender Report Timestamp
30
41
  * compactNtp
31
42
  */
@@ -36,7 +47,7 @@ export declare class RTCRtpReceiver {
36
47
  readonly receiveLastSRTimestamp: {
37
48
  [ssrc: number]: number;
38
49
  };
39
- readonly onPacketLost: Event<[import("../imports/rtp").GenericNack]>;
50
+ readonly onPacketLost: Event<[import("..").GenericNack]>;
40
51
  readonly onRtcp: Event<[RtcpPacket]>;
41
52
  dtlsTransport: RTCDtlsTransport;
42
53
  sdesMid?: string;
@@ -56,28 +67,102 @@ export declare class RTCRtpReceiver {
56
67
  private remoteOctetCountBySsrc;
57
68
  private nackCountBySsrc;
58
69
  private pliCountBySsrc;
70
+ /** Media payload type last received on each SSRC (RTX resolved to its media SSRC). */
71
+ private payloadTypeBySsrc;
59
72
  constructor(config: PeerConfig, kind: Kind, rtcpSsrc: number);
60
73
  get transport(): RTCDtlsTransport;
61
74
  setDtlsTransport(dtls: RTCDtlsTransport): void;
62
75
  get track(): MediaStreamTrack;
63
76
  get nackEnabled(): import("./parameters").RTCPFB | undefined;
64
77
  get twccEnabled(): import("./parameters").RTCPFB | undefined;
78
+ /** `a=rtcp-fb:<pt> nack pli` (RFC 4585): a generic `nack` alone does not allow PLI. */
65
79
  get pliEnabled(): import("./parameters").RTCPFB | undefined;
66
- prepareReceive(params: RTCRtpReceiveParameters): void;
67
80
  /**
68
- * negotiated codec と receiver の実処理状態を再同期する。
69
- * codec map と RTX mapping を置換し、既存 remote track の codec
70
- * metadata も新しい先頭 codec に更新する。
71
- * 既存の receiverTWCC は破棄し、新しい codec が transport-cc を持ち
72
- * remote SSRC が分かる場合だけ再生成する。
73
- * setCodecPreferences() 後の createAnswer() 再解決や remote からの
74
- * 再交渉では、除外された payload type の RTP を受け付けないようにする。
81
+ * Receive tables are keyed by payload type and RTX SSRC. With
82
+ * `deferConflicts` (a pending offer or pranswer), a new key applies at once
83
+ * so provisional RTP decodes, but a key the current session already uses
84
+ * with another value is staged: current RTP keeps its codec and RTX pairing
85
+ * until the transaction commits, and rollback drops the staged value.
86
+ */
87
+ prepareReceive(params: RTCRtpReceiveParameters, { deferConflicts }?: {
88
+ deferConflicts?: boolean;
89
+ }): void;
90
+ /**
91
+ * Internal: drop values staged by an earlier remote pranswer. A later
92
+ * pranswer or the final answer replaces that proposal as a whole.
93
+ */
94
+ discardStagedReceive(): void;
95
+ /** Internal: the transaction committed, staged payload types and RTX pairs apply. */
96
+ commitStagedReceive(): void;
97
+ /** Internal: capture the decode tables for a negotiation rollback baseline. */
98
+ snapshotReceiveTables(): {
99
+ codecs: {
100
+ [pt: number]: RTCRtpCodecParameters;
101
+ };
102
+ ssrcByRtx: {
103
+ [rtxSsrc: number]: number;
104
+ };
105
+ stagedCodecs: {
106
+ [pt: number]: RTCRtpCodecParameters;
107
+ };
108
+ stagedSsrcByRtx: {
109
+ [rtxSsrc: number]: number;
110
+ };
111
+ };
112
+ /** Internal: replace the decode tables with a rollback baseline. */
113
+ restoreReceiveTables(snapshot: ReturnType<RTCRtpReceiver["snapshotReceiveTables"]>): void;
114
+ /**
115
+ * Internal: everything a negotiation may change on this receiver, for a
116
+ * rollback baseline. Packet-driven runtime (statistics, NACK, RTCP) is not
117
+ * part of it.
118
+ */
119
+ snapshotNegotiationState(): {
120
+ receiverTWCC: ReceiverTWCC | undefined;
121
+ remoteStreamIds: string[];
122
+ remoteStreamId: string | undefined;
123
+ remoteTrackId: string | undefined;
124
+ tracks: MediaStreamTrack[];
125
+ trackBySSRC: {
126
+ [ssrc: string]: MediaStreamTrack;
127
+ };
128
+ trackByRID: {
129
+ [rid: string]: MediaStreamTrack;
130
+ };
131
+ unboundTracks: MediaStreamTrack[];
132
+ receiveTables: {
133
+ codecs: {
134
+ [pt: number]: RTCRtpCodecParameters;
135
+ };
136
+ ssrcByRtx: {
137
+ [rtxSsrc: number]: number;
138
+ };
139
+ stagedCodecs: {
140
+ [pt: number]: RTCRtpCodecParameters;
141
+ };
142
+ stagedSsrcByRtx: {
143
+ [rtxSsrc: number]: number;
144
+ };
145
+ };
146
+ };
147
+ /** Internal: return to a negotiation baseline taken by `snapshotNegotiationState`. */
148
+ restoreNegotiationState(state: ReceiverNegotiationState): void;
149
+ /**
150
+ * Replace receiver codec state after a negotiated codec preference change.
151
+ * Use only when the transaction commits; pending descriptions stage through
152
+ * prepareReceive() so the current decode path remains available.
75
153
  */
76
154
  resyncCodecs(params: RTCRtpReceiveParameters, mediaSourceSsrc?: number): void;
77
155
  /**
78
156
  * setup TWCC if supported
79
157
  */
80
- setupTWCC(mediaSourceSsrc: number): void;
158
+ setupTWCC(mediaSourceSsrc: number, negotiated?: boolean): void;
159
+ /**
160
+ * Internal: tracks a replaced remote offer gave this receiver stay its
161
+ * tracks; the SSRCs the replacing offer gives take them over.
162
+ */
163
+ keepUnboundTracks(tracks: MediaStreamTrack[]): void;
164
+ /** Internal: a superseded pending description no longer routes `ssrc`. */
165
+ releaseProvisionalSsrc(ssrc: number): void;
81
166
  addTrack(track: MediaStreamTrack): boolean;
82
167
  stop(): void;
83
168
  /**transceiver の停止確定時に remote track を ended にする */
@@ -88,6 +173,16 @@ export declare class RTCRtpReceiver {
88
173
  getStatsRootIds(selector?: MediaStreamTrack): string[];
89
174
  collectStats(timestamp: number): RTCStats[];
90
175
  getStats(): Promise<RTCStatsReport>;
176
+ /**
177
+ * Internal: whether PLI is negotiated for `mediaSsrc`, and the payload type
178
+ * that decides it. PLI follows the negotiated receive codec of this SSRC:
179
+ * the live codec table (current while a proposal is pending, switched at
180
+ * commit and restored on rollback), not the codec its track was created with.
181
+ */
182
+ pliNegotiation(mediaSsrc: number): {
183
+ payloadType: number | undefined;
184
+ allowed: boolean;
185
+ };
91
186
  sendRtcpPLI(mediaSsrc: number): Promise<void>;
92
187
  handleRtcpPacket(packet: RtcpPacket): void;
93
188
  handleRtpBySsrc: (packet: RtpPacket, extensions: Extensions) => void;
@@ -5,13 +5,13 @@ const crypto_1 = require("crypto");
5
5
  const promises_1 = require("timers/promises");
6
6
  const common_1 = require("../imports/common");
7
7
  const rtp_1 = require("../imports/rtp");
8
+ const sdp_1 = require("../sdp");
8
9
  const utils_1 = require("../utils");
9
10
  const codecCompatibility_1 = require("./codecCompatibility");
11
+ const rtcpFeedback_1 = require("./extension/rtcpFeedback");
10
12
  const nack_1 = require("./receiver/nack");
11
13
  const receiverTwcc_1 = require("./receiver/receiverTwcc");
12
14
  const statistics_1 = require("./receiver/statistics");
13
- const sdp_1 = require("../sdp");
14
- const rtcpFeedback_1 = require("./extension/rtcpFeedback");
15
15
  const stats_1 = require("./stats");
16
16
  const track_1 = require("./track");
17
17
  const log = (0, rtp_1.debug)("werift:packages/webrtc/src/media/rtpReceiver.ts");
@@ -56,6 +56,25 @@ class RTCRtpReceiver {
56
56
  writable: true,
57
57
  value: {}
58
58
  });
59
+ Object.defineProperty(this, "stagedCodecs", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: {}
64
+ });
65
+ Object.defineProperty(this, "stagedSsrcByRtx", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: {}
70
+ });
71
+ /** SSRCs of `trackBySSRC` learned from RID packets rather than SDP. */
72
+ Object.defineProperty(this, "learnedTrackSsrcs", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: new Set()
77
+ });
59
78
  Object.defineProperty(this, "nack", {
60
79
  enumerable: true,
61
80
  configurable: true,
@@ -98,6 +117,17 @@ class RTCRtpReceiver {
98
117
  writable: true,
99
118
  value: {}
100
119
  });
120
+ /**
121
+ * Tracks whose SSRC a later pranswer / answer of the same offer replaced.
122
+ * The next SSRC a description gives this receiver takes one over, so the
123
+ * application keeps receiving on the same track object.
124
+ */
125
+ Object.defineProperty(this, "unboundTracks", {
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ value: []
130
+ });
101
131
  /**last sender Report Timestamp
102
132
  * compactNtp
103
133
  */
@@ -234,6 +264,13 @@ class RTCRtpReceiver {
234
264
  writable: true,
235
265
  value: {}
236
266
  });
267
+ /** Media payload type last received on each SSRC (RTX resolved to its media SSRC). */
268
+ Object.defineProperty(this, "payloadTypeBySsrc", {
269
+ enumerable: true,
270
+ configurable: true,
271
+ writable: true,
272
+ value: {}
273
+ });
237
274
  Object.defineProperty(this, "handleRtpBySsrc", {
238
275
  enumerable: true,
239
276
  configurable: true,
@@ -251,6 +288,7 @@ class RTCRtpReceiver {
251
288
  const track = this.trackByRID[rid];
252
289
  if (!this.trackBySSRC[packet.header.ssrc]) {
253
290
  this.trackBySSRC[packet.header.ssrc] = track;
291
+ this.learnedTrackSsrcs.add(packet.header.ssrc);
254
292
  }
255
293
  this.handleRTP(packet, extensions, track);
256
294
  }
@@ -277,57 +315,199 @@ class RTCRtpReceiver {
277
315
  get twccEnabled() {
278
316
  return this.codecArray[0]?.rtcpFeedback.find((f) => f.type === (0, rtcpFeedback_1.useTWCC)().type);
279
317
  }
318
+ /** `a=rtcp-fb:<pt> nack pli` (RFC 4585): a generic `nack` alone does not allow PLI. */
280
319
  get pliEnabled() {
281
- return this.codecArray[0]?.rtcpFeedback.find((f) => f.type === (0, rtcpFeedback_1.usePLI)().type);
320
+ const pli = (0, rtcpFeedback_1.usePLI)();
321
+ return this.codecArray[0]?.rtcpFeedback.find((f) => f.type === pli.type && f.parameter === pli.parameter);
282
322
  }
283
- prepareReceive(params) {
323
+ /**
324
+ * Receive tables are keyed by payload type and RTX SSRC. With
325
+ * `deferConflicts` (a pending offer or pranswer), a new key applies at once
326
+ * so provisional RTP decodes, but a key the current session already uses
327
+ * with another value is staged: current RTP keeps its codec and RTX pairing
328
+ * until the transaction commits, and rollback drops the staged value.
329
+ */
330
+ prepareReceive(params, { deferConflicts = false } = {}) {
284
331
  params.codecs.forEach((c) => {
285
- this.codecs[c.payloadType] = c;
332
+ const existing = this.codecs[c.payloadType];
333
+ if (deferConflicts && existing && !sameCodec(existing, c)) {
334
+ this.stagedCodecs[c.payloadType] = c;
335
+ }
336
+ else {
337
+ // The latest description decides the key: an earlier staged value
338
+ // must not overwrite it at the commit.
339
+ delete this.stagedCodecs[c.payloadType];
340
+ this.codecs[c.payloadType] = c;
341
+ }
286
342
  });
287
343
  params.encodings.forEach((e) => {
288
- if (e.rtx) {
344
+ if (!e.rtx)
345
+ return;
346
+ const existing = this.ssrcByRtx[e.rtx.ssrc];
347
+ if (deferConflicts && existing !== undefined && existing !== e.ssrc) {
348
+ this.stagedSsrcByRtx[e.rtx.ssrc] = e.ssrc;
349
+ }
350
+ else {
351
+ delete this.stagedSsrcByRtx[e.rtx.ssrc];
289
352
  this.ssrcByRtx[e.rtx.ssrc] = e.ssrc;
290
353
  }
291
354
  });
292
355
  }
293
356
  /**
294
- * negotiated codec と receiver の実処理状態を再同期する。
295
- * codec map と RTX mapping を置換し、既存 remote track の codec
296
- * metadata も新しい先頭 codec に更新する。
297
- * 既存の receiverTWCC は破棄し、新しい codec が transport-cc を持ち
298
- * remote SSRC が分かる場合だけ再生成する。
299
- * setCodecPreferences() 後の createAnswer() 再解決や remote からの
300
- * 再交渉では、除外された payload type の RTP を受け付けないようにする。
357
+ * Internal: drop values staged by an earlier remote pranswer. A later
358
+ * pranswer or the final answer replaces that proposal as a whole.
301
359
  */
302
- resyncCodecs(params, mediaSourceSsrc) {
303
- for (const key of Object.keys(this.codecs)) {
304
- delete this.codecs[Number(key)];
360
+ discardStagedReceive() {
361
+ clearTable(this.stagedCodecs);
362
+ clearTable(this.stagedSsrcByRtx);
363
+ }
364
+ /** Internal: the transaction committed, staged payload types and RTX pairs apply. */
365
+ commitStagedReceive() {
366
+ Object.assign(this.codecs, this.stagedCodecs);
367
+ Object.assign(this.ssrcByRtx, this.stagedSsrcByRtx);
368
+ clearTable(this.stagedCodecs);
369
+ clearTable(this.stagedSsrcByRtx);
370
+ }
371
+ /** Internal: capture the decode tables for a negotiation rollback baseline. */
372
+ snapshotReceiveTables() {
373
+ return {
374
+ codecs: { ...this.codecs },
375
+ ssrcByRtx: { ...this.ssrcByRtx },
376
+ stagedCodecs: { ...this.stagedCodecs },
377
+ stagedSsrcByRtx: { ...this.stagedSsrcByRtx },
378
+ };
379
+ }
380
+ /** Internal: replace the decode tables with a rollback baseline. */
381
+ restoreReceiveTables(snapshot) {
382
+ for (const [table, saved] of [
383
+ [this.codecs, snapshot.codecs],
384
+ [this.ssrcByRtx, snapshot.ssrcByRtx],
385
+ [this.stagedCodecs, snapshot.stagedCodecs],
386
+ [this.stagedSsrcByRtx, snapshot.stagedSsrcByRtx],
387
+ ]) {
388
+ clearTable(table);
389
+ Object.assign(table, saved);
305
390
  }
306
- for (const key of Object.keys(this.ssrcByRtx)) {
307
- delete this.ssrcByRtx[Number(key)];
391
+ }
392
+ /**
393
+ * Internal: everything a negotiation may change on this receiver, for a
394
+ * rollback baseline. Packet-driven runtime (statistics, NACK, RTCP) is not
395
+ * part of it.
396
+ */
397
+ snapshotNegotiationState() {
398
+ return {
399
+ receiverTWCC: this.receiverTWCC,
400
+ remoteStreamIds: [...this.remoteStreamIds],
401
+ remoteStreamId: this.remoteStreamId,
402
+ remoteTrackId: this.remoteTrackId,
403
+ tracks: [...this.tracks],
404
+ trackBySSRC: { ...this.trackBySSRC },
405
+ trackByRID: { ...this.trackByRID },
406
+ unboundTracks: [...this.unboundTracks],
407
+ receiveTables: this.snapshotReceiveTables(),
408
+ };
409
+ }
410
+ /** Internal: return to a negotiation baseline taken by `snapshotNegotiationState`. */
411
+ restoreNegotiationState(state) {
412
+ // Transport-cc feedback a pending description started for this receiver
413
+ // stops; the current session's feedback (if any) remains.
414
+ if (this.receiverTWCC !== state.receiverTWCC) {
415
+ if (this.receiverTWCC)
416
+ this.receiverTWCC.twccRunning = false;
417
+ this.receiverTWCC = state.receiverTWCC;
418
+ }
419
+ this.remoteStreamIds = state.remoteStreamIds;
420
+ this.remoteStreamId = state.remoteStreamId;
421
+ this.remoteTrackId = state.remoteTrackId;
422
+ this.tracks.splice(0, this.tracks.length, ...state.tracks);
423
+ // SSRCs learned from RID packets are live state, not SDP: keep those
424
+ // whose track survives the rollback.
425
+ const learnedTracks = Object.entries(this.trackBySSRC).filter(([ssrc, track]) => this.learnedTrackSsrcs.has(Number(ssrc)) &&
426
+ !(ssrc in state.trackBySSRC) &&
427
+ state.tracks.includes(track));
428
+ replaceTable(this.trackBySSRC, state.trackBySSRC);
429
+ for (const [ssrc, track] of learnedTracks) {
430
+ this.trackBySSRC[ssrc] = track;
308
431
  }
432
+ replaceTable(this.trackByRID, state.trackByRID);
433
+ this.unboundTracks = [...state.unboundTracks];
434
+ // A track the rolled-back description rebound gets its SSRC back.
435
+ for (const [ssrc, track] of Object.entries(state.trackBySSRC)) {
436
+ if (!track.rid)
437
+ track.ssrc = Number(ssrc);
438
+ }
439
+ // Codec/RTX tables added or changed by a pending description are
440
+ // dropped; current RTP is decoded exactly as before the transaction.
441
+ this.restoreReceiveTables(state.receiveTables);
442
+ }
443
+ /**
444
+ * Replace receiver codec state after a negotiated codec preference change.
445
+ * Use only when the transaction commits; pending descriptions stage through
446
+ * prepareReceive() so the current decode path remains available.
447
+ */
448
+ resyncCodecs(params, mediaSourceSsrc) {
449
+ // The committed description replaces the tables as a whole: values a
450
+ // pending description staged must not come back at the commit.
451
+ this.discardStagedReceive();
452
+ clearTable(this.codecs);
453
+ clearTable(this.ssrcByRtx);
309
454
  this.prepareReceive(params);
310
455
  const codec = (0, codecCompatibility_1.deliveredTrackCodec)(this.kind, params.codecs[0], params.codecs);
311
456
  if (codec) {
312
- for (const track of this.tracks) {
457
+ for (const track of this.tracks)
313
458
  track.codec = codec;
314
- }
315
459
  }
316
460
  this.receiverTWCC = undefined;
317
- if (mediaSourceSsrc != undefined) {
461
+ if (mediaSourceSsrc != undefined)
318
462
  this.setupTWCC(mediaSourceSsrc);
319
- }
320
463
  }
321
464
  /**
322
465
  * setup TWCC if supported
323
466
  */
324
- setupTWCC(mediaSourceSsrc) {
325
- if (this.twccEnabled && !this.receiverTWCC) {
467
+ setupTWCC(mediaSourceSsrc, negotiated = !!this.twccEnabled) {
468
+ // `negotiated`: a received packet's own codec negotiated transport-cc
469
+ // (whatever codec has the lowest payload type).
470
+ if (negotiated && !this.receiverTWCC) {
326
471
  this.receiverTWCC = new receiverTwcc_1.ReceiverTWCC(this.dtlsTransport, this.rtcpSsrc, mediaSourceSsrc);
327
472
  }
328
473
  }
474
+ /**
475
+ * Internal: tracks a replaced remote offer gave this receiver stay its
476
+ * tracks; the SSRCs the replacing offer gives take them over.
477
+ */
478
+ keepUnboundTracks(tracks) {
479
+ for (const track of tracks) {
480
+ if (track.rid || this.tracks.includes(track))
481
+ continue;
482
+ this.tracks.push(track);
483
+ this.unboundTracks.push(track);
484
+ }
485
+ }
486
+ /** Internal: a superseded pending description no longer routes `ssrc`. */
487
+ releaseProvisionalSsrc(ssrc) {
488
+ const track = this.trackBySSRC[ssrc];
489
+ if (!track || track.rid)
490
+ return;
491
+ delete this.trackBySSRC[ssrc];
492
+ this.unboundTracks.push(track);
493
+ }
329
494
  addTrack(track) {
495
+ if (track.ssrc &&
496
+ !track.rid &&
497
+ !this.trackBySSRC[track.ssrc] &&
498
+ this.unboundTracks.length > 0) {
499
+ const unbound = this.unboundTracks.find((t) => t.ssrc === track.ssrc) ??
500
+ this.unboundTracks[0];
501
+ this.unboundTracks = this.unboundTracks.filter((t) => t !== unbound);
502
+ unbound.ssrc = track.ssrc;
503
+ unbound.codec = track.codec ?? unbound.codec;
504
+ this.trackBySSRC[track.ssrc] = unbound;
505
+ this.learnedTrackSsrcs.delete(track.ssrc);
506
+ return false;
507
+ }
330
508
  const exist = this.tracks.find((t) => {
509
+ if (this.unboundTracks.includes(t))
510
+ return false;
331
511
  if (t.rid) {
332
512
  return t.rid === track.rid;
333
513
  }
@@ -341,6 +521,7 @@ class RTCRtpReceiver {
341
521
  this.tracks.push(track);
342
522
  if (track.ssrc) {
343
523
  this.trackBySSRC[track.ssrc] = track;
524
+ this.learnedTrackSsrcs.delete(track.ssrc);
344
525
  }
345
526
  if (track.rid) {
346
527
  this.trackByRID[track.rid] = track;
@@ -506,8 +687,25 @@ class RTCRtpReceiver {
506
687
  }
507
688
  return (0, stats_1.buildStatsReport)(stats, this.getStatsRootIds());
508
689
  }
690
+ /**
691
+ * Internal: whether PLI is negotiated for `mediaSsrc`, and the payload type
692
+ * that decides it. PLI follows the negotiated receive codec of this SSRC:
693
+ * the live codec table (current while a proposal is pending, switched at
694
+ * commit and restored on rollback), not the codec its track was created with.
695
+ */
696
+ pliNegotiation(mediaSsrc) {
697
+ const payloadType = this.payloadTypeBySsrc[mediaSsrc] ??
698
+ this.trackBySSRC[mediaSsrc]?.codec?.payloadType;
699
+ const codec = payloadType != undefined ? this.codecs[payloadType] : undefined;
700
+ return {
701
+ payloadType: codec ? payloadType : undefined,
702
+ allowed: codec
703
+ ? hasFeedback(codec, (0, rtcpFeedback_1.usePLI)().type, (0, rtcpFeedback_1.usePLI)().parameter)
704
+ : !!this.pliEnabled,
705
+ };
706
+ }
509
707
  async sendRtcpPLI(mediaSsrc) {
510
- if (!this.pliEnabled) {
708
+ if (!this.pliNegotiation(mediaSsrc).allowed) {
511
709
  log("pli not supported", { mediaSsrc });
512
710
  return;
513
711
  }
@@ -571,9 +769,12 @@ class RTCRtpReceiver {
571
769
  }
572
770
  this.receiverTWCC.handleTWCC(transportSequenceNumber);
573
771
  }
574
- else if (this.twccEnabled) {
575
- this.setupTWCC(packet.header.ssrc);
772
+ else if (hasFeedback(codec, (0, rtcpFeedback_1.useTWCC)().type)) {
773
+ this.setupTWCC(packet.header.ssrc, true);
576
774
  }
775
+ // RTCP feedback follows the codec this packet was negotiated with, not
776
+ // whichever payload type happens to sort first in the receive table.
777
+ let mediaCodec = codec;
577
778
  if (codec.name.toLowerCase() === "rtx") {
578
779
  const originalSsrc = this.ssrcByRtx[packet.header.ssrc];
579
780
  const codecParams = (0, sdp_1.codecParametersFromString)(codec.parameters ?? "");
@@ -582,6 +783,7 @@ class RTCRtpReceiver {
582
783
  return;
583
784
  packet = (0, rtp_1.unwrapRtx)(packet, rtxCodec.payloadType, originalSsrc);
584
785
  track = this.trackBySSRC[originalSsrc];
786
+ mediaCodec = rtxCodec;
585
787
  }
586
788
  let red;
587
789
  if (codec.name.toLowerCase() === "red") {
@@ -590,7 +792,8 @@ class RTCRtpReceiver {
590
792
  return;
591
793
  }
592
794
  }
593
- if (track?.kind === "video" && this.nackEnabled) {
795
+ this.payloadTypeBySsrc[packet.header.ssrc] = mediaCodec.payloadType;
796
+ if (track?.kind === "video" && hasFeedback(mediaCodec, "nack")) {
594
797
  this.nack.addPacket(packet);
595
798
  }
596
799
  if (track) {
@@ -612,4 +815,28 @@ class RTCRtpReceiver {
612
815
  }
613
816
  }
614
817
  exports.RTCRtpReceiver = RTCRtpReceiver;
818
+ function clearTable(table) {
819
+ for (const key of Object.keys(table))
820
+ delete table[Number(key)];
821
+ }
822
+ /** Replace the entries of a string-keyed table in place (keys may be RIDs). */
823
+ function replaceTable(table, source) {
824
+ for (const key of Object.keys(table))
825
+ delete table[key];
826
+ Object.assign(table, source);
827
+ }
828
+ const feedbackKey = (codec) => codec.rtcpFeedback
829
+ .map((f) => `${f.type} ${f.parameter ?? ""}`)
830
+ .sort()
831
+ .join(",");
832
+ function sameCodec(a, b) {
833
+ return (a.mimeType.toLowerCase() === b.mimeType.toLowerCase() &&
834
+ a.clockRate === b.clockRate &&
835
+ (a.channels ?? 1) === (b.channels ?? 1) &&
836
+ (a.parameters ?? "") === (b.parameters ?? "") &&
837
+ feedbackKey(a) === feedbackKey(b));
838
+ }
839
+ function hasFeedback(codec, type, parameter) {
840
+ return !!codec?.rtcpFeedback.some((f) => f.type === type && (parameter === undefined || f.parameter === parameter));
841
+ }
615
842
  //# sourceMappingURL=rtpReceiver.js.map