How to use the sdp-transform.parse function in sdp-transform

To help you get started, we’ve selected a few sdp-transform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kurento / mediasoup-demos / mediasoup-kurento-filter / server.js View on Github external
`a=rtcp:${msListenPortRtcp}\r\n` +
    `a=rtpmap:${msPayloadType} VP8/90000\r\n` +
    "a=recvonly\r\n" +
    "";

  const kmsEndpoint = await kmsPipeline.create("RtpEndpoint");
  global.kurento.rtp.sendEndpoint = kmsEndpoint;

  console.log("SDP Offer from App to Kurento RTP SEND: %s\n", kmsSdpOffer);
  const kmsSdpAnswer = await kmsEndpoint.processOffer(kmsSdpOffer);
  console.log("SDP Answer from Kurento RTP SEND to App:\n%s", kmsSdpAnswer);

  // WARNING: A real application would need to parse this SDP Answer and adapt
  // to the parameters given in it, following the SDP Offer/Answer Model.

  const kmsSdpAnswerObj = SdpTransform.parse(kmsSdpAnswer);
  console.log("kmsSdpAnswerObj: %s", JSON.stringify(kmsSdpAnswerObj, null, 2));

  // Build an RtpSendParameters from the Kurento SDP Answer,
  // this gives us the Kurento RTP stream's SSRC, payload type, etc.

  const kmsRtpCapabilities = MediasoupSdpUtils.extractRtpCapabilities({
    sdpObject: kmsSdpAnswerObj
  });
  console.log(
    "kmsRtpCapabilities: %s",
    JSON.stringify(kmsRtpCapabilities, null, 2)
  );

  const msExtendedRtpCapabilities = MediasoupOrtc.getExtendedRtpCapabilities(
    kmsRtpCapabilities,
    global.mediasoup.router.rtpCapabilities
github versatica / mediasoup-client / src / handlers / Chrome74.ts View on Github external
encodings.forEach((encoding: any, idx: number) =>
			{
				encoding.rid = `r${idx}`;
			});
		}

		const mediaSectionIdx = this._remoteSdp.getNextMediaSectionIdx();
		const transceiver = this._pc.addTransceiver(
			track,
			{
				direction     : 'sendonly',
				streams       : [ this._stream ],
				sendEncodings : encodings
			});
		let offer = await this._pc.createOffer();
		let localSdpObject = sdpTransform.parse(offer.sdp);
		let offerMediaObject;
		const sendingRtpParameters =
			utils.clone(this._sendingRtpParametersByKind[track.kind]);

		if (!this._transportReady)
			await this._setupTransport({ localDtlsRole: 'server', localSdpObject });

		logger.debug(
			'send() | calling pc.setLocalDescription() [offer:%o]', offer);

		// Special case for VP9 with SVC.
		let hackVp9Svc = false;

		const layers =
			parseScalabilityMode((encodings || [ {} ])[0].scalabilityMode);
github davehorton / drachtio-siprec-recording-server / lib / freeswitch-call-handler.js View on Github external
function handleLeg2SiprecInvite(req, res, opts) {
  const logger = opts.logger;
  const sessionId = req.get('X-Return-Token');
  debug(`handleLeg2SiprecInvite: sessionId is ${sessionId}`);

  // add a=recvonly
  let sdp = transform.parse(req.body);
  sdp.media[0].direction = 'recvonly';
  sdp = transform.write(sdp);
  exchangeSdp(sessionId, sdp)
    .then((sdp) => req.srf.createUAS(req, res, {localSdp: sdp}))
    .catch((err) => {
      logger.error(err, 'Error replying to leg2 INVITE from Freeswitch');
      res.send(480);
    });
}
github skerit / rudeplay / lib / server / server.js View on Github external
req.getBody(function gotBody(err, buffer) {

		var status_code,
		    conf;

		if (err) {
			throw err;
		}

		// Parse the body, which is just an SDP string
		conf = Sdp.parse(buffer.toString());

		status_code = req.session.setSdp(conf);

		if (status_code != null) {
			res.status_code = status_code;
		}

		res.end();
	});
});
github versatica / mediasoup-client / src / handlers / Safari12.ts View on Github external
priority
		};

		logger.debug('DataChannel options:%o', options);

		const dataChannel = this._pc.createDataChannel(label, options);

		// Increase next id.
		this._nextSctpStreamId = ++this._nextSctpStreamId % SCTP_NUM_STREAMS.MIS;

		// If this is the first DataChannel we need to create the SDP answer with
		// m=application section.
		if (!this._hasDataChannelMediaSection)
		{
			const offer = await this._pc.createOffer();
			const localSdpObject = sdpTransform.parse(offer.sdp);
			const offerMediaObject = localSdpObject.media
				.find((m: any) => m.type === 'application');

			if (!this._transportReady)
				await this._setupTransport({ localDtlsRole: 'server', localSdpObject });

			logger.debug(
				'sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);

			await this._pc.setLocalDescription(offer);

			this._remoteSdp.sendSctpAssociation({ offerMediaObject });

			const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };

			logger.debug(
github versatica / mediasoup-client / src / handlers / ReactNative.ts View on Github external
async _setupTransport(
		{ localDtlsRole, localSdpObject = null }:
		{ localDtlsRole: DtlsRole; localSdpObject: any | null }
	): Promise
	{
		if (!localSdpObject)
			localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);

		// Get our local DTLS parameters.
		const dtlsParameters =
			sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

		// Set our DTLS role.
		dtlsParameters.role = localDtlsRole;

		// Update the remote DTLS role in the SDP.
		this._remoteSdp.updateDtlsRole(
			localDtlsRole === 'client' ? 'server' : 'client');

		// Need to tell the remote transport about our parameters.
		await this.safeEmitAsPromise('@connect', { dtlsParameters });

		this._transportReady = true;
github versatica / mediasoup-client / lib / handlers / Chrome69.js View on Github external
.then(() =>
			{
				// Get our local DTLS parameters.
				const transportLocalParameters = {};
				const sdp = this._pc.localDescription.sdp;
				const sdpObj = sdpTransform.parse(sdp);
				const dtlsParameters = sdpCommonUtils.extractDtlsParameters(sdpObj);

				// Let's decide that we'll be DTLS server (because we can).
				dtlsParameters.role = 'server';

				transportLocalParameters.dtlsParameters = dtlsParameters;

				// Provide the remote SDP handler with transport local parameters.
				this._remoteSdp.setTransportLocalParameters(transportLocalParameters);

				// We need transport remote parameters.
				return this.safeEmitAsPromise(
					'@needcreatetransport', transportLocalParameters);
			})
			.then((transportRemoteParameters) =>
github pion / ion / sdk / js / src / Client.js View on Github external
if (codec === undefined)
            return desc;

        /*
         * DefaultPayloadTypePCMU = 0
         * DefaultPayloadTypePCMA = 8
         * DefaultPayloadTypeG722 = 9
         * DefaultPayloadTypeOpus = 111
         * DefaultPayloadTypeVP8  = 96
         * DefaultPayloadTypeVP9  = 98
         * DefaultPayloadTypeH264 = 102
        */
        let payload;
        let codeName = '';
        const session = sdpTransform.parse(desc.sdp);
        console.log('SDP object => %o', session);
        var videoIdx = -1;
        session['media'].map((m, index) => {
            if (m.type == 'video') {
                videoIdx = index;
            }
        });

        if (videoIdx == -1) return desc;

        if (codec.toLowerCase() === 'vp8') {
            payload = DefaultPayloadTypeVP8;
            codeName = "VP8";
        } else if (codec.toLowerCase() === 'vp9') {
            payload = DefaultPayloadTypeVP9;
            codeName = "VP9";
github versatica / mediasoup-client / src / handlers / Chrome55.ts View on Github external
this._pc.addStream(this._stream);

		let offer = await this._pc.createOffer();
		let localSdpObject = sdpTransform.parse(offer.sdp);
		let offerMediaObject;
		const sendingRtpParameters =
			utils.clone(this._sendingRtpParametersByKind[track.kind]);

		if (!this._transportReady)
			await this._setupTransport({ localDtlsRole: 'server', localSdpObject });

		if (track.kind === 'video' && encodings && encodings.length > 1)
		{
			logger.debug('send() | enabling simulcast');

			localSdpObject = sdpTransform.parse(offer.sdp);
			offerMediaObject = localSdpObject.media.find(
				(m: any) => m.type === 'video'
			);

			sdpPlanBUtils.addLegacySimulcast(
				{
					offerMediaObject,
					track,
					numStreams : encodings.length
				});

			offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
		}

		logger.debug(
			'send() | calling pc.setLocalDescription() [offer:%o]', offer);
github versatica / mediasoup-client / src / handlers / Firefox60.ts View on Github external
parameters.encodings = encodings;
			await videoTransceiver.sender.setParameters(parameters);

			const offer = await pc.createOffer();

			try { canvas.remove(); }
			catch (error) {}

			try { fakeVideoTrack.stop(); }
			catch (error) {}

			try { pc.close(); }
			catch (error) {}

			const sdpObject = sdpTransform.parse(offer.sdp);
			const nativeRtpCapabilities =
				sdpCommonUtils.extractRtpCapabilities({ sdpObject });

			return nativeRtpCapabilities;
		}
		catch (error)
		{
			try { canvas.remove(); }
			catch (error2) {}

			try { fakeVideoTrack.stop(); }
			catch (error2) {}

			try { pc.close(); }
			catch (error2) {}

sdp-transform

A simple parser/writer for the Session Description Protocol

MIT
Latest version published 3 months ago

Package Health Score

70 / 100
Full package analysis