Kaynağa Gözat

feat(ts) migrate modules\statistics\SpeakerStatsCollector to TS

master
Naman Jain 6 ay önce
ebeveyn
işleme
b1c9bd483d
No account linked to committer's email address

+ 1
- 1
modules/statistics/SpeakerStats.ts Dosyayı Görüntüle

@@ -1,7 +1,7 @@
1 1
 /**
2 2
  * Interface for face landmarks.
3 3
  */
4
-interface IFaceLandmarks {
4
+export interface IFaceLandmarks {
5 5
     duration: number;
6 6
     faceExpression: string;
7 7
 }

modules/statistics/SpeakerStatsCollector.js → modules/statistics/SpeakerStatsCollector.ts Dosyayı Görüntüle

@@ -2,8 +2,8 @@ import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
2 2
 import { XMPPEvents } from '../../service/xmpp/XMPPEvents';
3 3
 
4 4
 import SpeakerStats from './SpeakerStats';
5
-
6
-
5
+import JitsiConference from '../../JitsiConference';
6
+import type { IFaceLandmarks } from './SpeakerStats';
7 7
 /**
8 8
  * The value to use for the "type" field for messages sent
9 9
  * over the data channel that contain a face landmark.
@@ -11,11 +11,26 @@ import SpeakerStats from './SpeakerStats';
11 11
 
12 12
 const FACE_LANDMARK_MESSAGE_TYPE = 'face-landmarks';
13 13
 
14
+export interface ISpeakerStatsState {
15
+    dominantSpeakerId: string | null;
16
+    users: {
17
+        [userId: string]: SpeakerStats;
18
+    };
19
+}
20
+
21
+export interface IFaceLandmarkMessage {
22
+    faceLandmarks: IFaceLandmarks;
23
+    type: string;
24
+}
25
+
14 26
 /**
15 27
  * A collection for tracking speaker stats. Attaches listeners
16 28
  * to the conference to automatically update on tracked events.
17 29
  */
18 30
 export default class SpeakerStatsCollector {
31
+    stats: ISpeakerStatsState;
32
+    conference: JitsiConference;
33
+
19 34
     /**
20 35
      * Initializes a new SpeakerStatsCollector instance.
21 36
      *
@@ -23,7 +38,7 @@ export default class SpeakerStatsCollector {
23 38
      * @param {JitsiConference} conference - The conference to track.
24 39
      * @returns {void}
25 40
      */
26
-    constructor(conference) {
41
+    constructor(conference: JitsiConference) {
27 42
         this.stats = {
28 43
             users: {
29 44
 
@@ -52,7 +67,7 @@ export default class SpeakerStatsCollector {
52 67
 
53 68
         conference.on(
54 69
             JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
55
-                (participant, { type, faceLandmarks }) => {
70
+                (participant: any, { type, faceLandmarks }: IFaceLandmarkMessage) => {
56 71
                     if (type === FACE_LANDMARK_MESSAGE_TYPE) {
57 72
                         this._onFaceLandmarkAdd(participant.getId(), faceLandmarks);
58 73
                     }
@@ -74,12 +89,12 @@ export default class SpeakerStatsCollector {
74 89
      * @returns {void}
75 90
      * @private
76 91
      */
77
-    _onDominantSpeaker(dominantSpeakerId, previous, silence) {
92
+    _onDominantSpeaker(dominantSpeakerId: string, previous: string[], silence: boolean): void {
78 93
         const oldDominantSpeaker
79
-            = this.stats.users[this.stats.dominantSpeakerId];
94
+            = this.stats.users[this.stats.dominantSpeakerId as string];
80 95
         const newDominantSpeaker = this.stats.users[dominantSpeakerId];
81 96
 
82
-        oldDominantSpeaker && oldDominantSpeaker.setDominantSpeaker(false);
97
+        oldDominantSpeaker && oldDominantSpeaker.setDominantSpeaker(false, false);
83 98
         newDominantSpeaker && newDominantSpeaker.setDominantSpeaker(true, silence);
84 99
         this.stats.dominantSpeakerId = dominantSpeakerId;
85 100
     }
@@ -92,13 +107,13 @@ export default class SpeakerStatsCollector {
92 107
      * @returns {void}
93 108
      * @private
94 109
      */
95
-    _onUserJoin(userId, participant) {
110
+    _onUserJoin(userId: string, participant: any): void {
96 111
         if (participant.isHidden()) {
97 112
             return;
98 113
         }
99 114
 
100 115
         if (!this.stats.users[userId]) {
101
-            this.stats.users[userId] = new SpeakerStats(userId, participant.getDisplayName());
116
+            this.stats.users[userId] = new SpeakerStats(userId, participant.getDisplayName(), false);
102 117
         }
103 118
     }
104 119
 
@@ -110,7 +125,7 @@ export default class SpeakerStatsCollector {
110 125
      * @returns {void}
111 126
      * @private
112 127
      */
113
-    _onUserLeave(userId) {
128
+    _onUserLeave(userId: string): void {
114 129
         const savedUser = this.stats.users[userId];
115 130
 
116 131
         if (savedUser) {
@@ -126,7 +141,7 @@ export default class SpeakerStatsCollector {
126 141
      * @returns {void}
127 142
      * @private
128 143
      */
129
-    _onDisplayNameChange(userId, newName) {
144
+    _onDisplayNameChange(userId: string, newName: string): void {
130 145
         const savedUser = this.stats.users[userId];
131 146
 
132 147
         if (savedUser) {
@@ -142,7 +157,7 @@ export default class SpeakerStatsCollector {
142 157
      * @returns {void}
143 158
      * @private
144 159
      */
145
-    _onFaceLandmarkAdd(userId, data) {
160
+    _onFaceLandmarkAdd(userId: string, data: any): void {
146 161
         const savedUser = this.stats.users[userId];
147 162
 
148 163
         if (savedUser && data) {
@@ -156,7 +171,7 @@ export default class SpeakerStatsCollector {
156 171
      * @returns {Object} The keys are the user ids and the values are the
157 172
      * associated user's SpeakerStats model.
158 173
      */
159
-    getStats() {
174
+    getStats(): { [userId: string]: SpeakerStats; } {
160 175
         return this.stats.users;
161 176
     }
162 177
 
@@ -166,13 +181,13 @@ export default class SpeakerStatsCollector {
166 181
      * @param {Object} newStats - The new values used to update current one.
167 182
      * @private
168 183
      */
169
-    _updateStats(newStats) {
184
+    _updateStats(newStats: { [userId: string]: any; }): void {
170 185
         for (const userId in newStats) { // eslint-disable-line guard-for-in
171 186
             let speakerStatsToUpdate;
172 187
             const newParticipant = this.conference.getParticipantById(userId);
173 188
 
174 189
             // we want to ignore hidden participants
175
-            if (!newParticipant || !newParticipant.isHidden()) {
190
+            if (!newParticipant?.isHidden()) {
176 191
                 if (this.stats.users[userId]) {
177 192
                     speakerStatsToUpdate = this.stats.users[userId];
178 193
 
@@ -182,7 +197,7 @@ export default class SpeakerStatsCollector {
182 197
                     }
183 198
                 } else {
184 199
                     speakerStatsToUpdate = new SpeakerStats(
185
-                        userId, newStats[userId].displayName);
200
+                        userId, newStats[userId].displayName, false);
186 201
                     this.stats.users[userId] = speakerStatsToUpdate;
187 202
                     speakerStatsToUpdate.markAsHasLeft();
188 203
                 }

Loading…
İptal
Kaydet