werift 0.15.0 → 0.15.1

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.
@@ -19,6 +19,10 @@ export declare type RTCPFB = {
19
19
  parameter?: string;
20
20
  };
21
21
  export declare class RTCRtpCodecParameters {
22
+ /**
23
+ * When specifying a codec with a fixed payloadType such as PCMU,
24
+ * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.
25
+ */
22
26
  payloadType: number;
23
27
  mimeType: string;
24
28
  clockRate: number;
@@ -1 +1 @@
1
- {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../../src/media/parameters.ts"],"names":[],"mappings":";;;AASA,MAAa,qBAAqB;IAKhC,YAAY,aAA6C,EAAE;QAD3D,eAAU,GAAG,EAAE,CAAC;QAEd,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;CACF;AAZD,sDAYC;AAID,MAAa,qBAAqB;IAQhC,YACE,KACgC;QALlC,iBAAY,GAAa,EAAE,CAAC;QAO1B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,GAAG;QACL,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC;YAAE,CAAC,IAAI,IAAI,CAAC;QACnC,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAxBD,sDAwBC;AAED,MAAa,+BAA+B;IAI1C,YACE,KAC8C;QAE9C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAVD,0EAUC;AAED,MAAa,iBAAiB;IAK5B,YAAY,QAAoC,EAAE;QAHlD,QAAG,GAAY,KAAK,CAAC;QAInB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AARD,8CAQC;AAED,MAAa,eAAe;IAI1B,YAAY,QAAkC,EAAE;QAC9C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAPD,0CAOC;AACD,MAAa,mBAAmB;IAG9B,YAAY,QAAsC,EAAE;QAClD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAND,kDAMC;AAED,MAAa,sBAAsB;IAKjC,YACE,KACsD;QAEtD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAXD,wDAWC;AAQD,MAAa,yBAAyB;IAGpC,YAAY,KAAgC;QAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAND,8DAMC","sourcesContent":["export interface RTCRtpParameters {\n codecs: RTCRtpCodecParameters[];\n headerExtensions: RTCRtpHeaderExtensionParameters[];\n muxId?: string;\n rtpStreamId?: string;\n repairedRtpStreamId?: string;\n rtcp?: RTCRtcpParameters;\n}\n\nexport class RTCRtpCodecCapability {\n mimeType!: string;\n clockRate!: number;\n channels?: number;\n parameters = {};\n constructor(parameters: Partial<RTCRtpCodecCapability> = {}) {\n Object.assign(this, parameters);\n }\n\n get name() {\n return this.mimeType.split(\"/\")[1];\n }\n}\n\nexport type RTCPFB = { type: string; parameter?: string };\n\nexport class RTCRtpCodecParameters {\n payloadType!: number;\n mimeType!: string;\n clockRate!: number;\n channels?: number;\n rtcpFeedback: RTCPFB[] = [];\n parameters?: string;\n\n constructor(\n props: Pick<RTCRtpCodecParameters, \"mimeType\" | \"clockRate\"> &\n Partial<RTCRtpCodecParameters>\n ) {\n Object.assign(this, props);\n }\n\n get name() {\n return this.mimeType.split(\"/\")[1];\n }\n\n get str() {\n let s = `${this.name}/${this.clockRate}`;\n if (this.channels === 2) s += \"/2\";\n return s;\n }\n}\n\nexport class RTCRtpHeaderExtensionParameters {\n id!: number;\n uri!: string;\n\n constructor(\n props: Partial<RTCRtpHeaderExtensionParameters> &\n Pick<RTCRtpHeaderExtensionParameters, \"uri\">\n ) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtcpParameters {\n cname?: string;\n mux: boolean = false;\n ssrc?: number;\n\n constructor(props: Partial<RTCRtcpParameters> = {}) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtcpFeedback {\n type!: string;\n parameter?: string;\n\n constructor(props: Partial<RTCRtcpFeedback> = {}) {\n Object.assign(this, props);\n }\n}\nexport class RTCRtpRtxParameters {\n ssrc!: number;\n\n constructor(props: Partial<RTCRtpRtxParameters> = {}) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtpCodingParameters {\n ssrc!: number;\n payloadType!: number;\n rtx?: RTCRtpRtxParameters;\n\n constructor(\n props: Partial<RTCRtpCodingParameters> &\n Pick<RTCRtpCodingParameters, \"ssrc\" | \"payloadType\">\n ) {\n Object.assign(this, props);\n }\n}\n\nexport interface RTCRtpReceiveParameters extends RTCRtpParameters {\n encodings: RTCRtpCodingParameters[];\n}\n\nexport interface RTCRtpSendParameters extends RTCRtpParameters {}\n\nexport class RTCRtpSimulcastParameters {\n rid!: string;\n direction!: \"send\" | \"recv\";\n constructor(props: RTCRtpSimulcastParameters) {\n Object.assign(this, props);\n }\n}\n"]}
1
+ {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../../src/media/parameters.ts"],"names":[],"mappings":";;;AASA,MAAa,qBAAqB;IAKhC,YAAY,aAA6C,EAAE;QAD3D,eAAU,GAA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AAC,CAAC;IAC7B,CAAC;CACF;AAND,kDAMC;AAED,MAAa,sBAAsB;IAKjC,YACE,KACsD;QAEtD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAXD,wDAWC;AAQD,MAAa,yBAAyB;IAGpC,YAAY,KAAgC;QAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AAND,8DAMC","sourcesContent":["export interface RTCRtpParameters {\n codecs: RTCRtpCodecParameters[];\n headerExtensions: RTCRtpHeaderExtensionParameters[];\n muxId?: string;\n rtpStreamId?: string;\n repairedRtpStreamId?: string;\n rtcp?: RTCRtcpParameters;\n}\n\nexport class RTCRtpCodecCapability {\n mimeType!: string;\n clockRate!: number;\n channels?: number;\n parameters = {};\n constructor(parameters: Partial<RTCRtpCodecCapability> = {}) {\n Object.assign(this, parameters);\n }\n\n get name() {\n return this.mimeType.split(\"/\")[1];\n }\n}\n\nexport type RTCPFB = { type: string; parameter?: string };\n\nexport class RTCRtpCodecParameters {\n /**\n * When specifying a codec with a fixed payloadType such as PCMU,\n * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.\n */\n payloadType!: number;\n mimeType!: string;\n clockRate!: number;\n channels?: number;\n rtcpFeedback: RTCPFB[] = [];\n parameters?: string;\n\n constructor(\n props: Pick<RTCRtpCodecParameters, \"mimeType\" | \"clockRate\"> &\n Partial<RTCRtpCodecParameters>\n ) {\n Object.assign(this, props);\n }\n\n get name() {\n return this.mimeType.split(\"/\")[1];\n }\n\n get str() {\n let s = `${this.name}/${this.clockRate}`;\n if (this.channels === 2) s += \"/2\";\n return s;\n }\n}\n\nexport class RTCRtpHeaderExtensionParameters {\n id!: number;\n uri!: string;\n\n constructor(\n props: Partial<RTCRtpHeaderExtensionParameters> &\n Pick<RTCRtpHeaderExtensionParameters, \"uri\">\n ) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtcpParameters {\n cname?: string;\n mux: boolean = false;\n ssrc?: number;\n\n constructor(props: Partial<RTCRtcpParameters> = {}) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtcpFeedback {\n type!: string;\n parameter?: string;\n\n constructor(props: Partial<RTCRtcpFeedback> = {}) {\n Object.assign(this, props);\n }\n}\nexport class RTCRtpRtxParameters {\n ssrc!: number;\n\n constructor(props: Partial<RTCRtpRtxParameters> = {}) {\n Object.assign(this, props);\n }\n}\n\nexport class RTCRtpCodingParameters {\n ssrc!: number;\n payloadType!: number;\n rtx?: RTCRtpRtxParameters;\n\n constructor(\n props: Partial<RTCRtpCodingParameters> &\n Pick<RTCRtpCodingParameters, \"ssrc\" | \"payloadType\">\n ) {\n Object.assign(this, props);\n }\n}\n\nexport interface RTCRtpReceiveParameters extends RTCRtpParameters {\n encodings: RTCRtpCodingParameters[];\n}\n\nexport interface RTCRtpSendParameters extends RTCRtpParameters {}\n\nexport class RTCRtpSimulcastParameters {\n rid!: string;\n direction!: \"send\" | \"recv\";\n constructor(props: RTCRtpSimulcastParameters) {\n Object.assign(this, props);\n }\n}\n"]}
@@ -112,6 +112,10 @@ export declare function allocateMid(mids: Set<string>): string;
112
112
  export declare type BundlePolicy = "max-compat" | "max-bundle" | "disable";
113
113
  export interface PeerConfig {
114
114
  codecs: Partial<{
115
+ /**
116
+ * When specifying a codec with a fixed payloadType such as PCMU,
117
+ * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.
118
+ */
115
119
  audio: RTCRtpCodecParameters[];
116
120
  video: RTCRtpCodecParameters[];
117
121
  }>;
@@ -102,6 +102,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
102
102
  ...(this.configuration.codecs.audio || []),
103
103
  ...(this.configuration.codecs.video || []),
104
104
  ])) {
105
+ if (codecParams.payloadType != undefined) {
106
+ continue;
107
+ }
105
108
  codecParams.payloadType = 96 + i;
106
109
  switch (codecParams.name.toLowerCase()) {
107
110
  case "rtx":
@@ -1082,6 +1085,7 @@ exports.defaultPeerConfig = {
1082
1085
  mimeType: "audio/PCMU",
1083
1086
  clockRate: 8000,
1084
1087
  channels: 1,
1088
+ payloadType: 0,
1085
1089
  }),
1086
1090
  ],
1087
1091
  video: [
@@ -1 +1 @@
1
- {"version":3,"file":"peerConnection.js","sourceRoot":"","sources":["../../../src/peerConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,iEAAyC;AACzC,6DAAqC;AACrC,sDAA4B;AAC5B,2CAA6B;AAG7B,wBAAwD;AACxD,mCAKiB;AACjB,+CAAyE;AACzE,qCAAkD;AAClD,mDAQ4B;AAC5B,2CAA2C;AAC3C,qDAAqD;AACrD,iDAAiD;AACjD,2DAIgC;AAChC,yCAA8D;AAC9D,+BAMe;AACf,2CAAoE;AACpE,yCAOyB;AACzB,2CAAoD;AAGpD,mCAKiB;AAEjB,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,8CAA8C,CAAC,CAAC;AAElE,MAAa,iBAAkB,SAAQ,oBAAW;IAyDhD,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,IAAI,EACJ,YAAY,MACW,EAAE;QACzB,KAAK,EAAE,CAAC;QAjED,UAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAE3B,+BAA0B,GAAG,KAAK,CAAC;QACnC,kBAAa,GACX,IAAA,mBAAS,EAAa,yBAAiB,CAAC,CAAC;QAC3C,oBAAe,GAAoB,KAAK,CAAC;QACzC,uBAAkB,GAA0B,KAAK,CAAC;QAClD,sBAAiB,GAAqB,KAAK,CAAC;QAC5C,mBAAc,GAAsB,QAAQ,CAAC;QAC7C,sBAAiB,GAAG,KAAK,CAAC;QACjB,iBAAY,GAAwB,EAAE,CAAC;QAEvC,4BAAuB,GAAG,IAAI,iBAAK,EAAsB,CAAC;QAC1D,6BAAwB,GAAG,IAAI,iBAAK,EAA2B,CAAC;QAChE,yBAA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F,IAAI,kCAAqB,CAAC;gBACxB,QAAQ,EAAE,YAAY;gBACtB,SAAS,EAAE,IAAI;gBACf,QAAQ,EAAE,CAAC;aACZ,CAAC;SACH;QACD,KAAK,EAAE;YACL,IAAI,kCAAqB,CAAC;gBACxB,QAAQ,EAAE,WAAW;gBACrB,SAAS,EAAE,KAAK;gBAChB,YAAY,EAAE;oBACZ,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;oBACjC,EAAE,IAAI,EAAE,MAAM,EAAE;oBAChB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE;oBAClC,EAAE,IAAI,EAAE,WAAW,EAAE;iBACtB;aACF,CAAC;SACH;KACF;IACD,gBAAgB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IAC1C,kBAAkB,EAAE,KAAK;IACzB,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC;IACtD,YAAY,EAAE,SAAS;IACvB,IAAI,EAAE,EAAE;IACR,YAAY,EAAE,YAAY;CAC3B,CAAC","sourcesContent":["import debug from \"debug\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\nimport Event from \"rx.mini\";\nimport * as uuid from \"uuid\";\n\nimport { Profile } from \"../../dtls/src/context/srtp\";\nimport { codecParametersFromString, DtlsKeys } from \".\";\nimport {\n DISCARD_HOST,\n DISCARD_PORT,\n SenderDirections,\n SRTP_PROFILE,\n} from \"./const\";\nimport { RTCDataChannel, RTCDataChannelParameters } from \"./dataChannel\";\nimport { enumerate, EventTarget } from \"./helper\";\nimport {\n RTCRtpCodecParameters,\n RTCRtpCodingParameters,\n RTCRtpHeaderExtensionParameters,\n RTCRtpParameters,\n RTCRtpReceiveParameters,\n RTCRtpRtxParameters,\n RTCRtpSimulcastParameters,\n} from \"./media/parameters\";\nimport { RtpRouter } from \"./media/router\";\nimport { RTCRtpReceiver } from \"./media/rtpReceiver\";\nimport { RTCRtpSender } from \"./media/rtpSender\";\nimport {\n Direction,\n RTCRtpTransceiver,\n TransceiverOptions,\n} from \"./media/rtpTransceiver\";\nimport { MediaStream, MediaStreamTrack } from \"./media/track\";\nimport {\n addSDPHeader,\n GroupDescription,\n MediaDescription,\n SessionDescription,\n SsrcDescription,\n} from \"./sdp\";\nimport { RTCCertificate, RTCDtlsTransport } from \"./transport/dtls\";\nimport {\n IceCandidate,\n IceGathererState,\n RTCIceCandidate,\n RTCIceConnectionState,\n RTCIceGatherer,\n RTCIceTransport,\n} from \"./transport/ice\";\nimport { RTCSctpTransport } from \"./transport/sctp\";\nimport { ConnectionState, Kind, RTCSignalingState } from \"./types/domain\";\nimport { Callback, CallbackWithValue } from \"./types/util\";\nimport {\n andDirection,\n parseIceServers,\n reverseDirection,\n reverseSimulcastDirection,\n} from \"./utils\";\n\nconst log = debug(\"werift:packages/webrtc/src/peerConnection.ts\");\n\nexport class RTCPeerConnection extends EventTarget {\n readonly cname = uuid.v4();\n sctpTransport?: RTCSctpTransport;\n masterTransportEstablished = false;\n configuration: Required<PeerConfig> =\n cloneDeep<PeerConfig>(defaultPeerConfig);\n connectionState: ConnectionState = \"new\";\n iceConnectionState: RTCIceConnectionState = \"new\";\n iceGatheringState: IceGathererState = \"new\";\n signalingState: RTCSignalingState = \"stable\";\n negotiationneeded = false;\n readonly transceivers: RTCRtpTransceiver[] = [];\n\n readonly iceGatheringStateChange = new Event<[IceGathererState]>();\n readonly iceConnectionStateChange = new Event<[RTCIceConnectionState]>();\n readonly signalingStateChange = new Event<[RTCSignalingState]>();\n readonly connectionStateChange = new Event<[ConnectionState]>();\n readonly onDataChannel = new Event<[RTCDataChannel]>();\n readonly onRemoteTransceiverAdded = new Event<[RTCRtpTransceiver]>();\n readonly onTransceiverAdded = new Event<[RTCRtpTransceiver]>();\n readonly onIceCandidate = new Event<[RTCIceCandidate]>();\n readonly onNegotiationneeded = new Event<[]>();\n\n ondatachannel?: CallbackWithValue<RTCDataChannelEvent>;\n onicecandidate?: CallbackWithValue<RTCPeerConnectionIceEvent>;\n onnegotiationneeded?: CallbackWithValue<any>;\n onsignalingstatechange?: CallbackWithValue<any>;\n ontrack?: CallbackWithValue<RTCTrackEvent>;\n onconnectionstatechange?: Callback;\n\n private readonly router = new RtpRouter();\n private readonly certificates: RTCCertificate[] = [];\n sctpRemotePort?: number;\n private seenMid = new Set<string>();\n private currentLocalDescription?: SessionDescription;\n private currentRemoteDescription?: SessionDescription;\n private pendingLocalDescription?: SessionDescription;\n private pendingRemoteDescription?: SessionDescription;\n private isClosed = false;\n private shouldNegotiationneeded = false;\n\n get dtlsTransports() {\n const transports = this.transceivers.map((t) => t.dtlsTransport);\n if (this.sctpTransport) {\n transports.push(this.sctpTransport.dtlsTransport);\n }\n return transports.reduce((acc: RTCDtlsTransport[], cur) => {\n if (!acc.map((d) => d.id).includes(cur.id)) {\n acc.push(cur);\n }\n return acc;\n }, []);\n }\n get iceTransports() {\n return this.dtlsTransports.map((d) => d.iceTransport);\n }\n\n constructor({\n codecs,\n headerExtensions,\n iceServers,\n iceTransportPolicy,\n icePortRange,\n dtls,\n bundlePolicy,\n }: Partial<PeerConfig> = {}) {\n super();\n\n if (iceServers) this.configuration.iceServers = iceServers;\n if (iceTransportPolicy)\n this.configuration.iceTransportPolicy = iceTransportPolicy;\n if (icePortRange) {\n const [min, max] = icePortRange;\n if (min === max) throw new Error(\"should not be same value\");\n if (min >= max) throw new Error(\"The min must be less than max\");\n this.configuration.icePortRange = icePortRange;\n }\n if (codecs?.audio) this.configuration.codecs.audio = codecs.audio;\n if (codecs?.video) this.configuration.codecs.video = codecs.video;\n\n for (const [i, codecParams] of enumerate([\n ...(this.configuration.codecs.audio || []),\n ...(this.configuration.codecs.video || []),\n ])) {\n codecParams.payloadType = 96 + i;\n switch (codecParams.name.toLowerCase()) {\n case \"rtx\":\n {\n codecParams.parameters = `apt=${codecParams.payloadType - 1}`;\n }\n break;\n case \"red\":\n {\n const redundant = codecParams.payloadType + 1;\n codecParams.parameters = `${redundant}/${redundant}`;\n codecParams.payloadType = 63;\n }\n break;\n }\n }\n\n if (headerExtensions?.audio)\n this.configuration.headerExtensions.audio = headerExtensions.audio;\n if (headerExtensions?.video)\n this.configuration.headerExtensions.video = headerExtensions.video;\n [\n ...(this.configuration.headerExtensions.audio || []),\n ...(this.configuration.headerExtensions.video || []),\n ].forEach((v, i) => {\n v.id = 1 + i;\n });\n\n if (dtls) {\n const { keys } = dtls;\n if (keys) {\n this.certificates.push(\n new RTCCertificate(keys.keyPem, keys.certPem, keys.signatureHash)\n );\n }\n }\n\n this.iceConnectionStateChange.subscribe((state) => {\n switch (state) {\n case \"disconnected\":\n this.setConnectionState(\"disconnected\");\n break;\n case \"closed\":\n this.close();\n break;\n }\n });\n if (bundlePolicy) {\n this.configuration.bundlePolicy = bundlePolicy;\n }\n }\n\n get localDescription() {\n if (!this._localDescription) return;\n return this._localDescription.toJSON();\n }\n\n get remoteDescription() {\n if (!this._remoteDescription) return;\n return this._remoteDescription.toJSON();\n }\n\n private get _localDescription() {\n return this.pendingLocalDescription || this.currentLocalDescription;\n }\n\n private get _remoteDescription() {\n return this.pendingRemoteDescription || this.currentRemoteDescription;\n }\n\n private getTransceiverByMid(mid: string) {\n return this.transceivers.find((transceiver) => transceiver.mid === mid);\n }\n\n private getTransceiverByMLineIndex(index: number) {\n return this.transceivers.find(\n (transceiver) => transceiver.mLineIndex === index\n );\n }\n\n async createOffer() {\n await this.ensureCerts();\n\n this.transceivers.forEach((transceiver) => {\n transceiver.codecs = this.configuration.codecs[transceiver.kind];\n transceiver.headerExtensions =\n this.configuration.headerExtensions[transceiver.kind];\n });\n\n const description = new SessionDescription();\n addSDPHeader(\"offer\", description);\n\n // # handle existing transceivers / sctp\n\n const currentMedia = this._localDescription\n ? this._localDescription.media\n : [];\n\n currentMedia.forEach((m, i) => {\n const mid = m.rtp.muxId;\n if (!mid) {\n log(\"mid missing\", m);\n return;\n }\n if (m.kind === \"application\") {\n description.media.push(\n createMediaDescriptionForSctp(this.sctpTransport!, mid)\n );\n } else {\n const transceiver = this.getTransceiverByMid(mid);\n if (!transceiver) {\n log(\"transceiver by mid not found\", mid);\n return;\n }\n transceiver.mLineIndex = i;\n description.media.push(\n createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n transceiver.direction,\n mid\n )\n );\n }\n });\n\n // # handle new transceivers / sctp\n this.transceivers\n .filter((t) => !description.media.find((m) => m.rtp.muxId === t.mid))\n .forEach((transceiver) => {\n transceiver.mLineIndex = description.media.length;\n description.media.push(\n createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n transceiver.direction,\n allocateMid(this.seenMid)\n )\n );\n });\n\n if (\n this.sctpTransport &&\n !description.media.find((m) => this.sctpTransport!.mid === m.rtp.muxId)\n ) {\n description.media.push(\n createMediaDescriptionForSctp(\n this.sctpTransport,\n allocateMid(this.seenMid)\n )\n );\n }\n\n if (this.configuration.bundlePolicy !== \"disable\") {\n const mids = description.media\n .map((m) => m.rtp.muxId)\n .filter((v) => v) as string[];\n const bundle = new GroupDescription(\"BUNDLE\", mids);\n description.group.push(bundle);\n }\n\n return description.toJSON();\n }\n\n createDataChannel(\n label: string,\n options: Partial<{\n maxPacketLifeTime?: number;\n protocol: string;\n maxRetransmits?: number;\n ordered: boolean;\n negotiated: boolean;\n id?: number;\n }> = {}\n ): RTCDataChannel {\n const base: typeof options = {\n protocol: \"\",\n ordered: true,\n negotiated: false,\n };\n const settings: Required<typeof base> = { ...base, ...options } as any;\n\n if (settings.maxPacketLifeTime && settings.maxRetransmits) {\n throw new Error(\"can not select both\");\n }\n\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n this.needNegotiation();\n }\n\n const parameters = new RTCDataChannelParameters({\n id: settings.id,\n label,\n maxPacketLifeTime: settings.maxPacketLifeTime,\n maxRetransmits: settings.maxRetransmits,\n negotiated: settings.negotiated,\n ordered: settings.ordered,\n protocol: settings.protocol,\n });\n\n const channel = new RTCDataChannel(this.sctpTransport, parameters);\n return channel;\n }\n\n removeTrack(sender: RTCRtpSender) {\n if (this.isClosed) throw new Error(\"peer closed\");\n if (!this.getSenders().find(({ ssrc }) => sender.ssrc === ssrc))\n throw new Error(\"unExist\");\n\n const transceiver = this.transceivers.find(\n ({ sender: { ssrc } }) => sender.ssrc === ssrc\n );\n if (!transceiver) throw new Error(\"unExist\");\n\n sender.stop();\n\n if (transceiver.currentDirection === \"recvonly\") {\n this.needNegotiation();\n return;\n }\n\n if (transceiver.direction === \"sendrecv\") {\n transceiver.direction = \"recvonly\";\n } else if (\n transceiver.direction === \"sendonly\" ||\n transceiver.direction === \"recvonly\"\n ) {\n transceiver.direction = \"inactive\";\n }\n this.needNegotiation();\n }\n\n private needNegotiation = async () => {\n this.shouldNegotiationneeded = true;\n if (this.negotiationneeded || this.signalingState !== \"stable\") return;\n this.shouldNegotiationneeded = false;\n setImmediate(() => {\n this.negotiationneeded = true;\n this.onNegotiationneeded.execute();\n if (this.onnegotiationneeded) this.onnegotiationneeded({});\n });\n };\n\n private createTransport(srtpProfiles: Profile[] = []) {\n const [existing] = this.iceTransports;\n\n // Gather ICE candidates for only one track. If the remote endpoint is not bundle-aware, negotiate only one media track.\n // https://w3c.github.io/webrtc-pc/#rtcbundlepolicy-enum\n if (this.configuration.bundlePolicy === \"max-bundle\") {\n if (existing) {\n return this.dtlsTransports[0];\n }\n }\n\n const iceGatherer = new RTCIceGatherer({\n ...parseIceServers(this.configuration.iceServers),\n forceTurn: this.configuration.iceTransportPolicy === \"relay\",\n portRange: this.configuration.icePortRange,\n });\n if (existing) {\n iceGatherer.connection.localUserName = existing.connection.localUserName;\n iceGatherer.connection.localPassword = existing.connection.localPassword;\n }\n iceGatherer.onGatheringStateChange.subscribe(() => {\n this.updateIceGatheringState();\n });\n this.updateIceGatheringState();\n const iceTransport = new RTCIceTransport(iceGatherer);\n iceTransport.onStateChange.subscribe(() => {\n this.updateIceConnectionState();\n });\n\n iceTransport.iceGather.onIceCandidate = (candidate) => {\n if (!this.localDescription) return;\n const sdp = SessionDescription.parse(this.localDescription.sdp);\n const media = sdp.media[0];\n if (!media) {\n log(\"media not exist\");\n return;\n }\n candidate.sdpMLineIndex = 0;\n candidate.sdpMid = media.rtp.muxId;\n candidate.foundation = \"candidate:\" + candidate.foundation;\n\n this.onIceCandidate.execute(candidate.toJSON());\n if (this.onicecandidate)\n this.onicecandidate({ candidate: candidate.toJSON() });\n this.emit(\"icecandidate\", { candidate });\n };\n\n const dtlsTransport = new RTCDtlsTransport(\n iceTransport,\n this.router,\n this.certificates,\n srtpProfiles\n );\n\n return dtlsTransport;\n }\n\n private createSctpTransport() {\n const dtlsTransport = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n const sctp = new RTCSctpTransport();\n sctp.setDtlsTransport(dtlsTransport);\n sctp.mid = undefined;\n\n sctp.onDataChannel.subscribe((channel) => {\n this.onDataChannel.execute(channel);\n\n const event: RTCDataChannelEvent = { channel };\n if (this.ondatachannel) this.ondatachannel(event);\n this.emit(\"datachannel\", event);\n });\n\n this.sctpTransport = sctp;\n this.updateIceConnectionState();\n\n return sctp;\n }\n\n async setLocalDescription(sessionDescription: {\n type: \"offer\" | \"answer\";\n sdp: string;\n }): Promise<SessionDescription> {\n // # parse and validate description\n const description = SessionDescription.parse(sessionDescription.sdp);\n description.type = sessionDescription.type;\n this.validateDescription(description, true);\n\n // # update signaling state\n if (description.type === \"offer\") {\n this.setSignalingState(\"have-local-offer\");\n } else if (description.type === \"answer\") {\n this.setSignalingState(\"stable\");\n }\n\n // # assign MID\n description.media.forEach((media, i) => {\n const mid = media.rtp.muxId!;\n this.seenMid.add(mid);\n if ([\"audio\", \"video\"].includes(media.kind)) {\n const transceiver = this.getTransceiverByMLineIndex(i);\n if (transceiver) {\n transceiver.mid = mid;\n }\n }\n if (media.kind === \"application\" && this.sctpTransport) {\n this.sctpTransport.mid = mid;\n }\n });\n\n const setupRole = (dtlsTransport: RTCDtlsTransport) => {\n const iceTransport = dtlsTransport.iceTransport;\n\n // # set ICE role\n if (description.type === \"offer\") {\n iceTransport.connection.iceControlling = true;\n } else {\n iceTransport.connection.iceControlling = false;\n }\n // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role\n // RFC 8445 S6.1.1\n if (iceTransport.connection.remoteIsLite) {\n iceTransport.connection.iceControlling = true;\n }\n\n // # set DTLS role for mediasoup\n if (description.type === \"answer\") {\n const role = description.media.find((media) => media.dtlsParams)\n ?.dtlsParams?.role;\n if (role) {\n dtlsTransport.role = role;\n }\n }\n };\n this.dtlsTransports.forEach((d) => setupRole(d));\n\n // # configure direction\n this.transceivers.forEach((t) => {\n if ([\"answer\", \"pranswer\"].includes(description.type)) {\n const direction = andDirection(t.direction, t.offerDirection);\n t.currentDirection = direction;\n }\n });\n\n // for trickle ice\n this.setLocal(description);\n\n // # gather candidates\n for (const iceTransport of this.iceTransports) {\n await iceTransport.iceGather.gather();\n }\n description.media\n .filter((m) => [\"audio\", \"video\"].includes(m.kind))\n .forEach((m, i) => {\n addTransportDescription(m, this.transceivers[i].dtlsTransport);\n });\n const sctpMedia = description.media.find((m) => m.kind === \"application\");\n if (this.sctpTransport && sctpMedia) {\n addTransportDescription(sctpMedia, this.sctpTransport.dtlsTransport);\n }\n\n this.setLocal(description);\n\n // connect transports\n if (description.type === \"answer\") {\n log(\"callee start connect\");\n this.connect().catch((err) => {\n log(\"connect failed\", err);\n this.setConnectionState(\"failed\");\n });\n }\n\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\n }\n\n return description;\n }\n\n private setLocal(description: SessionDescription) {\n if (description.type === \"answer\") {\n this.currentLocalDescription = description;\n this.pendingLocalDescription = undefined;\n } else {\n this.pendingLocalDescription = description;\n }\n }\n\n async addIceCandidate(candidateMessage: RTCIceCandidate) {\n const candidate = IceCandidate.fromJSON(candidateMessage);\n for (const iceTransport of this.iceTransports) {\n await iceTransport.addRemoteCandidate(candidate);\n }\n }\n\n private async connect() {\n if (this.masterTransportEstablished) return;\n\n this.setConnectionState(\"connecting\");\n\n await Promise.all(\n this.dtlsTransports.map(async (dtlsTransport) => {\n const { iceTransport } = dtlsTransport;\n await iceTransport.start().catch((err) => {\n log(\"iceTransport.start failed\", err);\n throw err;\n });\n await dtlsTransport.start().catch((err) => {\n log(\"dtlsTransport.start failed\", err);\n throw err;\n });\n if (\n this.sctpTransport &&\n this.sctpRemotePort &&\n this.sctpTransport.dtlsTransport.id === dtlsTransport.id\n ) {\n await this.sctpTransport.start(this.sctpRemotePort);\n await this.sctpTransport.sctp.stateChanged.connected.asPromise();\n log(\"sctp connected\");\n }\n })\n );\n\n this.masterTransportEstablished = true;\n this.setConnectionState(\"connected\");\n }\n\n private getLocalRtpParams(transceiver: RTCRtpTransceiver): RTCRtpParameters {\n if (transceiver.mid == undefined) throw new Error(\"mid not assigned\");\n\n const rtp: RTCRtpParameters = {\n codecs: transceiver.codecs,\n muxId: transceiver.mid,\n headerExtensions: transceiver.headerExtensions,\n rtcp: { cname: this.cname, ssrc: transceiver.sender.ssrc, mux: true },\n };\n return rtp;\n }\n\n private getRemoteRtpParams(\n media: MediaDescription,\n transceiver: RTCRtpTransceiver\n ): RTCRtpReceiveParameters {\n const receiveParameters: RTCRtpReceiveParameters = {\n muxId: media.rtp.muxId,\n rtcp: media.rtp.rtcp,\n codecs: transceiver.codecs,\n headerExtensions: transceiver.headerExtensions,\n encodings: Object.values(\n transceiver.codecs.reduce(\n (acc: { [pt: number]: RTCRtpCodingParameters }, codec) => {\n if (codec.name.toLowerCase() === \"rtx\") {\n const params = codecParametersFromString(codec.parameters ?? \"\");\n const apt = acc[params[\"apt\"]];\n if (apt && media.ssrc.length === 2) {\n apt.rtx = new RTCRtpRtxParameters({ ssrc: media.ssrc[1].ssrc });\n }\n return acc;\n }\n acc[codec.payloadType] = new RTCRtpCodingParameters({\n ssrc: media.ssrc[0]?.ssrc,\n payloadType: codec.payloadType,\n });\n return acc;\n },\n {}\n )\n ),\n };\n\n return receiveParameters;\n }\n\n async setRemoteDescription(sessionDescription: {\n type: \"offer\" | \"answer\";\n sdp: string;\n }) {\n // # parse and validate description\n const remoteSdp = SessionDescription.parse(sessionDescription.sdp);\n remoteSdp.type = sessionDescription.type;\n this.validateDescription(remoteSdp, false);\n\n if (remoteSdp.type === \"answer\") {\n this.currentRemoteDescription = remoteSdp;\n this.pendingRemoteDescription = undefined;\n } else {\n this.pendingRemoteDescription = remoteSdp;\n }\n\n const bundle = remoteSdp.group.find(\n (g) =>\n g.semantic === \"BUNDLE\" && this.configuration.bundlePolicy !== \"disable\"\n );\n let bundleTransport: RTCDtlsTransport | undefined;\n\n // # apply description\n await Promise.all(\n enumerate(remoteSdp.media).map(async ([i, remoteMedia]) => {\n let dtlsTransport: RTCDtlsTransport | undefined;\n\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n let transceiver = this.transceivers.find(\n (t) =>\n t.kind === remoteMedia.kind &&\n [undefined, remoteMedia.rtp.muxId].includes(t.mid)\n );\n if (!transceiver) {\n // create remote transceiver\n transceiver = this.addTransceiver(remoteMedia.kind, {\n direction: \"recvonly\",\n });\n this.onRemoteTransceiverAdded.execute(transceiver);\n }\n\n if (bundle) {\n if (!bundleTransport) {\n bundleTransport = transceiver.dtlsTransport;\n } else {\n transceiver.setDtlsTransport(bundleTransport);\n }\n }\n\n dtlsTransport = transceiver.dtlsTransport;\n\n this.setRemoteRTP(transceiver, remoteMedia, remoteSdp.type, i);\n } else if (remoteMedia.kind === \"application\") {\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n }\n\n if (bundle) {\n if (!bundleTransport) {\n bundleTransport = this.sctpTransport.dtlsTransport;\n } else {\n this.sctpTransport.setDtlsTransport(bundleTransport);\n }\n }\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n\n this.setRemoteSCTP(remoteMedia, this.sctpTransport);\n } else {\n throw new Error(\"invalid media kind\");\n }\n\n const iceTransport = dtlsTransport.iceTransport;\n\n if (remoteMedia.iceParams && remoteMedia.dtlsParams) {\n iceTransport.setRemoteParams(remoteMedia.iceParams);\n dtlsTransport.setRemoteParams(remoteMedia.dtlsParams);\n\n // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role\n // RFC 8445 S6.1.1\n if (remoteMedia.iceParams?.iceLite) {\n iceTransport.connection.iceControlling = true;\n }\n }\n\n // # add ICE candidates\n remoteMedia.iceCandidates.forEach(iceTransport.addRemoteCandidate);\n\n await iceTransport.iceGather.gather();\n\n if (remoteMedia.iceCandidatesComplete) {\n await iceTransport.addRemoteCandidate(undefined);\n }\n\n // # set DTLS role\n if (remoteSdp.type === \"answer\" && remoteMedia.dtlsParams?.role) {\n dtlsTransport.role =\n remoteMedia.dtlsParams.role === \"client\" ? \"server\" : \"client\";\n }\n })\n );\n\n // connect transports\n if (remoteSdp.type === \"answer\") {\n log(\"caller start connect\");\n this.connect().catch((err) => {\n log(\"connect failed\", err);\n this.setConnectionState(\"failed\");\n });\n }\n\n if (remoteSdp.type === \"offer\") {\n this.setSignalingState(\"have-remote-offer\");\n } else if (remoteSdp.type === \"answer\") {\n this.setSignalingState(\"stable\");\n }\n\n this.negotiationneeded = false;\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\n }\n }\n\n private setRemoteRTP(\n transceiver: RTCRtpTransceiver,\n remoteMedia: MediaDescription,\n type: \"offer\" | \"answer\",\n mLineIndex: number\n ) {\n if (!transceiver.mid) {\n transceiver.mid = remoteMedia.rtp.muxId;\n transceiver.mLineIndex = mLineIndex;\n }\n\n // # negotiate codecs\n transceiver.codecs = remoteMedia.rtp.codecs.filter((remoteCodec) => {\n const localCodecs = this.configuration.codecs[remoteMedia.kind] || [];\n\n const existCodec = findCodecByMimeType(localCodecs, remoteCodec);\n if (!existCodec) return false;\n\n if (existCodec?.name.toLowerCase() === \"rtx\") {\n const params = codecParametersFromString(existCodec.parameters ?? \"\");\n const pt = params[\"apt\"];\n const origin = remoteMedia.rtp.codecs.find((c) => c.payloadType === pt);\n if (!origin) return false;\n return !!findCodecByMimeType(localCodecs, origin);\n }\n\n return true;\n });\n\n log(\"negotiated codecs\", transceiver.codecs);\n if (transceiver.codecs.length === 0) {\n throw new Error(\"negotiate codecs failed.\");\n }\n transceiver.headerExtensions = remoteMedia.rtp.headerExtensions.filter(\n (extension) =>\n (\n this.configuration.headerExtensions[\n remoteMedia.kind as \"video\" | \"audio\"\n ] || []\n ).find((v) => v.uri === extension.uri)\n );\n\n // # configure direction\n const mediaDirection = remoteMedia.direction || \"inactive\";\n const direction = reverseDirection(mediaDirection);\n if ([\"answer\", \"pranswer\"].includes(type)) {\n transceiver.currentDirection = direction;\n } else {\n transceiver.offerDirection = direction;\n }\n\n const localParams = this.getLocalRtpParams(transceiver);\n transceiver.sender.prepareSend(localParams);\n\n if ([\"recvonly\", \"sendrecv\"].includes(transceiver.direction)) {\n const remotePrams = this.getRemoteRtpParams(remoteMedia, transceiver);\n\n // register simulcast receiver\n remoteMedia.simulcastParameters.forEach((param) => {\n this.router.registerRtpReceiverByRid(transceiver, param, remotePrams);\n });\n\n transceiver.receiver.prepareReceive(remotePrams);\n // register ssrc receiver\n this.router.registerRtpReceiverBySsrc(transceiver, remotePrams);\n }\n if ([\"sendonly\", \"sendrecv\"].includes(mediaDirection)) {\n // assign msid\n if (remoteMedia.msid != undefined) {\n const [streamId, trackId] = remoteMedia.msid.split(\" \");\n transceiver.receiver.remoteStreamId = streamId;\n transceiver.receiver.remoteTrackId = trackId;\n\n this.fireOnTrack(\n transceiver.receiver.track,\n transceiver,\n new MediaStream({\n id: streamId,\n tracks: [transceiver.receiver.track],\n })\n );\n }\n }\n\n transceiver.receiver.setupTWCC(remoteMedia.ssrc[0]?.ssrc);\n }\n\n private setRemoteSCTP(\n remoteMedia: MediaDescription,\n sctpTransport: RTCSctpTransport\n ) {\n // # configure sctp\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n\n sctpTransport.setRemotePort(this.sctpRemotePort);\n if (!sctpTransport.mid) {\n sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n private validateDescription(\n description: SessionDescription,\n isLocal: boolean\n ) {\n if (isLocal) {\n if (description.type === \"offer\") {\n if (![\"stable\", \"have-local-offer\"].includes(this.signalingState))\n throw new Error(\"Cannot handle offer in signaling state\");\n } else if (description.type === \"answer\") {\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"Cannot handle answer in signaling state\");\n }\n }\n } else {\n if (description.type === \"offer\") {\n if (![\"stable\", \"have-remote-offer\"].includes(this.signalingState)) {\n throw new Error(\"Cannot handle offer in signaling state\");\n }\n } else if (description.type === \"answer\") {\n if (\n ![\"have-local-offer\", \"have-remote-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"Cannot handle answer in signaling state\");\n }\n }\n }\n\n description.media.forEach((media) => {\n if (media.direction === \"inactive\") return;\n if (\n !media.iceParams ||\n !media.iceParams.usernameFragment ||\n !media.iceParams.password\n )\n throw new Error(\"ICE username fragment or password is missing\");\n });\n\n if ([\"answer\", \"pranswer\"].includes(description.type || \"\")) {\n const offer = isLocal ? this._remoteDescription : this._localDescription;\n if (!offer) throw new Error();\n\n const offerMedia = offer.media.map((v) => [v.kind, v.rtp.muxId]);\n const answerMedia = description.media.map((v) => [v.kind, v.rtp.muxId]);\n if (!isEqual(offerMedia, answerMedia))\n throw new Error(\"Media sections in answer do not match offer\");\n }\n }\n\n private fireOnTrack(\n track: MediaStreamTrack,\n transceiver: RTCRtpTransceiver,\n stream: MediaStream\n ) {\n const event: RTCTrackEvent = {\n track,\n streams: [stream],\n transceiver,\n receiver: transceiver.receiver,\n };\n this.emit(\"track\", event);\n if (this.ontrack) this.ontrack(event);\n }\n\n addTransceiver(\n trackOrKind: Kind | MediaStreamTrack,\n options: Partial<TransceiverOptions> = {}\n ) {\n const kind =\n typeof trackOrKind === \"string\" ? trackOrKind : trackOrKind.kind;\n\n const direction = options.direction || \"sendrecv\";\n\n const dtlsTransport = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n\n const sender = new RTCRtpSender(trackOrKind);\n const receiver = new RTCRtpReceiver(kind, sender.ssrc);\n const transceiver = new RTCRtpTransceiver(\n kind,\n dtlsTransport,\n receiver,\n sender,\n direction\n );\n transceiver.options = options;\n this.router.registerRtpSender(transceiver.sender);\n\n this.transceivers.push(transceiver);\n this.onTransceiverAdded.execute(transceiver);\n\n this.updateIceConnectionState();\n this.needNegotiation();\n\n return transceiver;\n }\n\n getTransceivers() {\n return this.transceivers;\n }\n\n getSenders(): RTCRtpSender[] {\n return this.getTransceivers().map((t) => t.sender);\n }\n\n getReceivers() {\n return this.getTransceivers().map((t) => t.receiver);\n }\n\n // todo fix\n addTrack(\n track: MediaStreamTrack,\n /**todo impl */\n ms?: MediaStream\n ) {\n if (this.isClosed) throw new Error(\"is closed\");\n if (this.getSenders().find((sender) => sender.track?.uuid === track.uuid)) {\n throw new Error(\"track exist\");\n }\n\n const emptyTrackSender = this.transceivers.find(\n (t) =>\n t.sender.track == undefined &&\n t.kind === track.kind &&\n SenderDirections.includes(t.direction) === true\n );\n if (emptyTrackSender) {\n const sender = emptyTrackSender.sender;\n sender.registerTrack(track);\n this.needNegotiation();\n return sender;\n }\n\n const notSendTransceiver = this.transceivers.find(\n (t) =>\n t.sender.track == undefined &&\n t.kind === track.kind &&\n SenderDirections.includes(t.direction) === false &&\n !t.usedForSender\n );\n if (notSendTransceiver) {\n const sender = notSendTransceiver.sender;\n sender.registerTrack(track);\n switch (notSendTransceiver.direction) {\n case \"recvonly\":\n notSendTransceiver.direction = \"sendrecv\";\n break;\n case \"inactive\":\n notSendTransceiver.direction = \"sendonly\";\n break;\n }\n this.needNegotiation();\n return sender;\n } else {\n const transceiver = this.addTransceiver(track, { direction: \"sendrecv\" });\n this.needNegotiation();\n return transceiver.sender;\n }\n }\n\n private async ensureCerts() {\n const ensureCert = async (dtlsTransport: RTCDtlsTransport) => {\n if (this.certificates.length === 0) {\n const localCertificate = await dtlsTransport.setupCertificate();\n this.certificates.push(localCertificate);\n } else {\n dtlsTransport.localCertificate = this.certificates[0];\n }\n };\n\n for (const dtlsTransport of this.dtlsTransports) {\n await ensureCert(dtlsTransport);\n }\n }\n\n async createAnswer() {\n this.assertNotClosed();\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"createAnswer failed\");\n }\n if (!this._remoteDescription) {\n throw new Error(\"wrong state\");\n }\n\n await this.ensureCerts();\n\n const description = new SessionDescription();\n addSDPHeader(\"answer\", description);\n\n this._remoteDescription.media.forEach((remoteMedia) => {\n let dtlsTransport!: RTCDtlsTransport;\n let media: MediaDescription;\n\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n const transceiver = this.getTransceiverByMid(remoteMedia.rtp.muxId!)!;\n media = createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n andDirection(transceiver.direction, transceiver.offerDirection),\n transceiver.mid!\n );\n dtlsTransport = transceiver.dtlsTransport;\n } else if (remoteMedia.kind === \"application\") {\n if (!this.sctpTransport || !this.sctpTransport.mid) {\n throw new Error(\"sctpTransport not found\");\n }\n media = createMediaDescriptionForSctp(\n this.sctpTransport,\n this.sctpTransport.mid\n );\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n } else {\n throw new Error(\"invalid kind\");\n }\n\n // # determine DTLS role, or preserve the currently configured role\n if (!media.dtlsParams) {\n throw new Error(\"dtlsParams missing\");\n }\n if (dtlsTransport.role === \"auto\") {\n media.dtlsParams.role = \"client\";\n } else {\n media.dtlsParams.role = dtlsTransport.role;\n }\n\n media.simulcastParameters = remoteMedia.simulcastParameters.map((v) => ({\n ...v,\n direction: reverseSimulcastDirection(v.direction),\n }));\n\n description.media.push(media);\n });\n\n if (this.configuration.bundlePolicy !== \"disable\") {\n const bundle = new GroupDescription(\"BUNDLE\", []);\n description.media.forEach((media) => {\n bundle.items.push(media.rtp.muxId!);\n });\n description.group.push(bundle);\n }\n\n return description.toJSON();\n }\n\n async close() {\n if (this.isClosed) return;\n\n this.isClosed = true;\n this.setSignalingState(\"closed\");\n this.setConnectionState(\"closed\");\n\n this.transceivers.forEach((transceiver) => {\n transceiver.receiver.stop();\n transceiver.sender.stop();\n });\n\n if (this.sctpTransport) {\n await this.sctpTransport.stop();\n }\n for (const dtlsTransport of this.dtlsTransports) {\n await dtlsTransport.stop();\n await dtlsTransport.iceTransport.stop();\n }\n\n this.dispose();\n log(\"peerConnection closed\");\n }\n\n private assertNotClosed() {\n if (this.isClosed) {\n throw new Error(\"RTCPeerConnection is closed\");\n }\n }\n\n // https://w3c.github.io/webrtc-pc/#dom-rtcicegatheringstate\n private updateIceGatheringState() {\n const all = this.iceTransports;\n\n function allMatch(...state: IceGathererState[]) {\n return (\n all.filter((check) => state.includes(check.iceGather.gatheringState))\n .length === all.length\n );\n }\n\n let newState: IceGathererState;\n\n if (all.length && allMatch(\"complete\")) {\n newState = \"complete\";\n } else if (!all.length || allMatch(\"new\", \"complete\")) {\n newState = \"new\";\n } else if (\n all.map((check) => check.iceGather.gatheringState).includes(\"gathering\")\n ) {\n newState = \"gathering\";\n } else {\n newState = \"new\";\n }\n\n if (this.iceGatheringState === newState) {\n return;\n }\n\n log(\"iceGatheringStateChange\", newState);\n this.iceGatheringState = newState;\n this.iceGatheringStateChange.execute(newState);\n this.emit(\"icegatheringstatechange\", newState);\n }\n\n // https://w3c.github.io/webrtc-pc/#dom-rtciceconnectionstate\n private updateIceConnectionState() {\n const all = this.iceTransports;\n let newState: RTCIceConnectionState;\n\n function allMatch(...state: RTCIceConnectionState[]) {\n return (\n all.filter((check) => state.includes(check.state)).length === all.length\n );\n }\n\n if (this.connectionState === \"closed\") {\n newState = \"closed\";\n } else if (allMatch(\"failed\")) {\n newState = \"failed\";\n } else if (allMatch(\"disconnected\")) {\n newState = \"disconnected\";\n } else if (allMatch(\"new\", \"closed\")) {\n newState = \"new\";\n } else if (allMatch(\"new\", \"checking\")) {\n newState = \"checking\";\n } else if (allMatch(\"completed\", \"closed\")) {\n newState = \"completed\";\n } else if (allMatch(\"connected\", \"completed\", \"closed\")) {\n newState = \"connected\";\n } else {\n // unreachable?\n newState = \"new\";\n }\n\n if (this.iceConnectionState === newState) {\n return;\n }\n\n log(\"iceConnectionStateChange\", newState);\n this.iceConnectionState = newState;\n this.iceConnectionStateChange.execute(newState);\n this.emit(\"iceconnectionstatechange\", newState);\n }\n\n private setSignalingState(state: RTCSignalingState) {\n log(\"signalingStateChange\", state);\n this.signalingState = state;\n this.signalingStateChange.execute(state);\n if (this.onsignalingstatechange) this.onsignalingstatechange({});\n }\n\n private setConnectionState(state: ConnectionState) {\n log(\"connectionStateChange\", state);\n this.connectionState = state;\n this.connectionStateChange.execute(state);\n if (this.onconnectionstatechange) this.onconnectionstatechange();\n this.emit(\"connectionstatechange\");\n }\n\n private dispose() {\n this.onDataChannel.allUnsubscribe();\n this.iceGatheringStateChange.allUnsubscribe();\n this.iceConnectionStateChange.allUnsubscribe();\n this.signalingStateChange.allUnsubscribe();\n this.onTransceiverAdded.allUnsubscribe();\n this.onRemoteTransceiverAdded.allUnsubscribe();\n this.onIceCandidate.allUnsubscribe();\n }\n}\n\nexport function createMediaDescriptionForTransceiver(\n transceiver: RTCRtpTransceiver,\n cname: string,\n direction: Direction,\n mid: string\n) {\n const media = new MediaDescription(\n transceiver.kind,\n 9,\n \"UDP/TLS/RTP/SAVPF\",\n transceiver.codecs.map((c) => c.payloadType)\n );\n media.direction = direction;\n media.msid = transceiver.msid;\n media.rtp = {\n codecs: transceiver.codecs,\n headerExtensions: transceiver.headerExtensions,\n muxId: mid,\n };\n media.rtcpHost = \"0.0.0.0\";\n media.rtcpPort = 9;\n media.rtcpMux = true;\n media.ssrc = [new SsrcDescription({ ssrc: transceiver.sender.ssrc, cname })];\n\n if (transceiver.options.simulcast) {\n media.simulcastParameters = transceiver.options.simulcast.map(\n (o) => new RTCRtpSimulcastParameters(o)\n );\n }\n\n if (media.rtp.codecs.find((c) => c.name.toLowerCase() === \"rtx\")) {\n media.ssrc.push(\n new SsrcDescription({ ssrc: transceiver.sender.rtxSsrc, cname })\n );\n media.ssrcGroup = [\n new GroupDescription(\"FID\", [\n transceiver.sender.ssrc.toString(),\n transceiver.sender.rtxSsrc.toString(),\n ]),\n ];\n }\n\n addTransportDescription(media, transceiver.dtlsTransport);\n return media;\n}\n\nexport function createMediaDescriptionForSctp(\n sctp: RTCSctpTransport,\n mid: string\n) {\n const media = new MediaDescription(\n \"application\",\n DISCARD_PORT,\n \"UDP/DTLS/SCTP\",\n [\"webrtc-datachannel\"]\n );\n media.sctpPort = sctp.port;\n media.rtp.muxId = mid;\n media.sctpCapabilities = RTCSctpTransport.getCapabilities();\n\n addTransportDescription(media, sctp.dtlsTransport);\n return media;\n}\n\nexport function addTransportDescription(\n media: MediaDescription,\n dtlsTransport: RTCDtlsTransport\n) {\n const iceTransport = dtlsTransport.iceTransport;\n const iceGatherer = iceTransport.iceGather;\n\n media.iceCandidates = iceGatherer.localCandidates;\n media.iceCandidatesComplete = iceGatherer.gatheringState === \"complete\";\n media.iceParams = iceGatherer.localParameters;\n media.iceOptions = \"trickle\";\n\n if (media.iceCandidates.length > 0) {\n const candidate = media.iceCandidates[media.iceCandidates.length - 1];\n media.host = candidate.ip;\n media.port = candidate.port;\n } else {\n media.host = DISCARD_HOST;\n media.port = DISCARD_PORT;\n }\n\n if (media.direction === \"inactive\") {\n media.port = 0;\n }\n\n if (!media.dtlsParams) {\n media.dtlsParams = dtlsTransport.localParameters;\n if (!media.dtlsParams.fingerprints) {\n media.dtlsParams.fingerprints =\n dtlsTransport.localParameters.fingerprints;\n }\n }\n}\n\nexport function allocateMid(mids: Set<string>) {\n let mid = \"\";\n for (let i = 0; ; ) {\n mid = (i++).toString();\n if (!mids.has(mid)) break;\n }\n mids.add(mid);\n return mid;\n}\n\nexport type BundlePolicy = \"max-compat\" | \"max-bundle\" | \"disable\";\n\nexport interface PeerConfig {\n codecs: Partial<{\n audio: RTCRtpCodecParameters[];\n video: RTCRtpCodecParameters[];\n }>;\n headerExtensions: Partial<{\n audio: RTCRtpHeaderExtensionParameters[];\n video: RTCRtpHeaderExtensionParameters[];\n }>;\n iceTransportPolicy: \"all\" | \"relay\";\n iceServers: RTCIceServer[];\n /**Minimum port and Maximum port must not be the same value */\n icePortRange: [number, number] | undefined;\n dtls: Partial<{\n keys: DtlsKeys;\n }>;\n bundlePolicy: BundlePolicy;\n}\n\nexport const findCodecByMimeType = (\n codecs: RTCRtpCodecParameters[],\n target: RTCRtpCodecParameters\n) =>\n codecs.find(\n (localCodec) =>\n localCodec.mimeType.toLowerCase() === target.mimeType.toLowerCase()\n )\n ? target\n : undefined;\n\nexport type RTCIceServer = {\n urls: string;\n username?: string;\n credential?: string;\n};\n\nexport const defaultPeerConfig: PeerConfig = {\n codecs: {\n audio: [\n new RTCRtpCodecParameters({\n mimeType: \"audio/opus\",\n clockRate: 48000,\n channels: 2,\n }),\n new RTCRtpCodecParameters({\n mimeType: \"audio/PCMU\",\n clockRate: 8000,\n channels: 1,\n }),\n ],\n video: [\n new RTCRtpCodecParameters({\n mimeType: \"video/VP8\",\n clockRate: 90000,\n rtcpFeedback: [\n { type: \"ccm\", parameter: \"fir\" },\n { type: \"nack\" },\n { type: \"nack\", parameter: \"pli\" },\n { type: \"goog-remb\" },\n ],\n }),\n ],\n },\n headerExtensions: { audio: [], video: [] },\n iceTransportPolicy: \"all\",\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n icePortRange: undefined,\n dtls: {},\n bundlePolicy: \"max-compat\",\n};\n\nexport interface RTCTrackEvent {\n track: MediaStreamTrack;\n streams: MediaStream[];\n transceiver: RTCRtpTransceiver;\n receiver: RTCRtpReceiver;\n}\n\nexport interface RTCDataChannelEvent {\n channel: RTCDataChannel;\n}\n\nexport interface RTCPeerConnectionIceEvent {\n candidate: RTCIceCandidate;\n}\n"]}
1
+ {"version":3,"file":"peerConnection.js","sourceRoot":"","sources":["../../../src/peerConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,iEAAyC;AACzC,6DAAqC;AACrC,sDAA4B;AAC5B,2CAA6B;AAG7B,wBAAwD;AACxD,mCAKiB;AACjB,+CAAyE;AACzE,qCAAkD;AAClD,mDAQ4B;AAC5B,2CAA2C;AAC3C,qDAAqD;AACrD,iDAAiD;AACjD,2DAIgC;AAChC,yCAA8D;AAC9D,+BAMe;AACf,2CAAoE;AACpE,yCAOyB;AACzB,2CAAoD;AAGpD,mCAKiB;AAEjB,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,8CAA8C,CAAC,CAAC;AAElE,MAAa,iBAAkB,SAAQ,oBAAW;IAyDhD,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,IAAI,EACJ,YAAY,MACW,EAAE;QACzB,KAAK,EAAE,CAAC;QAjED,UAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAE3B,+BAA0B,GAAG,KAAK,CAAC;QACnC,kBAAa,GACX,IAAA,mBAAS,EAAa,yBAAiB,CAAC,CAAC;QAC3C,oBAAe,GAAoB,KAAK,CAAC;QACzC,uBAAkB,GAA0B,KAAK,CAAC;QAClD,sBAAiB,GAAqB,KAAK,CAAC;QAC5C,mBAAc,GAAsB,QAAQ,CAAC;QAC7C,sBAAiB,GAAG,KAAK,CAAC;QACjB,iBAAY,GAAwB,EAAE,CAAC;QAEvC,4BAAuB,GAAG,IAAI,iBAAK,EAAsB,CAAC;QAC1D,6BAAwB,GAAG,IAAI,iBAAK,EAA2B,CAAC;QAChE,yBAAoB,GAAG,IAAI,iBAAK,EAAuB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,QAAQ,EAAE,CAAC;aACZ,CAAC;YACF,IAAI,kCAAqB,CAAC;gBACxB,QAAQ,EAAE,YAAY;gBACtB,SAAS,EAAE,IAAI;gBACf,QAAQ,EAAE,CAAC;gBACX,WAAW,EAAE,CAAC;aACf,CAAC;SACH;QACD,KAAK,EAAE;YACL,IAAI,kCAAqB,CAAC;gBACxB,QAAQ,EAAE,WAAW;gBACrB,SAAS,EAAE,KAAK;gBAChB,YAAY,EAAE;oBACZ,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;oBACjC,EAAE,IAAI,EAAE,MAAM,EAAE;oBAChB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE;oBAClC,EAAE,IAAI,EAAE,WAAW,EAAE;iBACtB;aACF,CAAC;SACH;KACF;IACD,gBAAgB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IAC1C,kBAAkB,EAAE,KAAK;IACzB,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC;IACtD,YAAY,EAAE,SAAS;IACvB,IAAI,EAAE,EAAE;IACR,YAAY,EAAE,YAAY;CAC3B,CAAC","sourcesContent":["import debug from \"debug\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport isEqual from \"lodash/isEqual\";\nimport Event from \"rx.mini\";\nimport * as uuid from \"uuid\";\n\nimport { Profile } from \"../../dtls/src/context/srtp\";\nimport { codecParametersFromString, DtlsKeys } from \".\";\nimport {\n DISCARD_HOST,\n DISCARD_PORT,\n SenderDirections,\n SRTP_PROFILE,\n} from \"./const\";\nimport { RTCDataChannel, RTCDataChannelParameters } from \"./dataChannel\";\nimport { enumerate, EventTarget } from \"./helper\";\nimport {\n RTCRtpCodecParameters,\n RTCRtpCodingParameters,\n RTCRtpHeaderExtensionParameters,\n RTCRtpParameters,\n RTCRtpReceiveParameters,\n RTCRtpRtxParameters,\n RTCRtpSimulcastParameters,\n} from \"./media/parameters\";\nimport { RtpRouter } from \"./media/router\";\nimport { RTCRtpReceiver } from \"./media/rtpReceiver\";\nimport { RTCRtpSender } from \"./media/rtpSender\";\nimport {\n Direction,\n RTCRtpTransceiver,\n TransceiverOptions,\n} from \"./media/rtpTransceiver\";\nimport { MediaStream, MediaStreamTrack } from \"./media/track\";\nimport {\n addSDPHeader,\n GroupDescription,\n MediaDescription,\n SessionDescription,\n SsrcDescription,\n} from \"./sdp\";\nimport { RTCCertificate, RTCDtlsTransport } from \"./transport/dtls\";\nimport {\n IceCandidate,\n IceGathererState,\n RTCIceCandidate,\n RTCIceConnectionState,\n RTCIceGatherer,\n RTCIceTransport,\n} from \"./transport/ice\";\nimport { RTCSctpTransport } from \"./transport/sctp\";\nimport { ConnectionState, Kind, RTCSignalingState } from \"./types/domain\";\nimport { Callback, CallbackWithValue } from \"./types/util\";\nimport {\n andDirection,\n parseIceServers,\n reverseDirection,\n reverseSimulcastDirection,\n} from \"./utils\";\n\nconst log = debug(\"werift:packages/webrtc/src/peerConnection.ts\");\n\nexport class RTCPeerConnection extends EventTarget {\n readonly cname = uuid.v4();\n sctpTransport?: RTCSctpTransport;\n masterTransportEstablished = false;\n configuration: Required<PeerConfig> =\n cloneDeep<PeerConfig>(defaultPeerConfig);\n connectionState: ConnectionState = \"new\";\n iceConnectionState: RTCIceConnectionState = \"new\";\n iceGatheringState: IceGathererState = \"new\";\n signalingState: RTCSignalingState = \"stable\";\n negotiationneeded = false;\n readonly transceivers: RTCRtpTransceiver[] = [];\n\n readonly iceGatheringStateChange = new Event<[IceGathererState]>();\n readonly iceConnectionStateChange = new Event<[RTCIceConnectionState]>();\n readonly signalingStateChange = new Event<[RTCSignalingState]>();\n readonly connectionStateChange = new Event<[ConnectionState]>();\n readonly onDataChannel = new Event<[RTCDataChannel]>();\n readonly onRemoteTransceiverAdded = new Event<[RTCRtpTransceiver]>();\n readonly onTransceiverAdded = new Event<[RTCRtpTransceiver]>();\n readonly onIceCandidate = new Event<[RTCIceCandidate]>();\n readonly onNegotiationneeded = new Event<[]>();\n\n ondatachannel?: CallbackWithValue<RTCDataChannelEvent>;\n onicecandidate?: CallbackWithValue<RTCPeerConnectionIceEvent>;\n onnegotiationneeded?: CallbackWithValue<any>;\n onsignalingstatechange?: CallbackWithValue<any>;\n ontrack?: CallbackWithValue<RTCTrackEvent>;\n onconnectionstatechange?: Callback;\n\n private readonly router = new RtpRouter();\n private readonly certificates: RTCCertificate[] = [];\n sctpRemotePort?: number;\n private seenMid = new Set<string>();\n private currentLocalDescription?: SessionDescription;\n private currentRemoteDescription?: SessionDescription;\n private pendingLocalDescription?: SessionDescription;\n private pendingRemoteDescription?: SessionDescription;\n private isClosed = false;\n private shouldNegotiationneeded = false;\n\n get dtlsTransports() {\n const transports = this.transceivers.map((t) => t.dtlsTransport);\n if (this.sctpTransport) {\n transports.push(this.sctpTransport.dtlsTransport);\n }\n return transports.reduce((acc: RTCDtlsTransport[], cur) => {\n if (!acc.map((d) => d.id).includes(cur.id)) {\n acc.push(cur);\n }\n return acc;\n }, []);\n }\n get iceTransports() {\n return this.dtlsTransports.map((d) => d.iceTransport);\n }\n\n constructor({\n codecs,\n headerExtensions,\n iceServers,\n iceTransportPolicy,\n icePortRange,\n dtls,\n bundlePolicy,\n }: Partial<PeerConfig> = {}) {\n super();\n\n if (iceServers) this.configuration.iceServers = iceServers;\n if (iceTransportPolicy)\n this.configuration.iceTransportPolicy = iceTransportPolicy;\n if (icePortRange) {\n const [min, max] = icePortRange;\n if (min === max) throw new Error(\"should not be same value\");\n if (min >= max) throw new Error(\"The min must be less than max\");\n this.configuration.icePortRange = icePortRange;\n }\n if (codecs?.audio) this.configuration.codecs.audio = codecs.audio;\n if (codecs?.video) this.configuration.codecs.video = codecs.video;\n\n for (const [i, codecParams] of enumerate([\n ...(this.configuration.codecs.audio || []),\n ...(this.configuration.codecs.video || []),\n ])) {\n if (codecParams.payloadType != undefined) {\n continue;\n }\n\n codecParams.payloadType = 96 + i;\n switch (codecParams.name.toLowerCase()) {\n case \"rtx\":\n {\n codecParams.parameters = `apt=${codecParams.payloadType - 1}`;\n }\n break;\n case \"red\":\n {\n const redundant = codecParams.payloadType + 1;\n codecParams.parameters = `${redundant}/${redundant}`;\n codecParams.payloadType = 63;\n }\n break;\n }\n }\n\n if (headerExtensions?.audio)\n this.configuration.headerExtensions.audio = headerExtensions.audio;\n if (headerExtensions?.video)\n this.configuration.headerExtensions.video = headerExtensions.video;\n [\n ...(this.configuration.headerExtensions.audio || []),\n ...(this.configuration.headerExtensions.video || []),\n ].forEach((v, i) => {\n v.id = 1 + i;\n });\n\n if (dtls) {\n const { keys } = dtls;\n if (keys) {\n this.certificates.push(\n new RTCCertificate(keys.keyPem, keys.certPem, keys.signatureHash)\n );\n }\n }\n\n this.iceConnectionStateChange.subscribe((state) => {\n switch (state) {\n case \"disconnected\":\n this.setConnectionState(\"disconnected\");\n break;\n case \"closed\":\n this.close();\n break;\n }\n });\n if (bundlePolicy) {\n this.configuration.bundlePolicy = bundlePolicy;\n }\n }\n\n get localDescription() {\n if (!this._localDescription) return;\n return this._localDescription.toJSON();\n }\n\n get remoteDescription() {\n if (!this._remoteDescription) return;\n return this._remoteDescription.toJSON();\n }\n\n private get _localDescription() {\n return this.pendingLocalDescription || this.currentLocalDescription;\n }\n\n private get _remoteDescription() {\n return this.pendingRemoteDescription || this.currentRemoteDescription;\n }\n\n private getTransceiverByMid(mid: string) {\n return this.transceivers.find((transceiver) => transceiver.mid === mid);\n }\n\n private getTransceiverByMLineIndex(index: number) {\n return this.transceivers.find(\n (transceiver) => transceiver.mLineIndex === index\n );\n }\n\n async createOffer() {\n await this.ensureCerts();\n\n this.transceivers.forEach((transceiver) => {\n transceiver.codecs = this.configuration.codecs[transceiver.kind];\n transceiver.headerExtensions =\n this.configuration.headerExtensions[transceiver.kind];\n });\n\n const description = new SessionDescription();\n addSDPHeader(\"offer\", description);\n\n // # handle existing transceivers / sctp\n\n const currentMedia = this._localDescription\n ? this._localDescription.media\n : [];\n\n currentMedia.forEach((m, i) => {\n const mid = m.rtp.muxId;\n if (!mid) {\n log(\"mid missing\", m);\n return;\n }\n if (m.kind === \"application\") {\n description.media.push(\n createMediaDescriptionForSctp(this.sctpTransport!, mid)\n );\n } else {\n const transceiver = this.getTransceiverByMid(mid);\n if (!transceiver) {\n log(\"transceiver by mid not found\", mid);\n return;\n }\n transceiver.mLineIndex = i;\n description.media.push(\n createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n transceiver.direction,\n mid\n )\n );\n }\n });\n\n // # handle new transceivers / sctp\n this.transceivers\n .filter((t) => !description.media.find((m) => m.rtp.muxId === t.mid))\n .forEach((transceiver) => {\n transceiver.mLineIndex = description.media.length;\n description.media.push(\n createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n transceiver.direction,\n allocateMid(this.seenMid)\n )\n );\n });\n\n if (\n this.sctpTransport &&\n !description.media.find((m) => this.sctpTransport!.mid === m.rtp.muxId)\n ) {\n description.media.push(\n createMediaDescriptionForSctp(\n this.sctpTransport,\n allocateMid(this.seenMid)\n )\n );\n }\n\n if (this.configuration.bundlePolicy !== \"disable\") {\n const mids = description.media\n .map((m) => m.rtp.muxId)\n .filter((v) => v) as string[];\n const bundle = new GroupDescription(\"BUNDLE\", mids);\n description.group.push(bundle);\n }\n\n return description.toJSON();\n }\n\n createDataChannel(\n label: string,\n options: Partial<{\n maxPacketLifeTime?: number;\n protocol: string;\n maxRetransmits?: number;\n ordered: boolean;\n negotiated: boolean;\n id?: number;\n }> = {}\n ): RTCDataChannel {\n const base: typeof options = {\n protocol: \"\",\n ordered: true,\n negotiated: false,\n };\n const settings: Required<typeof base> = { ...base, ...options } as any;\n\n if (settings.maxPacketLifeTime && settings.maxRetransmits) {\n throw new Error(\"can not select both\");\n }\n\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n this.needNegotiation();\n }\n\n const parameters = new RTCDataChannelParameters({\n id: settings.id,\n label,\n maxPacketLifeTime: settings.maxPacketLifeTime,\n maxRetransmits: settings.maxRetransmits,\n negotiated: settings.negotiated,\n ordered: settings.ordered,\n protocol: settings.protocol,\n });\n\n const channel = new RTCDataChannel(this.sctpTransport, parameters);\n return channel;\n }\n\n removeTrack(sender: RTCRtpSender) {\n if (this.isClosed) throw new Error(\"peer closed\");\n if (!this.getSenders().find(({ ssrc }) => sender.ssrc === ssrc))\n throw new Error(\"unExist\");\n\n const transceiver = this.transceivers.find(\n ({ sender: { ssrc } }) => sender.ssrc === ssrc\n );\n if (!transceiver) throw new Error(\"unExist\");\n\n sender.stop();\n\n if (transceiver.currentDirection === \"recvonly\") {\n this.needNegotiation();\n return;\n }\n\n if (transceiver.direction === \"sendrecv\") {\n transceiver.direction = \"recvonly\";\n } else if (\n transceiver.direction === \"sendonly\" ||\n transceiver.direction === \"recvonly\"\n ) {\n transceiver.direction = \"inactive\";\n }\n this.needNegotiation();\n }\n\n private needNegotiation = async () => {\n this.shouldNegotiationneeded = true;\n if (this.negotiationneeded || this.signalingState !== \"stable\") return;\n this.shouldNegotiationneeded = false;\n setImmediate(() => {\n this.negotiationneeded = true;\n this.onNegotiationneeded.execute();\n if (this.onnegotiationneeded) this.onnegotiationneeded({});\n });\n };\n\n private createTransport(srtpProfiles: Profile[] = []) {\n const [existing] = this.iceTransports;\n\n // Gather ICE candidates for only one track. If the remote endpoint is not bundle-aware, negotiate only one media track.\n // https://w3c.github.io/webrtc-pc/#rtcbundlepolicy-enum\n if (this.configuration.bundlePolicy === \"max-bundle\") {\n if (existing) {\n return this.dtlsTransports[0];\n }\n }\n\n const iceGatherer = new RTCIceGatherer({\n ...parseIceServers(this.configuration.iceServers),\n forceTurn: this.configuration.iceTransportPolicy === \"relay\",\n portRange: this.configuration.icePortRange,\n });\n if (existing) {\n iceGatherer.connection.localUserName = existing.connection.localUserName;\n iceGatherer.connection.localPassword = existing.connection.localPassword;\n }\n iceGatherer.onGatheringStateChange.subscribe(() => {\n this.updateIceGatheringState();\n });\n this.updateIceGatheringState();\n const iceTransport = new RTCIceTransport(iceGatherer);\n iceTransport.onStateChange.subscribe(() => {\n this.updateIceConnectionState();\n });\n\n iceTransport.iceGather.onIceCandidate = (candidate) => {\n if (!this.localDescription) return;\n const sdp = SessionDescription.parse(this.localDescription.sdp);\n const media = sdp.media[0];\n if (!media) {\n log(\"media not exist\");\n return;\n }\n candidate.sdpMLineIndex = 0;\n candidate.sdpMid = media.rtp.muxId;\n candidate.foundation = \"candidate:\" + candidate.foundation;\n\n this.onIceCandidate.execute(candidate.toJSON());\n if (this.onicecandidate)\n this.onicecandidate({ candidate: candidate.toJSON() });\n this.emit(\"icecandidate\", { candidate });\n };\n\n const dtlsTransport = new RTCDtlsTransport(\n iceTransport,\n this.router,\n this.certificates,\n srtpProfiles\n );\n\n return dtlsTransport;\n }\n\n private createSctpTransport() {\n const dtlsTransport = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n const sctp = new RTCSctpTransport();\n sctp.setDtlsTransport(dtlsTransport);\n sctp.mid = undefined;\n\n sctp.onDataChannel.subscribe((channel) => {\n this.onDataChannel.execute(channel);\n\n const event: RTCDataChannelEvent = { channel };\n if (this.ondatachannel) this.ondatachannel(event);\n this.emit(\"datachannel\", event);\n });\n\n this.sctpTransport = sctp;\n this.updateIceConnectionState();\n\n return sctp;\n }\n\n async setLocalDescription(sessionDescription: {\n type: \"offer\" | \"answer\";\n sdp: string;\n }): Promise<SessionDescription> {\n // # parse and validate description\n const description = SessionDescription.parse(sessionDescription.sdp);\n description.type = sessionDescription.type;\n this.validateDescription(description, true);\n\n // # update signaling state\n if (description.type === \"offer\") {\n this.setSignalingState(\"have-local-offer\");\n } else if (description.type === \"answer\") {\n this.setSignalingState(\"stable\");\n }\n\n // # assign MID\n description.media.forEach((media, i) => {\n const mid = media.rtp.muxId!;\n this.seenMid.add(mid);\n if ([\"audio\", \"video\"].includes(media.kind)) {\n const transceiver = this.getTransceiverByMLineIndex(i);\n if (transceiver) {\n transceiver.mid = mid;\n }\n }\n if (media.kind === \"application\" && this.sctpTransport) {\n this.sctpTransport.mid = mid;\n }\n });\n\n const setupRole = (dtlsTransport: RTCDtlsTransport) => {\n const iceTransport = dtlsTransport.iceTransport;\n\n // # set ICE role\n if (description.type === \"offer\") {\n iceTransport.connection.iceControlling = true;\n } else {\n iceTransport.connection.iceControlling = false;\n }\n // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role\n // RFC 8445 S6.1.1\n if (iceTransport.connection.remoteIsLite) {\n iceTransport.connection.iceControlling = true;\n }\n\n // # set DTLS role for mediasoup\n if (description.type === \"answer\") {\n const role = description.media.find((media) => media.dtlsParams)\n ?.dtlsParams?.role;\n if (role) {\n dtlsTransport.role = role;\n }\n }\n };\n this.dtlsTransports.forEach((d) => setupRole(d));\n\n // # configure direction\n this.transceivers.forEach((t) => {\n if ([\"answer\", \"pranswer\"].includes(description.type)) {\n const direction = andDirection(t.direction, t.offerDirection);\n t.currentDirection = direction;\n }\n });\n\n // for trickle ice\n this.setLocal(description);\n\n // # gather candidates\n for (const iceTransport of this.iceTransports) {\n await iceTransport.iceGather.gather();\n }\n description.media\n .filter((m) => [\"audio\", \"video\"].includes(m.kind))\n .forEach((m, i) => {\n addTransportDescription(m, this.transceivers[i].dtlsTransport);\n });\n const sctpMedia = description.media.find((m) => m.kind === \"application\");\n if (this.sctpTransport && sctpMedia) {\n addTransportDescription(sctpMedia, this.sctpTransport.dtlsTransport);\n }\n\n this.setLocal(description);\n\n // connect transports\n if (description.type === \"answer\") {\n log(\"callee start connect\");\n this.connect().catch((err) => {\n log(\"connect failed\", err);\n this.setConnectionState(\"failed\");\n });\n }\n\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\n }\n\n return description;\n }\n\n private setLocal(description: SessionDescription) {\n if (description.type === \"answer\") {\n this.currentLocalDescription = description;\n this.pendingLocalDescription = undefined;\n } else {\n this.pendingLocalDescription = description;\n }\n }\n\n async addIceCandidate(candidateMessage: RTCIceCandidate) {\n const candidate = IceCandidate.fromJSON(candidateMessage);\n for (const iceTransport of this.iceTransports) {\n await iceTransport.addRemoteCandidate(candidate);\n }\n }\n\n private async connect() {\n if (this.masterTransportEstablished) return;\n\n this.setConnectionState(\"connecting\");\n\n await Promise.all(\n this.dtlsTransports.map(async (dtlsTransport) => {\n const { iceTransport } = dtlsTransport;\n await iceTransport.start().catch((err) => {\n log(\"iceTransport.start failed\", err);\n throw err;\n });\n await dtlsTransport.start().catch((err) => {\n log(\"dtlsTransport.start failed\", err);\n throw err;\n });\n if (\n this.sctpTransport &&\n this.sctpRemotePort &&\n this.sctpTransport.dtlsTransport.id === dtlsTransport.id\n ) {\n await this.sctpTransport.start(this.sctpRemotePort);\n await this.sctpTransport.sctp.stateChanged.connected.asPromise();\n log(\"sctp connected\");\n }\n })\n );\n\n this.masterTransportEstablished = true;\n this.setConnectionState(\"connected\");\n }\n\n private getLocalRtpParams(transceiver: RTCRtpTransceiver): RTCRtpParameters {\n if (transceiver.mid == undefined) throw new Error(\"mid not assigned\");\n\n const rtp: RTCRtpParameters = {\n codecs: transceiver.codecs,\n muxId: transceiver.mid,\n headerExtensions: transceiver.headerExtensions,\n rtcp: { cname: this.cname, ssrc: transceiver.sender.ssrc, mux: true },\n };\n return rtp;\n }\n\n private getRemoteRtpParams(\n media: MediaDescription,\n transceiver: RTCRtpTransceiver\n ): RTCRtpReceiveParameters {\n const receiveParameters: RTCRtpReceiveParameters = {\n muxId: media.rtp.muxId,\n rtcp: media.rtp.rtcp,\n codecs: transceiver.codecs,\n headerExtensions: transceiver.headerExtensions,\n encodings: Object.values(\n transceiver.codecs.reduce(\n (acc: { [pt: number]: RTCRtpCodingParameters }, codec) => {\n if (codec.name.toLowerCase() === \"rtx\") {\n const params = codecParametersFromString(codec.parameters ?? \"\");\n const apt = acc[params[\"apt\"]];\n if (apt && media.ssrc.length === 2) {\n apt.rtx = new RTCRtpRtxParameters({ ssrc: media.ssrc[1].ssrc });\n }\n return acc;\n }\n acc[codec.payloadType] = new RTCRtpCodingParameters({\n ssrc: media.ssrc[0]?.ssrc,\n payloadType: codec.payloadType,\n });\n return acc;\n },\n {}\n )\n ),\n };\n\n return receiveParameters;\n }\n\n async setRemoteDescription(sessionDescription: {\n type: \"offer\" | \"answer\";\n sdp: string;\n }) {\n // # parse and validate description\n const remoteSdp = SessionDescription.parse(sessionDescription.sdp);\n remoteSdp.type = sessionDescription.type;\n this.validateDescription(remoteSdp, false);\n\n if (remoteSdp.type === \"answer\") {\n this.currentRemoteDescription = remoteSdp;\n this.pendingRemoteDescription = undefined;\n } else {\n this.pendingRemoteDescription = remoteSdp;\n }\n\n const bundle = remoteSdp.group.find(\n (g) =>\n g.semantic === \"BUNDLE\" && this.configuration.bundlePolicy !== \"disable\"\n );\n let bundleTransport: RTCDtlsTransport | undefined;\n\n // # apply description\n await Promise.all(\n enumerate(remoteSdp.media).map(async ([i, remoteMedia]) => {\n let dtlsTransport: RTCDtlsTransport | undefined;\n\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n let transceiver = this.transceivers.find(\n (t) =>\n t.kind === remoteMedia.kind &&\n [undefined, remoteMedia.rtp.muxId].includes(t.mid)\n );\n if (!transceiver) {\n // create remote transceiver\n transceiver = this.addTransceiver(remoteMedia.kind, {\n direction: \"recvonly\",\n });\n this.onRemoteTransceiverAdded.execute(transceiver);\n }\n\n if (bundle) {\n if (!bundleTransport) {\n bundleTransport = transceiver.dtlsTransport;\n } else {\n transceiver.setDtlsTransport(bundleTransport);\n }\n }\n\n dtlsTransport = transceiver.dtlsTransport;\n\n this.setRemoteRTP(transceiver, remoteMedia, remoteSdp.type, i);\n } else if (remoteMedia.kind === \"application\") {\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n }\n\n if (bundle) {\n if (!bundleTransport) {\n bundleTransport = this.sctpTransport.dtlsTransport;\n } else {\n this.sctpTransport.setDtlsTransport(bundleTransport);\n }\n }\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n\n this.setRemoteSCTP(remoteMedia, this.sctpTransport);\n } else {\n throw new Error(\"invalid media kind\");\n }\n\n const iceTransport = dtlsTransport.iceTransport;\n\n if (remoteMedia.iceParams && remoteMedia.dtlsParams) {\n iceTransport.setRemoteParams(remoteMedia.iceParams);\n dtlsTransport.setRemoteParams(remoteMedia.dtlsParams);\n\n // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role\n // RFC 8445 S6.1.1\n if (remoteMedia.iceParams?.iceLite) {\n iceTransport.connection.iceControlling = true;\n }\n }\n\n // # add ICE candidates\n remoteMedia.iceCandidates.forEach(iceTransport.addRemoteCandidate);\n\n await iceTransport.iceGather.gather();\n\n if (remoteMedia.iceCandidatesComplete) {\n await iceTransport.addRemoteCandidate(undefined);\n }\n\n // # set DTLS role\n if (remoteSdp.type === \"answer\" && remoteMedia.dtlsParams?.role) {\n dtlsTransport.role =\n remoteMedia.dtlsParams.role === \"client\" ? \"server\" : \"client\";\n }\n })\n );\n\n // connect transports\n if (remoteSdp.type === \"answer\") {\n log(\"caller start connect\");\n this.connect().catch((err) => {\n log(\"connect failed\", err);\n this.setConnectionState(\"failed\");\n });\n }\n\n if (remoteSdp.type === \"offer\") {\n this.setSignalingState(\"have-remote-offer\");\n } else if (remoteSdp.type === \"answer\") {\n this.setSignalingState(\"stable\");\n }\n\n this.negotiationneeded = false;\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\n }\n }\n\n private setRemoteRTP(\n transceiver: RTCRtpTransceiver,\n remoteMedia: MediaDescription,\n type: \"offer\" | \"answer\",\n mLineIndex: number\n ) {\n if (!transceiver.mid) {\n transceiver.mid = remoteMedia.rtp.muxId;\n transceiver.mLineIndex = mLineIndex;\n }\n\n // # negotiate codecs\n transceiver.codecs = remoteMedia.rtp.codecs.filter((remoteCodec) => {\n const localCodecs = this.configuration.codecs[remoteMedia.kind] || [];\n\n const existCodec = findCodecByMimeType(localCodecs, remoteCodec);\n if (!existCodec) return false;\n\n if (existCodec?.name.toLowerCase() === \"rtx\") {\n const params = codecParametersFromString(existCodec.parameters ?? \"\");\n const pt = params[\"apt\"];\n const origin = remoteMedia.rtp.codecs.find((c) => c.payloadType === pt);\n if (!origin) return false;\n return !!findCodecByMimeType(localCodecs, origin);\n }\n\n return true;\n });\n\n log(\"negotiated codecs\", transceiver.codecs);\n if (transceiver.codecs.length === 0) {\n throw new Error(\"negotiate codecs failed.\");\n }\n transceiver.headerExtensions = remoteMedia.rtp.headerExtensions.filter(\n (extension) =>\n (\n this.configuration.headerExtensions[\n remoteMedia.kind as \"video\" | \"audio\"\n ] || []\n ).find((v) => v.uri === extension.uri)\n );\n\n // # configure direction\n const mediaDirection = remoteMedia.direction || \"inactive\";\n const direction = reverseDirection(mediaDirection);\n if ([\"answer\", \"pranswer\"].includes(type)) {\n transceiver.currentDirection = direction;\n } else {\n transceiver.offerDirection = direction;\n }\n\n const localParams = this.getLocalRtpParams(transceiver);\n transceiver.sender.prepareSend(localParams);\n\n if ([\"recvonly\", \"sendrecv\"].includes(transceiver.direction)) {\n const remotePrams = this.getRemoteRtpParams(remoteMedia, transceiver);\n\n // register simulcast receiver\n remoteMedia.simulcastParameters.forEach((param) => {\n this.router.registerRtpReceiverByRid(transceiver, param, remotePrams);\n });\n\n transceiver.receiver.prepareReceive(remotePrams);\n // register ssrc receiver\n this.router.registerRtpReceiverBySsrc(transceiver, remotePrams);\n }\n if ([\"sendonly\", \"sendrecv\"].includes(mediaDirection)) {\n // assign msid\n if (remoteMedia.msid != undefined) {\n const [streamId, trackId] = remoteMedia.msid.split(\" \");\n transceiver.receiver.remoteStreamId = streamId;\n transceiver.receiver.remoteTrackId = trackId;\n\n this.fireOnTrack(\n transceiver.receiver.track,\n transceiver,\n new MediaStream({\n id: streamId,\n tracks: [transceiver.receiver.track],\n })\n );\n }\n }\n\n transceiver.receiver.setupTWCC(remoteMedia.ssrc[0]?.ssrc);\n }\n\n private setRemoteSCTP(\n remoteMedia: MediaDescription,\n sctpTransport: RTCSctpTransport\n ) {\n // # configure sctp\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n\n sctpTransport.setRemotePort(this.sctpRemotePort);\n if (!sctpTransport.mid) {\n sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n private validateDescription(\n description: SessionDescription,\n isLocal: boolean\n ) {\n if (isLocal) {\n if (description.type === \"offer\") {\n if (![\"stable\", \"have-local-offer\"].includes(this.signalingState))\n throw new Error(\"Cannot handle offer in signaling state\");\n } else if (description.type === \"answer\") {\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"Cannot handle answer in signaling state\");\n }\n }\n } else {\n if (description.type === \"offer\") {\n if (![\"stable\", \"have-remote-offer\"].includes(this.signalingState)) {\n throw new Error(\"Cannot handle offer in signaling state\");\n }\n } else if (description.type === \"answer\") {\n if (\n ![\"have-local-offer\", \"have-remote-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"Cannot handle answer in signaling state\");\n }\n }\n }\n\n description.media.forEach((media) => {\n if (media.direction === \"inactive\") return;\n if (\n !media.iceParams ||\n !media.iceParams.usernameFragment ||\n !media.iceParams.password\n )\n throw new Error(\"ICE username fragment or password is missing\");\n });\n\n if ([\"answer\", \"pranswer\"].includes(description.type || \"\")) {\n const offer = isLocal ? this._remoteDescription : this._localDescription;\n if (!offer) throw new Error();\n\n const offerMedia = offer.media.map((v) => [v.kind, v.rtp.muxId]);\n const answerMedia = description.media.map((v) => [v.kind, v.rtp.muxId]);\n if (!isEqual(offerMedia, answerMedia))\n throw new Error(\"Media sections in answer do not match offer\");\n }\n }\n\n private fireOnTrack(\n track: MediaStreamTrack,\n transceiver: RTCRtpTransceiver,\n stream: MediaStream\n ) {\n const event: RTCTrackEvent = {\n track,\n streams: [stream],\n transceiver,\n receiver: transceiver.receiver,\n };\n this.emit(\"track\", event);\n if (this.ontrack) this.ontrack(event);\n }\n\n addTransceiver(\n trackOrKind: Kind | MediaStreamTrack,\n options: Partial<TransceiverOptions> = {}\n ) {\n const kind =\n typeof trackOrKind === \"string\" ? trackOrKind : trackOrKind.kind;\n\n const direction = options.direction || \"sendrecv\";\n\n const dtlsTransport = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n\n const sender = new RTCRtpSender(trackOrKind);\n const receiver = new RTCRtpReceiver(kind, sender.ssrc);\n const transceiver = new RTCRtpTransceiver(\n kind,\n dtlsTransport,\n receiver,\n sender,\n direction\n );\n transceiver.options = options;\n this.router.registerRtpSender(transceiver.sender);\n\n this.transceivers.push(transceiver);\n this.onTransceiverAdded.execute(transceiver);\n\n this.updateIceConnectionState();\n this.needNegotiation();\n\n return transceiver;\n }\n\n getTransceivers() {\n return this.transceivers;\n }\n\n getSenders(): RTCRtpSender[] {\n return this.getTransceivers().map((t) => t.sender);\n }\n\n getReceivers() {\n return this.getTransceivers().map((t) => t.receiver);\n }\n\n // todo fix\n addTrack(\n track: MediaStreamTrack,\n /**todo impl */\n ms?: MediaStream\n ) {\n if (this.isClosed) throw new Error(\"is closed\");\n if (this.getSenders().find((sender) => sender.track?.uuid === track.uuid)) {\n throw new Error(\"track exist\");\n }\n\n const emptyTrackSender = this.transceivers.find(\n (t) =>\n t.sender.track == undefined &&\n t.kind === track.kind &&\n SenderDirections.includes(t.direction) === true\n );\n if (emptyTrackSender) {\n const sender = emptyTrackSender.sender;\n sender.registerTrack(track);\n this.needNegotiation();\n return sender;\n }\n\n const notSendTransceiver = this.transceivers.find(\n (t) =>\n t.sender.track == undefined &&\n t.kind === track.kind &&\n SenderDirections.includes(t.direction) === false &&\n !t.usedForSender\n );\n if (notSendTransceiver) {\n const sender = notSendTransceiver.sender;\n sender.registerTrack(track);\n switch (notSendTransceiver.direction) {\n case \"recvonly\":\n notSendTransceiver.direction = \"sendrecv\";\n break;\n case \"inactive\":\n notSendTransceiver.direction = \"sendonly\";\n break;\n }\n this.needNegotiation();\n return sender;\n } else {\n const transceiver = this.addTransceiver(track, { direction: \"sendrecv\" });\n this.needNegotiation();\n return transceiver.sender;\n }\n }\n\n private async ensureCerts() {\n const ensureCert = async (dtlsTransport: RTCDtlsTransport) => {\n if (this.certificates.length === 0) {\n const localCertificate = await dtlsTransport.setupCertificate();\n this.certificates.push(localCertificate);\n } else {\n dtlsTransport.localCertificate = this.certificates[0];\n }\n };\n\n for (const dtlsTransport of this.dtlsTransports) {\n await ensureCert(dtlsTransport);\n }\n }\n\n async createAnswer() {\n this.assertNotClosed();\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n )\n ) {\n throw new Error(\"createAnswer failed\");\n }\n if (!this._remoteDescription) {\n throw new Error(\"wrong state\");\n }\n\n await this.ensureCerts();\n\n const description = new SessionDescription();\n addSDPHeader(\"answer\", description);\n\n this._remoteDescription.media.forEach((remoteMedia) => {\n let dtlsTransport!: RTCDtlsTransport;\n let media: MediaDescription;\n\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n const transceiver = this.getTransceiverByMid(remoteMedia.rtp.muxId!)!;\n media = createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n andDirection(transceiver.direction, transceiver.offerDirection),\n transceiver.mid!\n );\n dtlsTransport = transceiver.dtlsTransport;\n } else if (remoteMedia.kind === \"application\") {\n if (!this.sctpTransport || !this.sctpTransport.mid) {\n throw new Error(\"sctpTransport not found\");\n }\n media = createMediaDescriptionForSctp(\n this.sctpTransport,\n this.sctpTransport.mid\n );\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n } else {\n throw new Error(\"invalid kind\");\n }\n\n // # determine DTLS role, or preserve the currently configured role\n if (!media.dtlsParams) {\n throw new Error(\"dtlsParams missing\");\n }\n if (dtlsTransport.role === \"auto\") {\n media.dtlsParams.role = \"client\";\n } else {\n media.dtlsParams.role = dtlsTransport.role;\n }\n\n media.simulcastParameters = remoteMedia.simulcastParameters.map((v) => ({\n ...v,\n direction: reverseSimulcastDirection(v.direction),\n }));\n\n description.media.push(media);\n });\n\n if (this.configuration.bundlePolicy !== \"disable\") {\n const bundle = new GroupDescription(\"BUNDLE\", []);\n description.media.forEach((media) => {\n bundle.items.push(media.rtp.muxId!);\n });\n description.group.push(bundle);\n }\n\n return description.toJSON();\n }\n\n async close() {\n if (this.isClosed) return;\n\n this.isClosed = true;\n this.setSignalingState(\"closed\");\n this.setConnectionState(\"closed\");\n\n this.transceivers.forEach((transceiver) => {\n transceiver.receiver.stop();\n transceiver.sender.stop();\n });\n\n if (this.sctpTransport) {\n await this.sctpTransport.stop();\n }\n for (const dtlsTransport of this.dtlsTransports) {\n await dtlsTransport.stop();\n await dtlsTransport.iceTransport.stop();\n }\n\n this.dispose();\n log(\"peerConnection closed\");\n }\n\n private assertNotClosed() {\n if (this.isClosed) {\n throw new Error(\"RTCPeerConnection is closed\");\n }\n }\n\n // https://w3c.github.io/webrtc-pc/#dom-rtcicegatheringstate\n private updateIceGatheringState() {\n const all = this.iceTransports;\n\n function allMatch(...state: IceGathererState[]) {\n return (\n all.filter((check) => state.includes(check.iceGather.gatheringState))\n .length === all.length\n );\n }\n\n let newState: IceGathererState;\n\n if (all.length && allMatch(\"complete\")) {\n newState = \"complete\";\n } else if (!all.length || allMatch(\"new\", \"complete\")) {\n newState = \"new\";\n } else if (\n all.map((check) => check.iceGather.gatheringState).includes(\"gathering\")\n ) {\n newState = \"gathering\";\n } else {\n newState = \"new\";\n }\n\n if (this.iceGatheringState === newState) {\n return;\n }\n\n log(\"iceGatheringStateChange\", newState);\n this.iceGatheringState = newState;\n this.iceGatheringStateChange.execute(newState);\n this.emit(\"icegatheringstatechange\", newState);\n }\n\n // https://w3c.github.io/webrtc-pc/#dom-rtciceconnectionstate\n private updateIceConnectionState() {\n const all = this.iceTransports;\n let newState: RTCIceConnectionState;\n\n function allMatch(...state: RTCIceConnectionState[]) {\n return (\n all.filter((check) => state.includes(check.state)).length === all.length\n );\n }\n\n if (this.connectionState === \"closed\") {\n newState = \"closed\";\n } else if (allMatch(\"failed\")) {\n newState = \"failed\";\n } else if (allMatch(\"disconnected\")) {\n newState = \"disconnected\";\n } else if (allMatch(\"new\", \"closed\")) {\n newState = \"new\";\n } else if (allMatch(\"new\", \"checking\")) {\n newState = \"checking\";\n } else if (allMatch(\"completed\", \"closed\")) {\n newState = \"completed\";\n } else if (allMatch(\"connected\", \"completed\", \"closed\")) {\n newState = \"connected\";\n } else {\n // unreachable?\n newState = \"new\";\n }\n\n if (this.iceConnectionState === newState) {\n return;\n }\n\n log(\"iceConnectionStateChange\", newState);\n this.iceConnectionState = newState;\n this.iceConnectionStateChange.execute(newState);\n this.emit(\"iceconnectionstatechange\", newState);\n }\n\n private setSignalingState(state: RTCSignalingState) {\n log(\"signalingStateChange\", state);\n this.signalingState = state;\n this.signalingStateChange.execute(state);\n if (this.onsignalingstatechange) this.onsignalingstatechange({});\n }\n\n private setConnectionState(state: ConnectionState) {\n log(\"connectionStateChange\", state);\n this.connectionState = state;\n this.connectionStateChange.execute(state);\n if (this.onconnectionstatechange) this.onconnectionstatechange();\n this.emit(\"connectionstatechange\");\n }\n\n private dispose() {\n this.onDataChannel.allUnsubscribe();\n this.iceGatheringStateChange.allUnsubscribe();\n this.iceConnectionStateChange.allUnsubscribe();\n this.signalingStateChange.allUnsubscribe();\n this.onTransceiverAdded.allUnsubscribe();\n this.onRemoteTransceiverAdded.allUnsubscribe();\n this.onIceCandidate.allUnsubscribe();\n }\n}\n\nexport function createMediaDescriptionForTransceiver(\n transceiver: RTCRtpTransceiver,\n cname: string,\n direction: Direction,\n mid: string\n) {\n const media = new MediaDescription(\n transceiver.kind,\n 9,\n \"UDP/TLS/RTP/SAVPF\",\n transceiver.codecs.map((c) => c.payloadType)\n );\n media.direction = direction;\n media.msid = transceiver.msid;\n media.rtp = {\n codecs: transceiver.codecs,\n headerExtensions: transceiver.headerExtensions,\n muxId: mid,\n };\n media.rtcpHost = \"0.0.0.0\";\n media.rtcpPort = 9;\n media.rtcpMux = true;\n media.ssrc = [new SsrcDescription({ ssrc: transceiver.sender.ssrc, cname })];\n\n if (transceiver.options.simulcast) {\n media.simulcastParameters = transceiver.options.simulcast.map(\n (o) => new RTCRtpSimulcastParameters(o)\n );\n }\n\n if (media.rtp.codecs.find((c) => c.name.toLowerCase() === \"rtx\")) {\n media.ssrc.push(\n new SsrcDescription({ ssrc: transceiver.sender.rtxSsrc, cname })\n );\n media.ssrcGroup = [\n new GroupDescription(\"FID\", [\n transceiver.sender.ssrc.toString(),\n transceiver.sender.rtxSsrc.toString(),\n ]),\n ];\n }\n\n addTransportDescription(media, transceiver.dtlsTransport);\n return media;\n}\n\nexport function createMediaDescriptionForSctp(\n sctp: RTCSctpTransport,\n mid: string\n) {\n const media = new MediaDescription(\n \"application\",\n DISCARD_PORT,\n \"UDP/DTLS/SCTP\",\n [\"webrtc-datachannel\"]\n );\n media.sctpPort = sctp.port;\n media.rtp.muxId = mid;\n media.sctpCapabilities = RTCSctpTransport.getCapabilities();\n\n addTransportDescription(media, sctp.dtlsTransport);\n return media;\n}\n\nexport function addTransportDescription(\n media: MediaDescription,\n dtlsTransport: RTCDtlsTransport\n) {\n const iceTransport = dtlsTransport.iceTransport;\n const iceGatherer = iceTransport.iceGather;\n\n media.iceCandidates = iceGatherer.localCandidates;\n media.iceCandidatesComplete = iceGatherer.gatheringState === \"complete\";\n media.iceParams = iceGatherer.localParameters;\n media.iceOptions = \"trickle\";\n\n if (media.iceCandidates.length > 0) {\n const candidate = media.iceCandidates[media.iceCandidates.length - 1];\n media.host = candidate.ip;\n media.port = candidate.port;\n } else {\n media.host = DISCARD_HOST;\n media.port = DISCARD_PORT;\n }\n\n if (media.direction === \"inactive\") {\n media.port = 0;\n }\n\n if (!media.dtlsParams) {\n media.dtlsParams = dtlsTransport.localParameters;\n if (!media.dtlsParams.fingerprints) {\n media.dtlsParams.fingerprints =\n dtlsTransport.localParameters.fingerprints;\n }\n }\n}\n\nexport function allocateMid(mids: Set<string>) {\n let mid = \"\";\n for (let i = 0; ; ) {\n mid = (i++).toString();\n if (!mids.has(mid)) break;\n }\n mids.add(mid);\n return mid;\n}\n\nexport type BundlePolicy = \"max-compat\" | \"max-bundle\" | \"disable\";\n\nexport interface PeerConfig {\n codecs: Partial<{\n /**\n * When specifying a codec with a fixed payloadType such as PCMU,\n * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.\n */\n audio: RTCRtpCodecParameters[];\n video: RTCRtpCodecParameters[];\n }>;\n headerExtensions: Partial<{\n audio: RTCRtpHeaderExtensionParameters[];\n video: RTCRtpHeaderExtensionParameters[];\n }>;\n iceTransportPolicy: \"all\" | \"relay\";\n iceServers: RTCIceServer[];\n /**Minimum port and Maximum port must not be the same value */\n icePortRange: [number, number] | undefined;\n dtls: Partial<{\n keys: DtlsKeys;\n }>;\n bundlePolicy: BundlePolicy;\n}\n\nexport const findCodecByMimeType = (\n codecs: RTCRtpCodecParameters[],\n target: RTCRtpCodecParameters\n) =>\n codecs.find(\n (localCodec) =>\n localCodec.mimeType.toLowerCase() === target.mimeType.toLowerCase()\n )\n ? target\n : undefined;\n\nexport type RTCIceServer = {\n urls: string;\n username?: string;\n credential?: string;\n};\n\nexport const defaultPeerConfig: PeerConfig = {\n codecs: {\n audio: [\n new RTCRtpCodecParameters({\n mimeType: \"audio/opus\",\n clockRate: 48000,\n channels: 2,\n }),\n new RTCRtpCodecParameters({\n mimeType: \"audio/PCMU\",\n clockRate: 8000,\n channels: 1,\n payloadType: 0,\n }),\n ],\n video: [\n new RTCRtpCodecParameters({\n mimeType: \"video/VP8\",\n clockRate: 90000,\n rtcpFeedback: [\n { type: \"ccm\", parameter: \"fir\" },\n { type: \"nack\" },\n { type: \"nack\", parameter: \"pli\" },\n { type: \"goog-remb\" },\n ],\n }),\n ],\n },\n headerExtensions: { audio: [], video: [] },\n iceTransportPolicy: \"all\",\n iceServers: [{ urls: \"stun:stun.l.google.com:19302\" }],\n icePortRange: undefined,\n dtls: {},\n bundlePolicy: \"max-compat\",\n};\n\nexport interface RTCTrackEvent {\n track: MediaStreamTrack;\n streams: MediaStream[];\n transceiver: RTCRtpTransceiver;\n receiver: RTCRtpReceiver;\n}\n\nexport interface RTCDataChannelEvent {\n channel: RTCDataChannel;\n}\n\nexport interface RTCPeerConnectionIceEvent {\n candidate: RTCIceCandidate;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "werift",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "WebRTC Implementation for TypeScript (Node.js)",
5
5
  "keywords": [
6
6
  "WebRTC",
@@ -24,6 +24,10 @@ export class RTCRtpCodecCapability {
24
24
  export type RTCPFB = { type: string; parameter?: string };
25
25
 
26
26
  export class RTCRtpCodecParameters {
27
+ /**
28
+ * When specifying a codec with a fixed payloadType such as PCMU,
29
+ * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.
30
+ */
27
31
  payloadType!: number;
28
32
  mimeType!: string;
29
33
  clockRate!: number;
@@ -144,6 +144,10 @@ export class RTCPeerConnection extends EventTarget {
144
144
  ...(this.configuration.codecs.audio || []),
145
145
  ...(this.configuration.codecs.video || []),
146
146
  ])) {
147
+ if (codecParams.payloadType != undefined) {
148
+ continue;
149
+ }
150
+
147
151
  codecParams.payloadType = 96 + i;
148
152
  switch (codecParams.name.toLowerCase()) {
149
153
  case "rtx":
@@ -1387,6 +1391,10 @@ export type BundlePolicy = "max-compat" | "max-bundle" | "disable";
1387
1391
 
1388
1392
  export interface PeerConfig {
1389
1393
  codecs: Partial<{
1394
+ /**
1395
+ * When specifying a codec with a fixed payloadType such as PCMU,
1396
+ * it is necessary to set the correct PayloadType in RTCRtpCodecParameters in advance.
1397
+ */
1390
1398
  audio: RTCRtpCodecParameters[];
1391
1399
  video: RTCRtpCodecParameters[];
1392
1400
  }>;
@@ -1433,6 +1441,7 @@ export const defaultPeerConfig: PeerConfig = {
1433
1441
  mimeType: "audio/PCMU",
1434
1442
  clockRate: 8000,
1435
1443
  channels: 1,
1444
+ payloadType: 0,
1436
1445
  }),
1437
1446
  ],
1438
1447
  video: [