Skip to content
Permalink
Browse files

Add Jingle SDP tests

  • Loading branch information
legastero committed Dec 22, 2019
1 parent 0095ab8 commit f38ae9d57e9e185333af0b5db621870afb773341
@@ -13,8 +13,8 @@ import {
} from '../protocol';

import ICESession from './ICESession';
import { exportToSDP, importFromSDP } from './lib/Intermediate';
import { convertIntermediateToRequest, convertRequestToIntermediate } from './lib/Protocol';
import { exportToSDP, importFromSDP } from './sdp/Intermediate';
import { convertIntermediateToRequest, convertRequestToIntermediate } from './sdp/Protocol';
import { ActionCallback } from './Session';

export class Sender extends EventEmitter {
@@ -4,13 +4,13 @@ import { JingleAction, JingleReasonCondition, JingleSessionRole } from '../Const
import { NS_JINGLE_ICE_UDP_1 } from '../Namespaces';
import { Jingle, JingleContent, JingleIce, JingleReason } from '../protocol';

import { exportToSDP, importFromSDP } from './lib/Intermediate';
import { exportToSDP, importFromSDP } from './sdp/Intermediate';
import {
convertCandidateToIntermediate,
convertIntermediateToTransport,
convertIntermediateToTransportInfo,
convertRequestToIntermediate
} from './lib/Protocol';
} from './sdp/Protocol';
import BaseSession, { ActionCallback } from './Session';

export default class ICESession extends BaseSession {
@@ -19,8 +19,8 @@ import {
} from '../protocol';

import ICESession from './ICESession';
import { exportToSDP, importFromSDP } from './lib/Intermediate';
import { convertIntermediateToRequest, convertRequestToIntermediate } from './lib/Protocol';
import { exportToSDP, importFromSDP } from './sdp/Intermediate';
import { convertIntermediateToRequest, convertRequestToIntermediate } from './sdp/Protocol';
import { ActionCallback } from './Session';

function applyStreamsCompatibility(content: JingleContent) {
@@ -78,11 +78,7 @@ export function importFromSDP(sdp: SDP.SDPBlob): IntermediateSessionDescription
media.rtpEncodingParameters = SDP.parseRtpEncodingParameters(mediaSection);
media.rtcpParameters = SDP.parseRtcpParameters(mediaSection);
const msid = SDP.parseMsid(mediaSection);
if (msid) {
media.streams = [msid];
} else {
media.streams = [];
}
media.streams = msid ? [msid] : [];
} else if (kind === 'application') {
media.sctp = SDP.parseSctpDescription(mediaSection);
}
@@ -107,10 +103,6 @@ export function exportToSDP(session: IntermediateSessionDescription) {
'a=msid-semantic:WMS *\r\n'
);

if (session.iceLite) {
output.push('a=ice-lite\r\n');
}

for (const group of session.groups || []) {
output.push(`a=group:${group.semantics} ${group.mids.join(' ')}\r\n`);
}
@@ -131,16 +123,21 @@ export function exportToSDP(session: IntermediateSessionDescription) {
for (const stream of media.streams || []) {
output.push(`a=msid:${stream.stream} ${stream.track}\r\n`);
}
if (media.rtcpParameters && media.rtcpParameters.cname) {
output.push(
`a=ssrc:${media.rtcpParameters.ssrc} cname:${media.rtcpParameters.cname}\r\n`
);
if (media.rtpEncodingParameters && media.rtpEncodingParameters[0].rtx) {
const params = media.rtpEncodingParameters[0];
output.push(`a=ssrc-group:FID ${params.ssrc} ${params.rtx!.ssrc}\r\n`);
if (media.rtcpParameters) {
if (media.rtcpParameters.reducedSize && mline.indexOf('a=rtcp-rsize') === -1) {
output.push('a=rtcp-rsize\r\n');
}
if (media.rtcpParameters.cname) {
output.push(
`a=ssrc:${params.rtx!.ssrc} cname:${media.rtcpParameters.cname}\r\n`
`a=ssrc:${media.rtcpParameters.ssrc} cname:${media.rtcpParameters.cname}\r\n`
);
if (media.rtpEncodingParameters && media.rtpEncodingParameters[0].rtx) {
const params = media.rtpEncodingParameters[0];
output.push(`a=ssrc-group:FID ${params.ssrc} ${params.rtx!.ssrc}\r\n`);
output.push(
`a=ssrc:${params.rtx!.ssrc} cname:${media.rtcpParameters.cname}\r\n`
);
}
}
}
}
@@ -9,7 +9,8 @@ import {
JingleIce,
JingleIceCandidate,
JingleRtpCodec,
JingleRtpDescription
JingleRtpDescription,
JingleRtpHeaderExtension
} from '../../protocol';

import {
@@ -45,14 +46,14 @@ export function convertIntermediateToApplication(
};

for (const ext of rtp.headerExtensions || []) {
application.headerExtensions!.push({
const header: JingleRtpHeaderExtension = {
id: ext.id,
senders:
ext.direction && ext.direction !== 'sendrecv'
? directionToSenders(role, ext.direction)
: undefined,
uri: ext.uri
});
};
if (ext.direction && ext.direction !== 'sendrecv') {
header.senders = directionToSenders(role, ext.direction);
}
application.headerExtensions!.push(header);
}

if (rtcp.ssrc && rtcp.cname) {
@@ -90,11 +91,13 @@ export function convertIntermediateToApplication(
channels: codec.channels,
clockRate: codec.clockRate,
id: codec.payloadType.toString(),
maxptime: codec.maxptime ? codec.maxptime.toString() : undefined,
name: codec.name,
parameters: codec.parameters,
rtcpFeedback: codec.rtcpFeedback
};
if (codec.maxptime) {
payload.maxptime = codec.maxptime.toString();
}

for (const key of Object.keys(codec.parameters || {})) {
if (key === 'ptime') {
@@ -228,6 +231,7 @@ export function convertContentToIntermediate(

if (isRTP) {
media.rtcpParameters = {
compound: !application.rtcpReducedSize,
mux: application.rtcpMux,
reducedSize: application.rtcpReducedSize
};
@@ -243,7 +247,8 @@ export function convertContentToIntermediate(
media.rtpParameters = {
codecs: [],
fecMechanisms: [],
headerExtensions: []
headerExtensions: [],
rtcp: []
};

if (application.streams) {
@@ -272,6 +277,8 @@ export function convertContentToIntermediate(
}
}

let hasRED = false;
let hasULPFEC = false;
for (const payload of application.codecs || []) {
const parameters: SDP.SDPCodecAdditionalParameters = payload.parameters || {};

@@ -283,6 +290,16 @@ export function convertContentToIntermediate(
});
}

if (payload.name === 'red' || payload.name === 'ulpfec') {
hasRED = hasRED || payload.name === 'red';
hasULPFEC = hasULPFEC || payload.name === 'ulpfec';

const fec = payload.name.toUpperCase();
if (!media.rtpParameters.fecMechanisms.includes(fec)) {
media.rtpParameters.fecMechanisms.push(fec);
}
}

media.rtpParameters.codecs.push({
channels: payload.channels!,
clockRate: payload.clockRate!,
@@ -296,10 +313,7 @@ export function convertContentToIntermediate(

for (const ext of application.headerExtensions || []) {
media.rtpParameters.headerExtensions.push({
direction:
ext.senders && ext.senders !== 'both'
? sendersToDirection(role, ext.senders)
: undefined,
direction: sendersToDirection(role, ext.senders || 'both'),
id: ext.id,
uri: ext.uri
});
@@ -313,7 +327,6 @@ export function convertContentToIntermediate(
usernameFragment: transport.usernameFragment
};
}

if (transport.fingerprints && transport.fingerprints.length) {
media.dtlsParameters = {
fingerprints: [],
@@ -333,6 +346,8 @@ export function convertContentToIntermediate(

media.setup = transport.fingerprints[0].setup;
}

media.candidates = (transport.candidates || []).map(convertCandidateToIntermediate);
}

return media;

0 comments on commit f38ae9d

Please sign in to comment.
You can’t perform that action at this time.