mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2025-12-30 11:22:31 +00:00
Send feedback metadata to JaaS feedback endpoint
This commit is contained in:
committed by
Horatiu Muresan
parent
01a127b557
commit
aea09a8da3
@@ -4,6 +4,8 @@ import type { Dispatch } from 'redux';
|
||||
|
||||
import { FEEDBACK_REQUEST_IN_PROGRESS } from '../../../modules/UI/UIErrors';
|
||||
import { openDialog } from '../base/dialog';
|
||||
import { isVpaasMeeting } from '../billing-counter/functions';
|
||||
import { extractFqnFromPath } from '../dynamic-branding/functions';
|
||||
|
||||
import {
|
||||
CANCEL_FEEDBACK,
|
||||
@@ -11,9 +13,9 @@ import {
|
||||
SUBMIT_FEEDBACK_SUCCESS
|
||||
} from './actionTypes';
|
||||
import { FeedbackDialog } from './components';
|
||||
import { sendFeedbackToJaaSRequest } from './functions';
|
||||
|
||||
declare var config: Object;
|
||||
declare var interfaceConfig: Object;
|
||||
|
||||
/**
|
||||
* Caches the passed in feedback in the redux store.
|
||||
@@ -110,6 +112,39 @@ export function openFeedbackDialog(conference: Object, onClose: ?Function) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends feedback metadata to JaaS endpoint.
|
||||
*
|
||||
* @param {JitsiConference} conference - The JitsiConference that is being rated.
|
||||
* @param {Object} feedback - The feedback message and score.
|
||||
*
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function sendJaasFeedbackMetadata(conference: Object, feedback: Object) {
|
||||
return (dispatch: Dispatch<any>, getState: Function): Promise<any> => {
|
||||
const state = getState();
|
||||
const { jaasFeedbackMetadataURL } = state['features/base/config'];
|
||||
|
||||
const { jwt, user, tenant } = state['features/base/jwt'];
|
||||
|
||||
if (!isVpaasMeeting(state) || !jaasFeedbackMetadataURL) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const meetingFqn = extractFqnFromPath(state['features/base/connection'].locationURL.pathname);
|
||||
const feedbackData = {
|
||||
...feedback,
|
||||
sessionId: conference.getMeetingUniqueId(),
|
||||
userId: user.id,
|
||||
meetingFqn,
|
||||
jwt,
|
||||
tenant
|
||||
};
|
||||
|
||||
return sendFeedbackToJaaSRequest(jaasFeedbackMetadataURL, feedbackData);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the passed in feedback.
|
||||
*
|
||||
@@ -125,16 +160,17 @@ export function submitFeedback(
|
||||
score: number,
|
||||
message: string,
|
||||
conference: Object) {
|
||||
return (dispatch: Dispatch<any>) => conference.sendFeedback(score, message)
|
||||
.then(
|
||||
() => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }),
|
||||
error => {
|
||||
dispatch({
|
||||
type: SUBMIT_FEEDBACK_ERROR,
|
||||
error
|
||||
});
|
||||
return (dispatch: Dispatch<any>) =>
|
||||
conference.sendFeedback(score, message)
|
||||
.then(() => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }))
|
||||
.then(() => dispatch(sendJaasFeedbackMetadata(conference, { score,
|
||||
message }))
|
||||
.catch(error => {
|
||||
dispatch({
|
||||
type: SUBMIT_FEEDBACK_ERROR,
|
||||
error
|
||||
});
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
return Promise.reject(error);
|
||||
}));
|
||||
}
|
||||
|
||||
50
react/features/feedback/functions.js
Normal file
50
react/features/feedback/functions.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// @flow
|
||||
|
||||
import logger from './logger';
|
||||
|
||||
/**
|
||||
* Sends feedback metadata to JaaS endpoints.
|
||||
*
|
||||
* @param {string} url - The JaaS metadata endpoint URL.
|
||||
* @param {Object} feedbackData - The feedback data object.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export async function sendFeedbackToJaaSRequest(url: string, feedbackData: Object) {
|
||||
const {
|
||||
jwt,
|
||||
sessionId,
|
||||
meetingFqn,
|
||||
score,
|
||||
message,
|
||||
userId,
|
||||
tenant
|
||||
} = feedbackData;
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${jwt}`,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
const data = {
|
||||
sessionId,
|
||||
meetingFqn,
|
||||
userId,
|
||||
tenant,
|
||||
submitted: new Date().getTime(),
|
||||
rating: score,
|
||||
comments: message
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
logger.error('Status error:', res.status);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Could not send request', err);
|
||||
}
|
||||
}
|
||||
|
||||
5
react/features/feedback/logger.js
Normal file
5
react/features/feedback/logger.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// @flow
|
||||
|
||||
import { getLogger } from '../base/logging/functions';
|
||||
|
||||
export default getLogger('features/feedback');
|
||||
Reference in New Issue
Block a user