Skip to content

Commit 23278f9

Browse files
naman9271naman9271
authored andcommitted
conflicts resolved
1 parent 806e213 commit 23278f9

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

modules/sdp/RtxModifier.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-len*/
22
import * as transform from 'sdp-transform';
33

4-
import RtxModifier from './RtxModifier.js';
4+
import RtxModifier from './RtxModifier.ts';
55
import SDPUtil from './SDPUtil';
66
import { default as SampleSdpStrings } from './SampleSdpStrings';
77

modules/sdp/RtxModifier.js renamed to modules/sdp/RtxModifier.ts

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ import { SdpTransformWrap, parseSecondarySSRC } from './SdpTransformUtil';
99

1010
const logger = getLogger('modules/sdp/RtxModifier');
1111

12+
/**
13+
* Helper interfaces for type safety.
14+
*/
15+
export interface IPrimarySsrcInfo {
16+
cname?: string;
17+
id: number;
18+
msid?: string;
19+
}
20+
21+
export interface IMLineWrap {
22+
addSSRCAttribute: (attr: { attribute: string; id: number; value: string; }) => void;
23+
addSSRCGroup: (group: { semantics: string; ssrcs: string; }) => void;
24+
containsAnySSRCGroups: () => boolean;
25+
direction: string;
26+
findGroups: (semantics: string) => Array<{ semantics: string; ssrcs: string; }>;
27+
getPrimaryVideoSSRCs: () => number[];
28+
getRtxSSRC: (primarySsrc: number) => number | undefined;
29+
getSSRCAttrValue: (ssrc: number, attribute: string) => string | undefined;
30+
getSSRCCount: () => number;
31+
removeGroupsBySemantics: (semantics: string) => void;
32+
removeGroupsWithSSRC: (ssrc: number) => void;
33+
removeSSRC: (ssrc: number) => void;
34+
}
35+
1236
/**
1337
* Begin helper functions
1438
*/
@@ -22,7 +46,11 @@ const logger = getLogger('modules/sdp/RtxModifier');
2246
* primary ssrc
2347
* @param {number} rtxSsrc the rtx ssrc to associate with the primary ssrc
2448
*/
25-
function updateAssociatedRtxStream(mLine, primarySsrcInfo, rtxSsrc) {
49+
function updateAssociatedRtxStream(
50+
mLine: IMLineWrap,
51+
primarySsrcInfo: IPrimarySsrcInfo,
52+
rtxSsrc: number
53+
): void {
2654
const primarySsrc = primarySsrcInfo.id;
2755
const primarySsrcMsid = primarySsrcInfo.msid;
2856
const primarySsrcCname = primarySsrcInfo.cname;
@@ -63,6 +91,12 @@ function updateAssociatedRtxStream(mLine, primarySsrcInfo, rtxSsrc) {
6391
* and makes sure that they remain consistent
6492
*/
6593
export default class RtxModifier {
94+
/**
95+
* Map of video ssrc to corresponding RTX
96+
* ssrc
97+
*/
98+
private correspondingRtxSsrcs: Map<number, number>;
99+
66100
/**
67101
* Constructor
68102
*/
@@ -71,15 +105,15 @@ export default class RtxModifier {
71105
* Map of video ssrc to corresponding RTX
72106
* ssrc
73107
*/
74-
this.correspondingRtxSsrcs = new Map();
108+
this.correspondingRtxSsrcs = new Map<number, number>();
75109
}
76110

77111
/**
78112
* Clear the cached map of primary video ssrcs to
79113
* their corresponding rtx ssrcs so that they will
80114
* not be used for the next call to modifyRtxSsrcs
81115
*/
82-
clearSsrcCache() {
116+
clearSsrcCache(): void {
83117
this.correspondingRtxSsrcs.clear();
84118
}
85119

@@ -89,7 +123,7 @@ export default class RtxModifier {
89123
* @param {Map} ssrcMapping a mapping of primary video
90124
* ssrcs to their corresponding rtx ssrcs
91125
*/
92-
setSsrcCache(ssrcMapping) {
126+
setSsrcCache(ssrcMapping: Map<number, number>): void {
93127
logger.debug('Setting ssrc cache to ', ssrcMapping);
94128
this.correspondingRtxSsrcs = ssrcMapping;
95129
}
@@ -101,19 +135,19 @@ export default class RtxModifier {
101135
* @param {string} sdpStr sdp in raw string format
102136
* @returns {string} The modified sdp in raw string format.
103137
*/
104-
modifyRtxSsrcs(sdpStr) {
138+
modifyRtxSsrcs(sdpStr: string): string {
105139
let modified = false;
106140
const sdpTransformer = new SdpTransformWrap(sdpStr);
107141
const videoMLines = sdpTransformer.selectMedia(MediaType.VIDEO);
108142

109-
if (!videoMLines?.length) {
143+
if (!videoMLines || (Array.isArray(videoMLines) && videoMLines.length === 0)) {
110144
logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);
111145

112146
return sdpStr;
113147
}
114148

115-
for (const videoMLine of videoMLines) {
116-
if (this.modifyRtxSsrcs2(videoMLine)) {
149+
for (const videoMLine of Array.isArray(videoMLines) ? videoMLines : [ videoMLines ]) {
150+
if (this.modifyRtxSsrcs2(videoMLine as IMLineWrap)) {
117151
modified = true;
118152
}
119153
}
@@ -128,7 +162,7 @@ export default class RtxModifier {
128162
* @return {boolean} <tt>true</tt> if the SDP wrapped by {@link SdpTransformWrap} has been modified or
129163
* <tt>false</tt> otherwise.
130164
*/
131-
modifyRtxSsrcs2(videoMLine) {
165+
modifyRtxSsrcs2(videoMLine: IMLineWrap): boolean {
132166
if (videoMLine.direction === MediaDirection.RECVONLY) {
133167
return false;
134168
}
@@ -161,7 +195,8 @@ export default class RtxModifier {
161195
id: ssrc,
162196
msid
163197
},
164-
correspondingRtxSsrc);
198+
correspondingRtxSsrc
199+
);
165200
}
166201

167202
// FIXME we're not looking into much details whether the SDP has been
@@ -175,20 +210,22 @@ export default class RtxModifier {
175210
* @param {string} sdpStr sdp in raw string format
176211
* @returns {string} sdp string with all rtx streams stripped
177212
*/
178-
stripRtx(sdpStr) {
213+
stripRtx(sdpStr: string): string {
179214
const sdpTransformer = new SdpTransformWrap(sdpStr);
180215
const videoMLines = sdpTransformer.selectMedia(MediaType.VIDEO);
181216

182-
if (!videoMLines?.length) {
217+
if (!videoMLines || (Array.isArray(videoMLines) && videoMLines.length === 0)) {
183218
logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);
184219

185220
return sdpStr;
186221
}
187222

188-
for (const videoMLine of videoMLines) {
189-
if (videoMLine.direction !== MediaDirection.RECVONLY
223+
for (const videoMLine of Array.isArray(videoMLines) ? videoMLines : [ videoMLines ]) {
224+
if (
225+
videoMLine.direction !== MediaDirection.RECVONLY
190226
&& videoMLine.getSSRCCount()
191-
&& videoMLine.containsAnySSRCGroups()) {
227+
&& videoMLine.containsAnySSRCGroups()
228+
) {
192229
const fidGroups = videoMLine.findGroups(SSRC_GROUP_SEMANTICS.FID);
193230

194231
// Remove the fid groups from the mline

0 commit comments

Comments
 (0)