Browse Source

ref(feedback): return promise for submitting callstats feedback

dev1
Leonard Kim 6 years ago
parent
commit
97475026de
3 changed files with 31 additions and 12 deletions
  1. 2
    1
      JitsiConference.js
  2. 23
    10
      modules/statistics/CallStats.js
  3. 6
    1
      modules/statistics/statistics.js

+ 2
- 1
JitsiConference.js View File

@@ -2251,11 +2251,12 @@ JitsiConference.prototype.getLocalParticipantProperty = function(name) {
2251 2251
  * @param overallFeedback an integer between 1 and 5 indicating the
2252 2252
  * user feedback
2253 2253
  * @param detailedFeedback detailed feedback from the user. Not yet used
2254
+ * @returns {Promise} Resolves if feedback is submitted successfully.
2254 2255
  */
2255 2256
 JitsiConference.prototype.sendFeedback = function(
2256 2257
         overallFeedback,
2257 2258
         detailedFeedback) {
2258
-    this.statistics.sendFeedback(overallFeedback, detailedFeedback);
2259
+    return this.statistics.sendFeedback(overallFeedback, detailedFeedback);
2259 2260
 };
2260 2261
 
2261 2262
 /**

+ 23
- 10
modules/statistics/CallStats.js View File

@@ -470,16 +470,29 @@ export default class CallStats {
470 470
      * @param comment detailed feedback from the user.
471 471
      */
472 472
     static sendFeedback(conferenceID, overall, comment) {
473
-        if (CallStats.backend) {
474
-            CallStats.backend.sendUserFeedback(
475
-                conferenceID, {
476
-                    userID: CallStats.userID,
477
-                    overall,
478
-                    comment
479
-                });
480
-        } else {
481
-            logger.error('Failed to submit feedback to CallStats - no backend');
482
-        }
473
+        return new Promise((resolve, reject) => {
474
+            if (CallStats.backend) {
475
+                CallStats.backend.sendUserFeedback(
476
+                    conferenceID,
477
+                    {
478
+                        userID: CallStats.userID,
479
+                        overall,
480
+                        comment
481
+                    },
482
+                    (status, message) => {
483
+                        if (status === 'success') {
484
+                            resolve(message);
485
+                        } else {
486
+                            reject(message);
487
+                        }
488
+                    });
489
+            } else {
490
+                const reason = 'Failed to submit feedback to CallStats - no backend';
491
+
492
+                logger.error(reason);
493
+                reject(reason);
494
+            }
495
+        });
483 496
     }
484 497
 
485 498
     /**

+ 6
- 1
modules/statistics/statistics.js View File

@@ -670,15 +670,20 @@ Statistics.sendLog = function(m) {
670 670
  *
671 671
  * @param overall an integer between 1 and 5 indicating the user's rating.
672 672
  * @param comment the comment from the user.
673
+ * @returns {Promise} Resolves when callstats feedback has been submitted
674
+ * successfully.
673 675
  */
674 676
 Statistics.prototype.sendFeedback = function(overall, comment) {
675
-    CallStats.sendFeedback(this.options.confID, overall, comment);
677
+    // Statistics.analytics.sendEvent is currently fire and forget, without
678
+    // confirmation of successful send.
676 679
     Statistics.analytics.sendEvent(
677 680
         FEEDBACK,
678 681
         {
679 682
             rating: overall,
680 683
             comment
681 684
         });
685
+
686
+    return CallStats.sendFeedback(this.options.confID, overall, comment);
682 687
 };
683 688
 
684 689
 Statistics.LOCAL_JID = require('../../service/statistics/constants').LOCAL_JID;

Loading…
Cancel
Save