浏览代码

fix: add a timer which automatically clears subtitles (#3349)

master
Nik 7 年前
父节点
当前提交
ef49817eaf
共有 1 个文件被更改,包括 30 次插入11 次删除
  1. 30
    11
      react/features/subtitles/middleware.js

+ 30
- 11
react/features/subtitles/middleware.js 查看文件

10
 
10
 
11
 const logger = require('jitsi-meet-logger').getLogger(__filename);
11
 const logger = require('jitsi-meet-logger').getLogger(__filename);
12
 
12
 
13
-declare var APP: Object;
14
-
15
 /**
13
 /**
16
  * The type of json-message which indicates that json carries a
14
  * The type of json-message which indicates that json carries a
17
  * transcription result.
15
  * transcription result.
85
 
83
 
86
             const newTranscriptMessage = {
84
             const newTranscriptMessage = {
87
                 participantName,
85
                 participantName,
88
-                final: json.text
86
+                final: json.text,
87
+                clearTimeOut: undefined
89
             };
88
             };
90
 
89
 
90
+            setClearerOnTranscriptMessage(dispatch,
91
+                transcriptMessageID, newTranscriptMessage);
91
             dispatch(updateTranscriptMessage(transcriptMessageID,
92
             dispatch(updateTranscriptMessage(transcriptMessageID,
92
                 newTranscriptMessage));
93
                 newTranscriptMessage));
93
 
94
 
94
-            setTimeout(() => {
95
-                dispatch(removeTranscriptMessage(transcriptMessageID));
96
-            }, REMOVE_AFTER_MS);
97
-
98
         } else if (json.type === JSON_TYPE_TRANSCRIPTION_RESULT
95
         } else if (json.type === JSON_TYPE_TRANSCRIPTION_RESULT
99
             && !translationLanguage) {
96
             && !translationLanguage) {
100
             // Displays interim and final results without any translation if
97
             // Displays interim and final results without any translation if
109
                 = { ...getState()['features/subtitles'].transcriptMessages
106
                 = { ...getState()['features/subtitles'].transcriptMessages
110
                     .get(transcriptMessageID) || { participantName } };
107
                     .get(transcriptMessageID) || { participantName } };
111
 
108
 
109
+            setClearerOnTranscriptMessage(dispatch,
110
+                transcriptMessageID, newTranscriptMessage);
111
+
112
             // If this is final result, update the state as a final result
112
             // If this is final result, update the state as a final result
113
             // and start a count down to remove the subtitle from the state
113
             // and start a count down to remove the subtitle from the state
114
             if (!isInterim) {
114
             if (!isInterim) {
116
                 newTranscriptMessage.final = text;
116
                 newTranscriptMessage.final = text;
117
                 dispatch(updateTranscriptMessage(transcriptMessageID,
117
                 dispatch(updateTranscriptMessage(transcriptMessageID,
118
                     newTranscriptMessage));
118
                     newTranscriptMessage));
119
-
120
-                setTimeout(() => {
121
-                    dispatch(removeTranscriptMessage(transcriptMessageID));
122
-                }, REMOVE_AFTER_MS);
123
             } else if (stability > 0.85) {
119
             } else if (stability > 0.85) {
124
 
120
 
125
                 // If the message has a high stability, we can update the
121
                 // If the message has a high stability, we can update the
146
 
142
 
147
     return next(action);
143
     return next(action);
148
 }
144
 }
145
+
146
+/**
147
+ * Set a timeout on a TranscriptMessage object so it clears itself when it's not
148
+ * updated.
149
+ *
150
+ * @param {Function} dispatch - Dispatch remove action to store.
151
+ * @param {string} transcriptMessageID - The id of the message to remove.
152
+ * @param {Object} transcriptMessage - The message to remove.
153
+ *
154
+ * @returns {void}
155
+ */
156
+function setClearerOnTranscriptMessage(
157
+        dispatch,
158
+        transcriptMessageID,
159
+        transcriptMessage) {
160
+    if (transcriptMessage.clearTimeOut) {
161
+        clearTimeout(transcriptMessage.clearTimeOut);
162
+    }
163
+
164
+    transcriptMessage.clearTimeOut = setTimeout(() => {
165
+        dispatch(removeTranscriptMessage(transcriptMessageID));
166
+    }, REMOVE_AFTER_MS);
167
+}

正在加载...
取消
保存