浏览代码

feat(TS) Migrate SendVideoController to TS

Co-authored-by: naman9271 <naman9271@gmail.com>
master
Naman Jain 3 个月前
父节点
当前提交
4b762c77db
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 34 次插入19 次删除
  1. 34
    19
      modules/qualitycontrol/SendVideoController.ts

modules/qualitycontrol/SendVideoController.js → modules/qualitycontrol/SendVideoController.ts 查看文件

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 
2
 
3
+import JitsiConference from '../../JitsiConference';
4
+import JingleSessionPC from '../xmpp/JingleSessionPC';
3
 import MediaSessionEvents from '../xmpp/MediaSessionEvents';
5
 import MediaSessionEvents from '../xmpp/MediaSessionEvents';
4
 
6
 
5
 const logger = getLogger('modules/qualitycontrol/SendVideoController');
7
 const logger = getLogger('modules/qualitycontrol/SendVideoController');
6
 const MAX_LOCAL_RESOLUTION = 2160;
8
 const MAX_LOCAL_RESOLUTION = 2160;
7
 
9
 
10
+export interface IVideoConstraint {
11
+    maxHeight: number;
12
+    sourceName: string;
13
+}
14
+
8
 /**
15
 /**
9
  * The class manages send video constraints across media sessions({@link JingleSessionPC}) which belong to
16
  * The class manages send video constraints across media sessions({@link JingleSessionPC}) which belong to
10
  * {@link JitsiConference}. It finds the lowest common value, between the local user's send preference and
17
  * {@link JitsiConference}. It finds the lowest common value, between the local user's send preference and
13
  * different.
20
  * different.
14
  */
21
  */
15
 export default class SendVideoController {
22
 export default class SendVideoController {
23
+    private _conference: JitsiConference;
24
+    private _preferredSendMaxFrameHeight: number;
25
+    /**
26
+     * Source name based sender constraints.
27
+     * @type {Map<string, number>};
28
+     */
29
+    private _sourceSenderConstraints: Map<string, number>;
30
+
16
     /**
31
     /**
17
      * Creates new instance for a given conference.
32
      * Creates new instance for a given conference.
18
      *
33
      *
19
      * @param {JitsiConference} conference - the conference instance for which the new instance will be managing
34
      * @param {JitsiConference} conference - the conference instance for which the new instance will be managing
20
      * the send video quality constraints.
35
      * the send video quality constraints.
21
      */
36
      */
22
-    constructor(conference) {
37
+    constructor(conference: JitsiConference) {
23
         this._conference = conference;
38
         this._conference = conference;
24
         this._preferredSendMaxFrameHeight = MAX_LOCAL_RESOLUTION;
39
         this._preferredSendMaxFrameHeight = MAX_LOCAL_RESOLUTION;
25
 
40
 
35
      * sessions for the reasons mentioned in this class description.
50
      * sessions for the reasons mentioned in this class description.
36
      *
51
      *
37
      * @param {string} sourceName - The source for which sender constraints have changed.
52
      * @param {string} sourceName - The source for which sender constraints have changed.
38
-     * @returns {Promise<void[]>}
53
+     * @returns {Promise<void>}
39
      * @private
54
      * @private
40
      */
55
      */
41
-    _propagateSendMaxFrameHeight(sourceName) {
56
+    async _propagateSendMaxFrameHeight(sourceName: string): Promise<void> {
42
         if (!sourceName) {
57
         if (!sourceName) {
43
             throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
58
             throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
44
         }
59
         }
45
         const sendMaxFrameHeight = this._selectSendMaxFrameHeight(sourceName);
60
         const sendMaxFrameHeight = this._selectSendMaxFrameHeight(sourceName);
46
         const promises = [];
61
         const promises = [];
47
 
62
 
48
-        if (sendMaxFrameHeight >= 0) {
63
+        if (sendMaxFrameHeight !== undefined && sendMaxFrameHeight >= 0) {
49
             for (const session of this._conference.getMediaSessions()) {
64
             for (const session of this._conference.getMediaSessions()) {
50
                 promises.push(session.setSenderVideoConstraint(sendMaxFrameHeight, sourceName));
65
                 promises.push(session.setSenderVideoConstraint(sendMaxFrameHeight, sourceName));
51
             }
66
             }
52
         }
67
         }
53
 
68
 
54
-        return Promise.all(promises);
69
+        await Promise.all(promises);
55
     }
70
     }
56
 
71
 
57
     /**
72
     /**
62
      * @returns {number|undefined}
77
      * @returns {number|undefined}
63
      * @private
78
      * @private
64
      */
79
      */
65
-    _selectSendMaxFrameHeight(sourceName) {
80
+    _selectSendMaxFrameHeight(sourceName: string): number | undefined {
66
         if (!sourceName) {
81
         if (!sourceName) {
67
             throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
82
             throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
68
         }
83
         }
71
             ? this._sourceSenderConstraints.get(sourceName)
86
             ? this._sourceSenderConstraints.get(sourceName)
72
             : undefined;
87
             : undefined;
73
 
88
 
74
-        if (this._preferredSendMaxFrameHeight >= 0 && remoteRecvMaxFrameHeight >= 0) {
89
+        if (this._preferredSendMaxFrameHeight >= 0 && remoteRecvMaxFrameHeight !== undefined && remoteRecvMaxFrameHeight >= 0) {
75
             return Math.min(this._preferredSendMaxFrameHeight, remoteRecvMaxFrameHeight);
90
             return Math.min(this._preferredSendMaxFrameHeight, remoteRecvMaxFrameHeight);
76
-        } else if (remoteRecvMaxFrameHeight >= 0) {
91
+        } else if (remoteRecvMaxFrameHeight !== undefined && remoteRecvMaxFrameHeight >= 0) {
77
             return remoteRecvMaxFrameHeight;
92
             return remoteRecvMaxFrameHeight;
78
         }
93
         }
79
 
94
 
85
      *
100
      *
86
      * @returns {void}
101
      * @returns {void}
87
      */
102
      */
88
-    configureConstraintsForLocalSources() {
103
+    configureConstraintsForLocalSources(): void {
89
         for (const track of this._conference.getLocalVideoTracks()) {
104
         for (const track of this._conference.getLocalVideoTracks()) {
90
             const sourceName = track.getSourceName();
105
             const sourceName = track.getSourceName();
91
 
106
 
100
      *
115
      *
101
      * @param {JingleSessionPC} mediaSession - the started media session.
116
      * @param {JingleSessionPC} mediaSession - the started media session.
102
      */
117
      */
103
-    onMediaSessionStarted(mediaSession) {
118
+    onMediaSessionStarted(mediaSession: JingleSessionPC): void {
104
         mediaSession.addListener(
119
         mediaSession.addListener(
105
             MediaSessionEvents.REMOTE_SOURCE_CONSTRAINTS_CHANGED,
120
             MediaSessionEvents.REMOTE_SOURCE_CONSTRAINTS_CHANGED,
106
-            (session, sourceConstraints) => {
121
+            (session: JingleSessionPC, sourceConstraints: Array<IVideoConstraint>) => {
107
                 session === this._conference.getActiveMediaSession()
122
                 session === this._conference.getActiveMediaSession()
108
                     && sourceConstraints.forEach(constraint => this.onSenderConstraintsReceived(constraint));
123
                     && sourceConstraints.forEach(constraint => this.onSenderConstraintsReceived(constraint));
109
             });
124
             });
112
     /**
127
     /**
113
      * Propagates the video constraints if they have changed.
128
      * Propagates the video constraints if they have changed.
114
      *
129
      *
115
-     * @param {Object} videoConstraints - The sender video constraints received from the bridge.
116
-     * @returns {Promise<void[]>}
130
+     * @param {IVideoConstraint} videoConstraints - The sender video constraints received from the bridge.
131
+     * @returns {Promise<void>}
117
      */
132
      */
118
-    onSenderConstraintsReceived(videoConstraints) {
133
+    async onSenderConstraintsReceived(videoConstraints: IVideoConstraint): Promise<void> {
119
         const { maxHeight, sourceName } = videoConstraints;
134
         const { maxHeight, sourceName } = videoConstraints;
120
         const localVideoTracks = this._conference.getLocalVideoTracks() ?? [];
135
         const localVideoTracks = this._conference.getLocalVideoTracks() ?? [];
121
 
136
 
129
                         ? Math.min(MAX_LOCAL_RESOLUTION, this._preferredSendMaxFrameHeight)
144
                         ? Math.min(MAX_LOCAL_RESOLUTION, this._preferredSendMaxFrameHeight)
130
                         : maxHeight);
145
                         : maxHeight);
131
                 logger.debug(`Sender constraints for source:${sourceName} changed to maxHeight:${maxHeight}`);
146
                 logger.debug(`Sender constraints for source:${sourceName} changed to maxHeight:${maxHeight}`);
132
-                this._propagateSendMaxFrameHeight(sourceName);
147
+                await this._propagateSendMaxFrameHeight(sourceName);
133
             }
148
             }
134
         }
149
         }
135
     }
150
     }
138
      * Sets local preference for max send video frame height.
153
      * Sets local preference for max send video frame height.
139
      *
154
      *
140
      * @param {number} maxFrameHeight - the new value to set.
155
      * @param {number} maxFrameHeight - the new value to set.
141
-     * @returns {Promise<void[]>} - resolved when the operation is complete.
156
+     * @returns {Promise<void>} - resolved when the operation is complete.
142
      */
157
      */
143
-    setPreferredSendMaxFrameHeight(maxFrameHeight) {
158
+    async setPreferredSendMaxFrameHeight(maxFrameHeight: number): Promise<void> {
144
         this._preferredSendMaxFrameHeight = maxFrameHeight;
159
         this._preferredSendMaxFrameHeight = maxFrameHeight;
145
-        const promises = [];
160
+        const promises: Promise<void>[] = [];
146
 
161
 
147
         for (const sourceName of this._sourceSenderConstraints.keys()) {
162
         for (const sourceName of this._sourceSenderConstraints.keys()) {
148
             promises.push(this._propagateSendMaxFrameHeight(sourceName));
163
             promises.push(this._propagateSendMaxFrameHeight(sourceName));
149
         }
164
         }
150
 
165
 
151
-        return Promise.allSettled(promises);
166
+        await Promise.allSettled(promises);
152
     }
167
     }
153
 }
168
 }

正在加载...
取消
保存