werift 0.14.2-debug1 → 0.14.2-debug2a

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.
@@ -557,13 +557,13 @@ class RTCPeerConnection extends helper_1.EventTarget {
557
557
  else if (remoteMedia.kind === "application") {
558
558
  // # configure sctp
559
559
  this.sctpRemotePort = remoteMedia.sctpPort;
560
+ if (!this.sctpRemotePort) {
561
+ throw new Error("sctpRemotePort not exist");
562
+ }
560
563
  if (!this.sctpTransport) {
561
- if (!this.sctpRemotePort) {
562
- throw new Error("sctpRemotePort not exist");
563
- }
564
564
  this.sctpTransport = this.createSctpTransport();
565
- this.sctpTransport.setRemotePort(this.sctpRemotePort);
566
565
  }
566
+ this.sctpTransport.setRemotePort(this.sctpRemotePort);
567
567
  if (!this.sctpTransport.mid) {
568
568
  this.sctpTransport.mid = remoteMedia.rtp.muxId;
569
569
  }
@@ -1 +1 @@
1
- {"version":3,"file":"peerConnection.js","sourceRoot":"","sources":["../../../src/peerConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,mCAA4C;AAC5C,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;IA+ChD,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,IAAI,MACmB,EAAE;QACzB,KAAK,EAAE,CAAC;QAtDD,UAAK,GAAG,IAAI,CAAC,EAAE,EAAE,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AAA,mBAAmB,uBAShB;AAQH,QAAA,iBAAiB,GAAe;IAC3C,MAAM,EAAE;QACN,KAAK,EAAE;YACL,IAAI,kCAAqB,CAAC;gBACxB,QAAQ,EAAE,YAAY;gBACtB,SAAS,EAAE,KAAK;gBAChB,QAAQ,EAAE,CAAC;aACZ,CAAC;YACF,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;CACT,CAAC","sourcesContent":["import debug from \"debug\";\nimport { cloneDeep, isEqual } from \"lodash\";\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 iceTransport: RTCIceTransport;\n dtlsTransport: RTCDtlsTransport;\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 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 /**\n * should use onRemoteTransceiverAdded\n * @deprecated\n */\n readonly onTransceiver = 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 constructor({\n codecs,\n headerExtensions,\n iceServers,\n iceTransportPolicy,\n icePortRange,\n dtls,\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\n const { iceTransport, dtlsTransport } = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n this.iceTransport = iceTransport;\n this.dtlsTransport = dtlsTransport;\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 if (this.certificates.length === 0) {\n await this.dtlsTransport.setupCertificate();\n }\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 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 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 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 return new RTCDataChannel(this.sctpTransport, parameters);\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 iceGatherer = new RTCIceGatherer({\n ...parseIceServers(this.configuration.iceServers),\n forceTurn: this.configuration.iceTransportPolicy === \"relay\",\n portRange: this.configuration.icePortRange,\n });\n iceGatherer.onGatheringStateChange.subscribe((state) => {\n this.updateIceGatheringState(state);\n });\n this.updateIceGatheringState(iceGatherer.gatheringState);\n const iceTransport = new RTCIceTransport(iceGatherer);\n iceTransport.onStateChange.subscribe((state) => {\n this.updateIceConnectionState(state);\n });\n this.updateIceConnectionState(iceTransport.state);\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 // for chrome & firefox & maybe others\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, iceTransport };\n }\n\n private createSctpTransport() {\n const sctp = new RTCSctpTransport(this.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 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 if (!mid) {\n throw new Error(\"mid not exist\");\n }\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 // # set ICE role\n if (description.type === \"offer\") {\n this.iceTransport.connection.iceControlling = true;\n } else {\n this.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 (this.iceTransport.connection.remoteIsLite) {\n this.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 this.dtlsTransport.role = role;\n }\n }\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 await this.iceTransport.iceGather.gather();\n description.media.map((media) => {\n addTransportDescription(media, this.dtlsTransport);\n });\n\n this.setLocal(description);\n\n // connect transports\n if (description.type === \"answer\") {\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 await this.iceTransport.addRemoteCandidate(candidate);\n }\n\n private async connect() {\n if (this.masterTransportEstablished) return;\n\n const dtlsTransport = this.dtlsTransport;\n const iceTransport = dtlsTransport.iceTransport;\n\n this.setConnectionState(\"connecting\");\n\n await iceTransport.start().catch((err) => {\n log(\"iceTransport.start failed\", err);\n throw err;\n });\n log(\"ice connected\");\n await dtlsTransport.start().catch((err) => {\n log(\"dtlsTransport.start failed\", err);\n throw err;\n });\n log(\"dtls connected\");\n\n if (this.sctpTransport && this.sctpRemotePort) {\n await this.sctpTransport.start(this.sctpRemotePort);\n await this.sctpTransport.sctp.stateChanged.connected.asPromise();\n }\n\n this.masterTransportEstablished = true;\n this.setConnectionState(\"connected\");\n }\n\n private localRtp(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 remoteRtp(\n remoteDescription: SessionDescription,\n transceiver: RTCRtpTransceiver\n ): RTCRtpReceiveParameters {\n if (transceiver.mLineIndex == undefined)\n throw new Error(\"mLineIndex not assigned\");\n const media = remoteDescription.media[transceiver.mLineIndex];\n if (!media) throw new Error(\"media line not exist\");\n\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 // # apply description\n for (const [i, remoteMedia] of enumerate(remoteSdp.media)) {\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n const transceiver =\n this.transceivers.find(\n (t) =>\n t.kind === remoteMedia.kind &&\n [undefined, remoteMedia.rtp.muxId].includes(t.mid)\n ) ||\n (() => {\n // create remote transceiver\n const transceiver = this.addTransceiver(remoteMedia.kind, {\n direction: \"recvonly\",\n });\n\n this.onRemoteTransceiverAdded.execute(transceiver);\n this.onTransceiver.execute(transceiver);\n\n return transceiver;\n })();\n\n if (!transceiver.mid) {\n transceiver.mid = remoteMedia.rtp.muxId;\n transceiver.mLineIndex = i;\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(\n existCodec.parameters ?? \"\"\n );\n const pt = params[\"apt\"];\n const origin = remoteMedia.rtp.codecs.find(\n (c) => c.payloadType === pt\n );\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(remoteSdp.type)) {\n transceiver.currentDirection = direction;\n } else {\n transceiver.offerDirection = direction;\n }\n\n const localParams = this.localRtp(transceiver);\n transceiver.sender.prepareSend(localParams);\n\n if ([\"recvonly\", \"sendrecv\"].includes(transceiver.direction)) {\n const remotePrams = this.remoteRtp(remoteSdp, transceiver);\n\n // register simulcast receiver\n remoteMedia.simulcastParameters.forEach((param) => {\n this.router.registerRtpReceiverByRid(\n transceiver,\n param,\n remotePrams\n );\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 } else if (remoteMedia.kind === \"application\") {\n // # configure sctp\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpTransport) {\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n this.sctpTransport = this.createSctpTransport();\n this.sctpTransport.setRemotePort(this.sctpRemotePort);\n }\n if (!this.sctpTransport.mid) {\n this.sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n if (remoteMedia.iceParams && remoteMedia.dtlsParams) {\n this.iceTransport.setRemoteParams(remoteMedia.iceParams);\n this.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 this.iceTransport.connection.iceControlling = true;\n }\n }\n\n // # add ICE candidates\n remoteMedia.iceCandidates.forEach(this.iceTransport.addRemoteCandidate);\n\n await this.iceTransport.iceGather.gather();\n\n if (remoteMedia.iceCandidatesComplete) {\n await this.iceTransport.addRemoteCandidate(undefined);\n }\n\n // # set DTLS role\n if (remoteSdp.type === \"answer\" && remoteMedia.dtlsParams?.role) {\n this.dtlsTransport.role =\n remoteMedia.dtlsParams.role === \"client\" ? \"server\" : \"client\";\n }\n }\n\n // connect transports\n if (remoteSdp.type === \"answer\") {\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 if (remoteSdp.type === \"answer\") {\n this.currentRemoteDescription = remoteSdp;\n this.pendingRemoteDescription = undefined;\n } else {\n this.pendingRemoteDescription = remoteSdp;\n }\n\n this.negotiationneeded = false;\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\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 sender = new RTCRtpSender(trackOrKind, this.dtlsTransport);\n const receiver = new RTCRtpReceiver(kind, this.dtlsTransport, sender.ssrc);\n const transceiver = new RTCRtpTransceiver(\n kind,\n receiver,\n sender,\n direction,\n this.dtlsTransport\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.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 async createAnswer() {\n this.assertNotClosed();\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n ) ||\n !this.dtlsTransport\n )\n throw new Error(\"createAnswer failed\");\n\n if (this.certificates.length === 0) {\n await this.dtlsTransport.setupCertificate();\n }\n\n const description = new SessionDescription();\n addSDPHeader(\"answer\", description);\n\n this._remoteDescription?.media.forEach((remoteM) => {\n let dtlsTransport!: RTCDtlsTransport;\n let media: MediaDescription;\n\n if ([\"audio\", \"video\"].includes(remoteM.kind)) {\n const transceiver = this.getTransceiverByMid(remoteM.rtp.muxId!)!;\n media = createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n andDirection(transceiver.direction, transceiver.offerDirection),\n transceiver.mid!\n );\n if (!transceiver.dtlsTransport) throw new Error();\n dtlsTransport = transceiver.dtlsTransport;\n } else if (remoteM.kind === \"application\") {\n if (!this.sctpTransport || !this.sctpTransport.mid) throw new Error();\n media = createMediaDescriptionForSctp(\n this.sctpTransport,\n this.sctpTransport.mid\n );\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n } else throw new Error();\n\n // # determine DTLS role, or preserve the currently configured role\n if (!media.dtlsParams) throw new Error();\n if (dtlsTransport.role === \"auto\") {\n media.dtlsParams.role = \"client\";\n } else {\n media.dtlsParams.role = dtlsTransport.role;\n }\n media.simulcastParameters = remoteM.simulcastParameters.map((v) => ({\n ...v,\n direction: reverseSimulcastDirection(v.direction),\n }));\n description.media.push(media);\n });\n\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 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 await this.dtlsTransport.stop();\n await this.iceTransport.stop();\n\n this.dispose();\n log(\"peerConnection closed\");\n }\n\n private assertNotClosed() {\n if (this.isClosed) throw new Error(\"RTCPeerConnection is closed\");\n }\n\n private updateIceGatheringState(state: IceGathererState) {\n log(\"iceGatheringStateChange\", state);\n this.iceGatheringState = state;\n this.iceGatheringStateChange.execute(state);\n this.emit(\"icegatheringstatechange\", state);\n }\n\n private updateIceConnectionState(state: RTCIceConnectionState) {\n log(\"iceConnectionStateChange\", state);\n this.iceConnectionState = state;\n this.iceConnectionStateChange.execute(state);\n this.emit(\"iceconnectionstatechange\", state);\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 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}\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};\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,mCAA4C;AAC5C,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;IA+ChD,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,IAAI,MACmB,EAAE;QACzB,KAAK,EAAE,CAAC;QAtDD,UAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAI3B,+BAA0B,GAAG,KAAK,CAAC;QACnC,kBAAa,GACX,IAAA,kBAAS,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;QACvC,4BAAuB,GAAG,IAAI,iBAAK,EAAsB,CAAC;QAC1D,6BAAwB,GAAG,IAAI,iBAAK,EAA2B,CAAC;QAChE,yBAAoB,GAAG,IAAI,iBAAK,EAAuB,CAAC;QACxD,0BAAqB,GAAG,IAAI,iBAAK,EAAqB,CAAC;QACvD,kBAAa,GAAG,IAAI,iBAAK,EAAoB,CAAC;QAC9C,6BAAwB,G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AE,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;CACT,CAAC","sourcesContent":["import debug from \"debug\";\nimport { cloneDeep, isEqual } from \"lodash\";\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 iceTransport: RTCIceTransport;\n dtlsTransport: RTCDtlsTransport;\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 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 /**\n * should use onRemoteTransceiverAdded\n * @deprecated\n */\n readonly onTransceiver = 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 constructor({\n codecs,\n headerExtensions,\n iceServers,\n iceTransportPolicy,\n icePortRange,\n dtls,\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\n const { iceTransport, dtlsTransport } = this.createTransport([\n SRTP_PROFILE.SRTP_AEAD_AES_128_GCM, // prefer\n SRTP_PROFILE.SRTP_AES128_CM_HMAC_SHA1_80,\n ]);\n this.iceTransport = iceTransport;\n this.dtlsTransport = dtlsTransport;\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 if (this.certificates.length === 0) {\n await this.dtlsTransport.setupCertificate();\n }\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 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 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 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 return new RTCDataChannel(this.sctpTransport, parameters);\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 iceGatherer = new RTCIceGatherer({\n ...parseIceServers(this.configuration.iceServers),\n forceTurn: this.configuration.iceTransportPolicy === \"relay\",\n portRange: this.configuration.icePortRange,\n });\n iceGatherer.onGatheringStateChange.subscribe((state) => {\n this.updateIceGatheringState(state);\n });\n this.updateIceGatheringState(iceGatherer.gatheringState);\n const iceTransport = new RTCIceTransport(iceGatherer);\n iceTransport.onStateChange.subscribe((state) => {\n this.updateIceConnectionState(state);\n });\n this.updateIceConnectionState(iceTransport.state);\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 // for chrome & firefox & maybe others\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, iceTransport };\n }\n\n private createSctpTransport() {\n const sctp = new RTCSctpTransport(this.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 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 if (!mid) {\n throw new Error(\"mid not exist\");\n }\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 // # set ICE role\n if (description.type === \"offer\") {\n this.iceTransport.connection.iceControlling = true;\n } else {\n this.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 (this.iceTransport.connection.remoteIsLite) {\n this.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 this.dtlsTransport.role = role;\n }\n }\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 await this.iceTransport.iceGather.gather();\n description.media.map((media) => {\n addTransportDescription(media, this.dtlsTransport);\n });\n\n this.setLocal(description);\n\n // connect transports\n if (description.type === \"answer\") {\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 await this.iceTransport.addRemoteCandidate(candidate);\n }\n\n private async connect() {\n if (this.masterTransportEstablished) return;\n\n const dtlsTransport = this.dtlsTransport;\n const iceTransport = dtlsTransport.iceTransport;\n\n this.setConnectionState(\"connecting\");\n\n await iceTransport.start().catch((err) => {\n log(\"iceTransport.start failed\", err);\n throw err;\n });\n log(\"ice connected\");\n await dtlsTransport.start().catch((err) => {\n log(\"dtlsTransport.start failed\", err);\n throw err;\n });\n log(\"dtls connected\");\n\n if (this.sctpTransport && this.sctpRemotePort) {\n await this.sctpTransport.start(this.sctpRemotePort);\n await this.sctpTransport.sctp.stateChanged.connected.asPromise();\n }\n\n this.masterTransportEstablished = true;\n this.setConnectionState(\"connected\");\n }\n\n private localRtp(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 remoteRtp(\n remoteDescription: SessionDescription,\n transceiver: RTCRtpTransceiver\n ): RTCRtpReceiveParameters {\n if (transceiver.mLineIndex == undefined)\n throw new Error(\"mLineIndex not assigned\");\n const media = remoteDescription.media[transceiver.mLineIndex];\n if (!media) throw new Error(\"media line not exist\");\n\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 // # apply description\n for (const [i, remoteMedia] of enumerate(remoteSdp.media)) {\n if ([\"audio\", \"video\"].includes(remoteMedia.kind)) {\n const transceiver =\n this.transceivers.find(\n (t) =>\n t.kind === remoteMedia.kind &&\n [undefined, remoteMedia.rtp.muxId].includes(t.mid)\n ) ||\n (() => {\n // create remote transceiver\n const transceiver = this.addTransceiver(remoteMedia.kind, {\n direction: \"recvonly\",\n });\n\n this.onRemoteTransceiverAdded.execute(transceiver);\n this.onTransceiver.execute(transceiver);\n\n return transceiver;\n })();\n\n if (!transceiver.mid) {\n transceiver.mid = remoteMedia.rtp.muxId;\n transceiver.mLineIndex = i;\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(\n existCodec.parameters ?? \"\"\n );\n const pt = params[\"apt\"];\n const origin = remoteMedia.rtp.codecs.find(\n (c) => c.payloadType === pt\n );\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(remoteSdp.type)) {\n transceiver.currentDirection = direction;\n } else {\n transceiver.offerDirection = direction;\n }\n\n const localParams = this.localRtp(transceiver);\n transceiver.sender.prepareSend(localParams);\n\n if ([\"recvonly\", \"sendrecv\"].includes(transceiver.direction)) {\n const remotePrams = this.remoteRtp(remoteSdp, transceiver);\n\n // register simulcast receiver\n remoteMedia.simulcastParameters.forEach((param) => {\n this.router.registerRtpReceiverByRid(\n transceiver,\n param,\n remotePrams\n );\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 } else if (remoteMedia.kind === \"application\") {\n // # configure sctp\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n }\n this.sctpTransport.setRemotePort(this.sctpRemotePort);\n if (!this.sctpTransport.mid) {\n this.sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n if (remoteMedia.iceParams && remoteMedia.dtlsParams) {\n this.iceTransport.setRemoteParams(remoteMedia.iceParams);\n this.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 this.iceTransport.connection.iceControlling = true;\n }\n }\n\n // # add ICE candidates\n remoteMedia.iceCandidates.forEach(this.iceTransport.addRemoteCandidate);\n\n await this.iceTransport.iceGather.gather();\n\n if (remoteMedia.iceCandidatesComplete) {\n await this.iceTransport.addRemoteCandidate(undefined);\n }\n\n // # set DTLS role\n if (remoteSdp.type === \"answer\" && remoteMedia.dtlsParams?.role) {\n this.dtlsTransport.role =\n remoteMedia.dtlsParams.role === \"client\" ? \"server\" : \"client\";\n }\n }\n\n // connect transports\n if (remoteSdp.type === \"answer\") {\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 if (remoteSdp.type === \"answer\") {\n this.currentRemoteDescription = remoteSdp;\n this.pendingRemoteDescription = undefined;\n } else {\n this.pendingRemoteDescription = remoteSdp;\n }\n\n this.negotiationneeded = false;\n if (this.shouldNegotiationneeded) {\n this.needNegotiation();\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 sender = new RTCRtpSender(trackOrKind, this.dtlsTransport);\n const receiver = new RTCRtpReceiver(kind, this.dtlsTransport, sender.ssrc);\n const transceiver = new RTCRtpTransceiver(\n kind,\n receiver,\n sender,\n direction,\n this.dtlsTransport\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.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 async createAnswer() {\n this.assertNotClosed();\n if (\n ![\"have-remote-offer\", \"have-local-pranswer\"].includes(\n this.signalingState\n ) ||\n !this.dtlsTransport\n )\n throw new Error(\"createAnswer failed\");\n\n if (this.certificates.length === 0) {\n await this.dtlsTransport.setupCertificate();\n }\n\n const description = new SessionDescription();\n addSDPHeader(\"answer\", description);\n\n this._remoteDescription?.media.forEach((remoteM) => {\n let dtlsTransport!: RTCDtlsTransport;\n let media: MediaDescription;\n\n if ([\"audio\", \"video\"].includes(remoteM.kind)) {\n const transceiver = this.getTransceiverByMid(remoteM.rtp.muxId!)!;\n media = createMediaDescriptionForTransceiver(\n transceiver,\n this.cname,\n andDirection(transceiver.direction, transceiver.offerDirection),\n transceiver.mid!\n );\n if (!transceiver.dtlsTransport) throw new Error();\n dtlsTransport = transceiver.dtlsTransport;\n } else if (remoteM.kind === \"application\") {\n if (!this.sctpTransport || !this.sctpTransport.mid) throw new Error();\n media = createMediaDescriptionForSctp(\n this.sctpTransport,\n this.sctpTransport.mid\n );\n\n dtlsTransport = this.sctpTransport.dtlsTransport;\n } else throw new Error();\n\n // # determine DTLS role, or preserve the currently configured role\n if (!media.dtlsParams) throw new Error();\n if (dtlsTransport.role === \"auto\") {\n media.dtlsParams.role = \"client\";\n } else {\n media.dtlsParams.role = dtlsTransport.role;\n }\n media.simulcastParameters = remoteM.simulcastParameters.map((v) => ({\n ...v,\n direction: reverseSimulcastDirection(v.direction),\n }));\n description.media.push(media);\n });\n\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 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 await this.dtlsTransport.stop();\n await this.iceTransport.stop();\n\n this.dispose();\n log(\"peerConnection closed\");\n }\n\n private assertNotClosed() {\n if (this.isClosed) throw new Error(\"RTCPeerConnection is closed\");\n }\n\n private updateIceGatheringState(state: IceGathererState) {\n log(\"iceGatheringStateChange\", state);\n this.iceGatheringState = state;\n this.iceGatheringStateChange.execute(state);\n this.emit(\"icegatheringstatechange\", state);\n }\n\n private updateIceConnectionState(state: RTCIceConnectionState) {\n log(\"iceConnectionStateChange\", state);\n this.iceConnectionState = state;\n this.iceConnectionStateChange.execute(state);\n this.emit(\"iceconnectionstatechange\", state);\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 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}\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};\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.14.2-debug1",
3
+ "version": "0.14.2-debug2a",
4
4
  "description": "WebRTC Implementation for TypeScript (Node.js)",
5
5
  "keywords": [
6
6
  "WebRTC",
@@ -740,13 +740,13 @@ export class RTCPeerConnection extends EventTarget {
740
740
  } else if (remoteMedia.kind === "application") {
741
741
  // # configure sctp
742
742
  this.sctpRemotePort = remoteMedia.sctpPort;
743
+ if (!this.sctpRemotePort) {
744
+ throw new Error("sctpRemotePort not exist");
745
+ }
743
746
  if (!this.sctpTransport) {
744
- if (!this.sctpRemotePort) {
745
- throw new Error("sctpRemotePort not exist");
746
- }
747
747
  this.sctpTransport = this.createSctpTransport();
748
- this.sctpTransport.setRemotePort(this.sctpRemotePort);
749
748
  }
749
+ this.sctpTransport.setRemotePort(this.sctpRemotePort);
750
750
  if (!this.sctpTransport.mid) {
751
751
  this.sctpTransport.mid = remoteMedia.rtp.muxId;
752
752
  }