소스 검색

feat(reactions-webhook) Added reactions backend call for webhook (#9534)

* Added backend call for reactions webhook

* Updated webhook url

* Fixed linting error

* Code review fixes

* Fixed linting errors
j8
robertpin 4 년 전
부모
커밋
ea0d953d1c
No account linked to committer's email address
3개의 변경된 파일90개의 추가작업 그리고 1개의 파일을 삭제
  1. 77
    0
      react/features/reactions/functions.any.js
  2. 5
    0
      react/features/reactions/logger.js
  3. 8
    1
      react/features/reactions/middleware.js

+ 77
- 0
react/features/reactions/functions.any.js 파일 보기

1
 // @flow
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
  * Returns the queue of reactions.
10
  * Returns the queue of reactions.
5
  *
11
  *
9
 export function getReactionsQueue(state: Object) {
15
 export function getReactionsQueue(state: Object) {
10
     return state['features/reactions'].queue;
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
+}

+ 5
- 0
react/features/reactions/logger.js 파일 보기

1
+// @flow
2
+
3
+import { getLogger } from '../base/logging/functions';
4
+
5
+export default getLogger('features/base/reactions');

+ 8
- 1
react/features/reactions/middleware.js 파일 보기

2
 
2
 
3
 import { ENDPOINT_REACTION_NAME } from '../../../modules/API/constants';
3
 import { ENDPOINT_REACTION_NAME } from '../../../modules/API/constants';
4
 import { MiddlewareRegistry } from '../base/redux';
4
 import { MiddlewareRegistry } from '../base/redux';
5
+import { isVpaasMeeting } from '../billing-counter/functions';
5
 
6
 
6
 import {
7
 import {
7
     SET_REACTIONS_MESSAGE,
8
     SET_REACTIONS_MESSAGE,
17
     setReactionQueue
18
     setReactionQueue
18
 } from './actions.any';
19
 } from './actions.any';
19
 import { REACTIONS } from './constants';
20
 import { REACTIONS } from './constants';
21
+import { messageToKeyArray, sendReactionsWebhook } from './functions.any';
20
 
22
 
21
 
23
 
22
 declare var APP: Object;
24
 declare var APP: Object;
46
     }
48
     }
47
 
49
 
48
     case CLEAR_REACTIONS_MESSAGE: {
50
     case CLEAR_REACTIONS_MESSAGE: {
49
-        const { message } = getState()['features/reactions'];
51
+        const state = getState();
52
+        const { message } = state['features/reactions'];
53
+
54
+        if (isVpaasMeeting(state)) {
55
+            sendReactionsWebhook(state, messageToKeyArray(message));
56
+        }
50
 
57
 
51
         dispatch(addReactionsMessageToChat(message));
58
         dispatch(addReactionsMessageToChat(message));
52
 
59
 

Loading…
취소
저장