소스 검색

feat(ts) migrate sdp/SDPDiffer to TS

master
Naman Jain 4 달 전
부모
커밋
dea1a5fe39
No account linked to committer's email address
1개의 변경된 파일41개의 추가작업 그리고 11개의 파일을 삭제
  1. 41
    11
      modules/sdp/SDPDiffer.ts

modules/sdp/SDPDiffer.js → modules/sdp/SDPDiffer.ts 파일 보기

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

Loading…
취소
저장