|
@@ -1,14 +1,48 @@
|
1
|
1
|
import { isEqual } from 'lodash-es';
|
|
2
|
+import Strophe from 'strophe';
|
2
|
3
|
|
3
|
4
|
import { XEP } from '../../service/xmpp/XMPPExtensioProtocols';
|
4
|
5
|
|
5
|
6
|
import SDPUtil from './SDPUtil';
|
6
|
7
|
|
|
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
|
+
|
7
|
37
|
/**
|
8
|
38
|
* A class that provides methods for comparing the source information present in two different SDPs so that the delta
|
9
|
39
|
* can be signaled to Jicofo via 'source-remove' or 'source-add'.
|
10
|
40
|
*/
|
11
|
41
|
export class SDPDiffer {
|
|
42
|
+ private isP2P: boolean;
|
|
43
|
+ private mySdp: ISDP;
|
|
44
|
+ private othersSdp: ISDP;
|
|
45
|
+
|
12
|
46
|
/**
|
13
|
47
|
* Constructor.
|
14
|
48
|
*
|
|
@@ -16,7 +50,7 @@ export class SDPDiffer {
|
16
|
50
|
* @param {SDP} othersSdp - the old SDP.
|
17
|
51
|
* @param {boolean} isP2P - Whether the SDPs belong to a p2p peerconnection.
|
18
|
52
|
*/
|
19
|
|
- constructor(mySdp, othersSdp, isP2P = false) {
|
|
53
|
+ constructor(mySdp: ISDP, othersSdp: ISDP, isP2P: boolean) {
|
20
|
54
|
this.isP2P = isP2P;
|
21
|
55
|
this.mySdp = mySdp;
|
22
|
56
|
this.othersSdp = othersSdp;
|
|
@@ -27,10 +61,10 @@ export class SDPDiffer {
|
27
|
61
|
*
|
28
|
62
|
* @returns {*}
|
29
|
63
|
*/
|
30
|
|
- getNewMedia() {
|
|
64
|
+ getNewMedia(): IDiffSourceInfo {
|
31
|
65
|
const mySources = this.mySdp.getMediaSsrcMap();
|
32
|
66
|
const othersSources = this.othersSdp.getMediaSsrcMap();
|
33
|
|
- const diff = {};
|
|
67
|
+ const diff: IDiffSourceInfo = {};
|
34
|
68
|
|
35
|
69
|
for (const [ index, othersSource ] of othersSources.entries()) {
|
36
|
70
|
const mySource = mySources.get(index);
|
|
@@ -53,10 +87,10 @@ export class SDPDiffer {
|
53
|
87
|
/**
|
54
|
88
|
* Adds the diff source info to the provided IQ stanza.
|
55
|
89
|
*
|
56
|
|
- * @param {*} modify - Stanza IQ.
|
|
90
|
+ * @param {Strophe.Builder} modify - Stanza IQ.
|
57
|
91
|
* @returns {boolean}
|
58
|
92
|
*/
|
59
|
|
- toJingle(modify) {
|
|
93
|
+ toJingle(modify: Strophe.Builder): boolean {
|
60
|
94
|
let modified = false;
|
61
|
95
|
const diffSourceInfo = this.getNewMedia();
|
62
|
96
|
|
|
@@ -86,10 +120,7 @@ export class SDPDiffer {
|
86
|
120
|
const msid = SDPUtil.parseMSIDAttribute(ssrcLines);
|
87
|
121
|
|
88
|
122
|
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();
|
93
|
124
|
}
|
94
|
125
|
|
95
|
126
|
modify.up(); // end of source
|
|
@@ -105,8 +136,7 @@ export class SDPDiffer {
|
105
|
136
|
});
|
106
|
137
|
|
107
|
138
|
ssrcGroup.ssrcs.forEach(ssrc => {
|
108
|
|
- modify.c('source', { ssrc })
|
109
|
|
- .up(); // end of source
|
|
139
|
+ modify.c('source', { ssrc }).up(); // end of source
|
110
|
140
|
});
|
111
|
141
|
modify.up(); // end of ssrc-group
|
112
|
142
|
}
|