Просмотр исходного кода

Send feedback metadata to JaaS feedback endpoint

j8
hmuresan 3 лет назад
Родитель
Сommit
aea09a8da3

+ 10
- 20
conference.js Просмотреть файл

@@ -1085,17 +1085,6 @@ export default {
1085 1085
         return room && room.isCallstatsEnabled();
1086 1086
     },
1087 1087
 
1088
-    /**
1089
-     * Sends the given feedback through CallStats if enabled.
1090
-     *
1091
-     * @param overallFeedback an integer between 1 and 5 indicating the
1092
-     * user feedback
1093
-     * @param detailedFeedback detailed feedback from the user. Not yet used
1094
-     */
1095
-    sendFeedback(overallFeedback, detailedFeedback) {
1096
-        return room.sendFeedback(overallFeedback, detailedFeedback);
1097
-    },
1098
-
1099 1088
     /**
1100 1089
      * Get speaker stats that track total dominant speaker time.
1101 1090
      *
@@ -2803,14 +2792,15 @@ export default {
2803 2792
             requestFeedbackPromise = Promise.resolve(true);
2804 2793
         }
2805 2794
 
2806
-        // All promises are returning Promise.resolve to make Promise.all to
2807
-        // be resolved when both Promises are finished. Otherwise Promise.all
2808
-        // will reject on first rejected Promise and we can redirect the page
2809
-        // before all operations are done.
2810
-        Promise.all([
2811
-            requestFeedbackPromise,
2812
-            this.leaveRoomAndDisconnect()
2813
-        ]).then(values => {
2795
+        let feedbackResult;
2796
+
2797
+        requestFeedbackPromise
2798
+        .then(res => {
2799
+            feedbackResult = res;
2800
+
2801
+            return this.leaveRoomAndDisconnect();
2802
+        })
2803
+        .then(() => {
2814 2804
             this._room = undefined;
2815 2805
             room = undefined;
2816 2806
 
@@ -2822,7 +2812,7 @@ export default {
2822 2812
             if (!interfaceConfig.SHOW_PROMOTIONAL_CLOSE_PAGE) {
2823 2813
                 APP.API.notifyReadyToClose();
2824 2814
             }
2825
-            APP.store.dispatch(maybeRedirectToWelcomePage(values[0]));
2815
+            APP.store.dispatch(maybeRedirectToWelcomePage(feedbackResult));
2826 2816
         });
2827 2817
     },
2828 2818
 

+ 2
- 2
react/features/base/jwt/middleware.js Просмотреть файл

@@ -134,7 +134,7 @@ function _setJWT(store, next, action) {
134 134
             }
135 135
 
136 136
             if (jwtPayload) {
137
-                const { context, iss } = jwtPayload;
137
+                const { context, iss, sub } = jwtPayload;
138 138
 
139 139
                 action.jwt = jwt;
140 140
                 action.issuer = iss;
@@ -144,7 +144,7 @@ function _setJWT(store, next, action) {
144 144
                     action.callee = context.callee;
145 145
                     action.group = context.group;
146 146
                     action.server = context.server;
147
-                    action.tenant = context.tenant;
147
+                    action.tenant = context.tenant || sub || undefined;
148 148
                     action.user = user;
149 149
 
150 150
                     user && _overwriteLocalParticipant(

+ 49
- 13
react/features/feedback/actions.js Просмотреть файл

@@ -4,6 +4,8 @@ import type { Dispatch } from 'redux';
4 4
 
5 5
 import { FEEDBACK_REQUEST_IN_PROGRESS } from '../../../modules/UI/UIErrors';
6 6
 import { openDialog } from '../base/dialog';
7
+import { isVpaasMeeting } from '../billing-counter/functions';
8
+import { extractFqnFromPath } from '../dynamic-branding/functions';
7 9
 
8 10
 import {
9 11
     CANCEL_FEEDBACK,
@@ -11,9 +13,9 @@ import {
11 13
     SUBMIT_FEEDBACK_SUCCESS
12 14
 } from './actionTypes';
13 15
 import { FeedbackDialog } from './components';
16
+import { sendFeedbackToJaaSRequest } from './functions';
14 17
 
15 18
 declare var config: Object;
16
-declare var interfaceConfig: Object;
17 19
 
18 20
 /**
19 21
  * Caches the passed in feedback in the redux store.
@@ -110,6 +112,39 @@ export function openFeedbackDialog(conference: Object, onClose: ?Function) {
110 112
     });
111 113
 }
112 114
 
115
+/**
116
+ * Sends feedback metadata to JaaS endpoint.
117
+ *
118
+ * @param {JitsiConference} conference - The JitsiConference that is being rated.
119
+ * @param {Object} feedback - The feedback message and score.
120
+ *
121
+ * @returns {Promise}
122
+ */
123
+export function sendJaasFeedbackMetadata(conference: Object, feedback: Object) {
124
+    return (dispatch: Dispatch<any>, getState: Function): Promise<any> => {
125
+        const state = getState();
126
+        const { jaasFeedbackMetadataURL } = state['features/base/config'];
127
+
128
+        const { jwt, user, tenant } = state['features/base/jwt'];
129
+
130
+        if (!isVpaasMeeting(state) || !jaasFeedbackMetadataURL) {
131
+            return Promise.resolve();
132
+        }
133
+
134
+        const meetingFqn = extractFqnFromPath(state['features/base/connection'].locationURL.pathname);
135
+        const feedbackData = {
136
+            ...feedback,
137
+            sessionId: conference.getMeetingUniqueId(),
138
+            userId: user.id,
139
+            meetingFqn,
140
+            jwt,
141
+            tenant
142
+        };
143
+
144
+        return sendFeedbackToJaaSRequest(jaasFeedbackMetadataURL, feedbackData);
145
+    };
146
+}
147
+
113 148
 /**
114 149
  * Send the passed in feedback.
115 150
  *
@@ -125,16 +160,17 @@ export function submitFeedback(
125 160
         score: number,
126 161
         message: string,
127 162
         conference: Object) {
128
-    return (dispatch: Dispatch<any>) => conference.sendFeedback(score, message)
129
-        .then(
130
-            () => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }),
131
-            error => {
132
-                dispatch({
133
-                    type: SUBMIT_FEEDBACK_ERROR,
134
-                    error
135
-                });
136
-
137
-                return Promise.reject(error);
138
-            }
139
-        );
163
+    return (dispatch: Dispatch<any>) =>
164
+        conference.sendFeedback(score, message)
165
+        .then(() => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }))
166
+        .then(() => dispatch(sendJaasFeedbackMetadata(conference, { score,
167
+            message }))
168
+        .catch(error => {
169
+            dispatch({
170
+                type: SUBMIT_FEEDBACK_ERROR,
171
+                error
172
+            });
173
+
174
+            return Promise.reject(error);
175
+        }));
140 176
 }

+ 50
- 0
react/features/feedback/functions.js Просмотреть файл

@@ -0,0 +1,50 @@
1
+// @flow
2
+
3
+import logger from './logger';
4
+
5
+/**
6
+ * Sends feedback metadata to JaaS endpoints.
7
+ *
8
+ * @param {string} url - The JaaS metadata endpoint URL.
9
+ * @param {Object} feedbackData - The feedback data object.
10
+ * @returns {Promise}
11
+ */
12
+export async function sendFeedbackToJaaSRequest(url: string, feedbackData: Object) {
13
+    const {
14
+        jwt,
15
+        sessionId,
16
+        meetingFqn,
17
+        score,
18
+        message,
19
+        userId,
20
+        tenant
21
+    } = feedbackData;
22
+    const headers = {
23
+        'Authorization': `Bearer ${jwt}`,
24
+        'Content-Type': 'application/json'
25
+    };
26
+    const data = {
27
+        sessionId,
28
+        meetingFqn,
29
+        userId,
30
+        tenant,
31
+        submitted: new Date().getTime(),
32
+        rating: score,
33
+        comments: message
34
+    };
35
+
36
+    try {
37
+        const res = await fetch(url, {
38
+            method: 'POST',
39
+            headers,
40
+            body: JSON.stringify(data)
41
+        });
42
+
43
+        if (!res.ok) {
44
+            logger.error('Status error:', res.status);
45
+        }
46
+    } catch (err) {
47
+        logger.error('Could not send request', err);
48
+    }
49
+}
50
+

+ 5
- 0
react/features/feedback/logger.js Просмотреть файл

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

Загрузка…
Отмена
Сохранить