Skip to content

Commit dea1a5f

Browse files
authored
feat(ts) migrate sdp/SDPDiffer to TS
1 parent efcb1ec commit dea1a5f

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

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

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
11
import { isEqual } from 'lodash-es';
2+
import Strophe from 'strophe';
23

34
import { XEP } from '../../service/xmpp/XMPPExtensioProtocols';
45

56
import SDPUtil from './SDPUtil';
67

8+
export interface IMediaSsrc {
9+
lines: string[];
10+
ssrc: number;
11+
}
12+
13+
export interface IMediaSsrcs {
14+
[ssrcNum: string]: IMediaSsrc;
15+
}
16+
17+
export interface ISsrcGroup {
18+
semantics: string;
19+
ssrcs: number[];
20+
}
21+
22+
export interface IMediaSource {
23+
mediaType: string;
24+
mid?: string;
25+
ssrcGroups: ISsrcGroup[];
26+
ssrcs: IMediaSsrcs;
27+
}
28+
29+
export interface IDiffSourceInfo {
30+
[index: string]: IMediaSource;
31+
}
32+
33+
export interface ISDP {
34+
getMediaSsrcMap: () => Map<string, IMediaSource>;
35+
}
36+
737
/**
838
* A class that provides methods for comparing the source information present in two different SDPs so that the delta
939
* can be signaled to Jicofo via 'source-remove' or 'source-add'.
1040
*/
1141
export class SDPDiffer {
42+
private isP2P: boolean;
43+
private mySdp: ISDP;
44+
private othersSdp: ISDP;
45+
1246
/**
1347
* Constructor.
1448
*
1549
* @param {SDP} mySdp - the new SDP.
1650
* @param {SDP} othersSdp - the old SDP.
1751
* @param {boolean} isP2P - Whether the SDPs belong to a p2p peerconnection.
1852
*/
19-
constructor(mySdp, othersSdp, isP2P = false) {
53+
constructor(mySdp: ISDP, othersSdp: ISDP, isP2P: boolean) {
2054
this.isP2P = isP2P;
2155
this.mySdp = mySdp;
2256
this.othersSdp = othersSdp;
@@ -27,10 +61,10 @@ export class SDPDiffer {
2761
*
2862
* @returns {*}
2963
*/
30-
getNewMedia() {
64+
getNewMedia(): IDiffSourceInfo {
3165
const mySources = this.mySdp.getMediaSsrcMap();
3266
const othersSources = this.othersSdp.getMediaSsrcMap();
33-
const diff = {};
67+
const diff: IDiffSourceInfo = {};
3468

3569
for (const [ index, othersSource ] of othersSources.entries()) {
3670
const mySource = mySources.get(index);
@@ -53,10 +87,10 @@ export class SDPDiffer {
5387
/**
5488
* Adds the diff source info to the provided IQ stanza.
5589
*
56-
* @param {*} modify - Stanza IQ.
90+
* @param {Strophe.Builder} modify - Stanza IQ.
5791
* @returns {boolean}
5892
*/
59-
toJingle(modify) {
93+
toJingle(modify: Strophe.Builder): boolean {
6094
let modified = false;
6195
const diffSourceInfo = this.getNewMedia();
6296

@@ -86,10 +120,7 @@ export class SDPDiffer {
86120
const msid = SDPUtil.parseMSIDAttribute(ssrcLines);
87121

88122
if (msid) {
89-
modify.c('parameter');
90-
modify.attrs({ name: 'msid' });
91-
modify.attrs({ value: msid });
92-
modify.up();
123+
modify.c('parameter', { name: 'msid', value: msid }).up();
93124
}
94125

95126
modify.up(); // end of source
@@ -105,8 +136,7 @@ export class SDPDiffer {
105136
});
106137

107138
ssrcGroup.ssrcs.forEach(ssrc => {
108-
modify.c('source', { ssrc })
109-
.up(); // end of source
139+
modify.c('source', { ssrc }).up(); // end of source
110140
});
111141
modify.up(); // end of ssrc-group
112142
}

0 commit comments

Comments
 (0)