|
@@ -1,14 +1,35 @@
|
|
1
|
+// @flow
|
|
2
|
+
|
1
|
3
|
import { MiddlewareRegistry } from '../base/redux';
|
2
|
4
|
|
3
|
5
|
import { ENDPOINT_MESSAGE_RECEIVED } from './actionTypes';
|
4
|
6
|
import {
|
5
|
|
- addTranscriptMessage,
|
6
|
7
|
removeTranscriptMessage,
|
7
|
8
|
updateTranscriptMessage
|
8
|
9
|
} from './actions';
|
9
|
10
|
|
10
|
11
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
11
|
12
|
|
|
13
|
+declare var APP: Object;
|
|
14
|
+
|
|
15
|
+/**
|
|
16
|
+ * The type of json-message which indicates that json carries a
|
|
17
|
+ * transcription result.
|
|
18
|
+ */
|
|
19
|
+const JSON_TYPE_TRANSCRIPTION_RESULT = 'transcription-result';
|
|
20
|
+
|
|
21
|
+/**
|
|
22
|
+ * The type of json-message which indicates that json carries a
|
|
23
|
+ * translation result.
|
|
24
|
+ */
|
|
25
|
+const JSON_TYPE_TRANSLATION_RESULT = 'translation-result';
|
|
26
|
+
|
|
27
|
+/**
|
|
28
|
+ * The local participant property which is used to store the language
|
|
29
|
+ * preference for translation for a participant.
|
|
30
|
+ */
|
|
31
|
+const P_NAME_TRANSLATION_LANGUAGE = 'translation_language';
|
|
32
|
+
|
12
|
33
|
/**
|
13
|
34
|
* Time after which the rendered subtitles will be removed.
|
14
|
35
|
*/
|
|
@@ -47,31 +68,46 @@ MiddlewareRegistry.register(store => next => action => {
|
47
|
68
|
*/
|
48
|
69
|
function _endpointMessageReceived({ dispatch, getState }, next, action) {
|
49
|
70
|
const json = action.json;
|
|
71
|
+ const translationLanguage
|
|
72
|
+ = getState()['features/base/conference'].conference
|
|
73
|
+ .getLocalParticipantProperty(P_NAME_TRANSLATION_LANGUAGE);
|
50
|
74
|
|
51
|
75
|
try {
|
|
76
|
+ const transcriptMessageID = json.message_id;
|
|
77
|
+ const participantName = json.participant.name;
|
|
78
|
+ const isInterim = json.is_interim;
|
|
79
|
+ const stability = json.stability;
|
|
80
|
+
|
|
81
|
+ if (json.type === JSON_TYPE_TRANSLATION_RESULT
|
|
82
|
+ && json.language === translationLanguage) {
|
|
83
|
+ // Displays final results in the target language if translation is
|
|
84
|
+ // enabled.
|
|
85
|
+
|
|
86
|
+ const newTranscriptMessage = {
|
|
87
|
+ participantName,
|
|
88
|
+ final: json.text
|
|
89
|
+ };
|
|
90
|
+
|
|
91
|
+ dispatch(updateTranscriptMessage(transcriptMessageID,
|
|
92
|
+ newTranscriptMessage));
|
|
93
|
+
|
|
94
|
+ setTimeout(() => {
|
|
95
|
+ dispatch(removeTranscriptMessage(transcriptMessageID));
|
|
96
|
+ }, REMOVE_AFTER_MS);
|
|
97
|
+
|
|
98
|
+ } else if (json.type === JSON_TYPE_TRANSCRIPTION_RESULT
|
|
99
|
+ && !translationLanguage) {
|
|
100
|
+ // Displays interim and final results without any translation if
|
|
101
|
+ // translations are disabled.
|
52
|
102
|
|
53
|
|
- // Let's first check if the given object has the correct
|
54
|
|
- // type in the json, which identifies it as a json message sent
|
55
|
|
- // from Jigasi with speech-to-to-text results
|
56
|
|
- if (json.type === 'transcription-result') {
|
57
|
|
- // Extract the useful data from the json.
|
58
|
|
- const isInterim = json.is_interim;
|
59
|
|
- const participantName = json.participant.name;
|
60
|
|
- const stability = json.stability;
|
61
|
103
|
const text = json.transcript[0].text;
|
62
|
|
- const transcriptMessageID = json.message_id;
|
63
|
|
-
|
64
|
|
- // If this is the first result with the unique message ID,
|
65
|
|
- // we add it to the state along with the name of the participant
|
66
|
|
- // who said given text
|
67
|
|
- if (!getState()['features/subtitles']
|
68
|
|
- .transcriptMessages.has(transcriptMessageID)) {
|
69
|
|
- dispatch(addTranscriptMessage(transcriptMessageID,
|
70
|
|
- participantName));
|
71
|
|
- }
|
72
|
|
- const { transcriptMessages } = getState()['features/subtitles'];
|
|
104
|
+
|
|
105
|
+ // We update the previous transcript message with the same
|
|
106
|
+ // message ID or adds a new transcript message if it does not
|
|
107
|
+ // exist in the map.
|
73
|
108
|
const newTranscriptMessage
|
74
|
|
- = { ...transcriptMessages.get(transcriptMessageID) };
|
|
109
|
+ = { ...getState()['features/subtitles'].transcriptMessages
|
|
110
|
+ .get(transcriptMessageID) || { participantName } };
|
75
|
111
|
|
76
|
112
|
// If this is final result, update the state as a final result
|
77
|
113
|
// and start a count down to remove the subtitle from the state
|