|
@@ -1,5 +1,11 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
|
3
|
+import { getLocalParticipant } from '../base/participants';
|
|
4
|
+import { extractFqnFromPath } from '../dynamic-branding/functions';
|
|
5
|
+
|
|
6
|
+import { REACTIONS } from './constants';
|
|
7
|
+import logger from './logger';
|
|
8
|
+
|
3
|
9
|
/**
|
4
|
10
|
* Returns the queue of reactions.
|
5
|
11
|
*
|
|
@@ -9,3 +15,74 @@
|
9
|
15
|
export function getReactionsQueue(state: Object) {
|
10
|
16
|
return state['features/reactions'].queue;
|
11
|
17
|
}
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * Returns reaction key from the reaction message.
|
|
21
|
+ *
|
|
22
|
+ * @param {string} message - The reaction message.
|
|
23
|
+ * @returns {string}
|
|
24
|
+ */
|
|
25
|
+export function getReactionKeyByMessage(message: string): ?string {
|
|
26
|
+ return Object.keys(REACTIONS).find(key => REACTIONS[key].message === `:${message}:`);
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+/**
|
|
30
|
+ * Gets reactions key array from concatenated message.
|
|
31
|
+ *
|
|
32
|
+ * @param {string} message - The reaction message.
|
|
33
|
+ * @returns {Array}
|
|
34
|
+ */
|
|
35
|
+export function messageToKeyArray(message: string) {
|
|
36
|
+ let formattedMessage = message.replace(/::/g, '-');
|
|
37
|
+
|
|
38
|
+ formattedMessage = formattedMessage.replace(/:/g, '');
|
|
39
|
+ const messageArray = formattedMessage.split('-');
|
|
40
|
+
|
|
41
|
+ return messageArray.map<?string>(getReactionKeyByMessage);
|
|
42
|
+}
|
|
43
|
+
|
|
44
|
+/**
|
|
45
|
+ * Sends reactions to the backend.
|
|
46
|
+ *
|
|
47
|
+ * @param {Object} state - The redux state object.
|
|
48
|
+ * @param {Array} reactions - Reactions array to be sent.
|
|
49
|
+ * @returns {void}
|
|
50
|
+ */
|
|
51
|
+export async function sendReactionsWebhook(state: Object, reactions: Array<?string>) {
|
|
52
|
+ const { webhookProxyUrl: url } = state['features/base/config'];
|
|
53
|
+ const { conference } = state['features/base/conference'];
|
|
54
|
+ const { jwt } = state['features/base/jwt'];
|
|
55
|
+ const { locationURL } = state['features/base/connection'];
|
|
56
|
+ const localParticipant = getLocalParticipant(state);
|
|
57
|
+
|
|
58
|
+ const headers = {
|
|
59
|
+ 'Authorization': `Bearer ${jwt}`,
|
|
60
|
+ 'Content-Type': 'application/json'
|
|
61
|
+ };
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+ const reqBody = {
|
|
65
|
+ meetingFqn: extractFqnFromPath(locationURL.pathname),
|
|
66
|
+ sessionId: conference.sessionId,
|
|
67
|
+ submitted: Date.now(),
|
|
68
|
+ reactions,
|
|
69
|
+ participantId: localParticipant.id,
|
|
70
|
+ participantName: localParticipant.name
|
|
71
|
+ };
|
|
72
|
+
|
|
73
|
+ if (url) {
|
|
74
|
+ try {
|
|
75
|
+ const res = await fetch(`${url}/reactions`, {
|
|
76
|
+ method: 'POST',
|
|
77
|
+ headers,
|
|
78
|
+ body: JSON.stringify(reqBody)
|
|
79
|
+ });
|
|
80
|
+
|
|
81
|
+ if (!res.ok) {
|
|
82
|
+ logger.error('Status error:', res.status);
|
|
83
|
+ }
|
|
84
|
+ } catch (err) {
|
|
85
|
+ logger.error('Could not send request', err);
|
|
86
|
+ }
|
|
87
|
+ }
|
|
88
|
+}
|