From 762f529f1d060fc0fed2f585c17ed6228f2d7ba9 Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Fri, 19 Jan 2018 14:19:55 -0800 Subject: [PATCH] feat(api): expose a way to submit feedback Spot will need a way to submit call feedback using the iframe api. For now expose a method on conference.js to submit that feedback. Exposing on conference.js looks to be the existing pattern... Also add an event to notify consumers of the iframe api that feedback was submitted, as postMessage is async and the notification can at least give some guarantee maybe. I haven't updated documentation yet as I'm not confident about this api. --- conference.js | 21 ++++++++++++++++++++- modules/API/API.js | 14 ++++++++++++++ modules/API/external/external_api.js | 2 ++ react/features/feedback/index.js | 1 + react/features/feedback/middleware.js | 26 ++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 react/features/feedback/middleware.js diff --git a/conference.js b/conference.js index 57ecec6de..3ec751eb7 100644 --- a/conference.js +++ b/conference.js @@ -91,7 +91,10 @@ import { import { statsEmitter } from './react/features/connection-indicator'; import { showDesktopPicker } from './react/features/desktop-picker'; import { appendSuffix } from './react/features/display-name'; -import { maybeOpenFeedbackDialog } from './react/features/feedback'; +import { + maybeOpenFeedbackDialog, + submitFeedback +} from './react/features/feedback'; import { mediaPermissionPromptVisibilityChanged, suspendDetected @@ -2798,5 +2801,21 @@ export default { setAudioMuteStatus(muted) { APP.UI.setAudioMuted(this.getMyUserId(), muted); APP.API.notifyAudioMutedStatusChanged(muted); + }, + + /** + * Dispatches the passed in feedback for submission. The submitted score + * should be a number inclusively between 1 through 5, or -1 for no score. + * + * @param {number} score - a number between 1 and 5 (inclusive) or -1 for no + * score. + * @param {string} message - An optional message to attach to the feedback + * in addition to the score. + * @returns {void} + */ + submitFeedback(score = -1, message = '') { + if (score === -1 || (score >= 1 && score <= 5)) { + APP.store.dispatch(submitFeedback(score, message, room)); + } } }; diff --git a/modules/API/API.js b/modules/API/API.js index 07943baa5..a1dcae336 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -59,6 +59,10 @@ function initCommands() { sendAnalytics(createApiEvent('display.name.changed')); APP.conference.changeLocalDisplayName(displayName); }, + 'submit-feedback': feedback => { + sendAnalytics(createApiEvent('submit.feedback')); + APP.conference.submitFeedback(feedback.score, feedback.message); + }, 'toggle-audio': () => { sendAnalytics(createApiEvent('toggle-audio')); logger.log('Audio toggle: API command received'); @@ -456,6 +460,16 @@ class API { }); } + /** + * Notify external application (if API is enabled) that conference feedback + * has been submitted. Intended to be used in conjunction with the + * submit-feedback command to get notified if feedback was submitted. + * + * @returns {void} + */ + notifyFeedbackSubmitted() { + this._sendEvent({ name: 'feedback-submitted' }); + } /** * Disposes the allocated resources. diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js index 1a3a4a53a..9408effb2 100644 --- a/modules/API/external/external_api.js +++ b/modules/API/external/external_api.js @@ -21,6 +21,7 @@ const commands = { displayName: 'display-name', email: 'email', hangup: 'video-hangup', + submitFeedback: 'submit-feedback', toggleAudio: 'toggle-audio', toggleChat: 'toggle-chat', toggleContactList: 'toggle-contact-list', @@ -38,6 +39,7 @@ const events = { 'audio-availability-changed': 'audioAvailabilityChanged', 'audio-mute-status-changed': 'audioMuteStatusChanged', 'display-name-change': 'displayNameChange', + 'feedback-submitted': 'feedbackSubmitted', 'incoming-message': 'incomingMessage', 'outgoing-message': 'outgoingMessage', 'participant-joined': 'participantJoined', diff --git a/react/features/feedback/index.js b/react/features/feedback/index.js index b2e9c09f6..a29aa08e0 100644 --- a/react/features/feedback/index.js +++ b/react/features/feedback/index.js @@ -2,4 +2,5 @@ export * from './actions'; export * from './actionTypes'; export * from './components'; +import './middleware'; import './reducer'; diff --git a/react/features/feedback/middleware.js b/react/features/feedback/middleware.js new file mode 100644 index 000000000..26b3baa8f --- /dev/null +++ b/react/features/feedback/middleware.js @@ -0,0 +1,26 @@ +/* @flow */ + +import { MiddlewareRegistry } from '../base/redux'; + +import { SUBMIT_FEEDBACK } from './actionTypes'; + +declare var APP: Object; + +/** + * Implements the middleware of the feature feedback. + * + * @param {Store} store - The redux store. + * @returns {Function} + */ +// eslint-disable-next-line no-unused-vars +MiddlewareRegistry.register(store => next => action => { + switch (action.type) { + case SUBMIT_FEEDBACK: + if (typeof APP === 'object') { + APP.API.notifyFeedbackSubmitted(); + } + break; + } + + return next(action); +});