From bff5e7116a319fee6cb45073075a25cd5d066e9c Mon Sep 17 00:00:00 2001 From: DispatchCommit Date: Mon, 21 Jun 2021 15:59:01 -0700 Subject: [PATCH] cleanup recsys code --- .../internal/plugins/videojs-recsys/plugin.js | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js b/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js index 2c159d317..5993b2063 100644 --- a/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js +++ b/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js @@ -58,18 +58,22 @@ function sendRecsysEvents(recsys) { body: JSON.stringify(recsys), }; - fetch(recsysEndpoint, requestOptions) - .then((response) => response.json()) - .then((data) => { - console.log(`Recsys response data:`, data); - }); + try { + fetch(recsysEndpoint, requestOptions) + .then((response) => response.json()) + .then((data) => { + // console.log(`Recsys response data:`, data); + }); + } catch (error) { + // console.error(`Recsys Error`, error); + } } const defaults = { endpoint: recsysEndpoint, recsysId: recsysId, - videoId: '0', - userId: '0', + videoId: null, + userId: 0, debug: false, }; @@ -81,7 +85,9 @@ class RecsysPlugin extends Component { super(player, options); // Plugin started - console.log(`Created recsys plugin for: videoId:${options.videoId}, userId:${options.userId}`); + if (options.debug) { + this.log(`Created recsys plugin for: videoId:${options.videoId}, userId:${options.userId}`); + } // To help with debugging, we'll add a global vjs object with the video js player window.vjs = player; @@ -101,6 +107,7 @@ class RecsysPlugin extends Component { player.on('timeupdate', (event) => this.onTimeUpdate(event)); player.on('seeked', (event) => this.onSeeked(event)); + // Event trigger to send recsys event player.on('dispose', (event) => this.onDispose(event)); } @@ -120,7 +127,6 @@ class RecsysPlugin extends Component { this.loadedAt, false ); - console.log(event); sendRecsysEvents(event); } @@ -154,7 +160,6 @@ class RecsysPlugin extends Component { } onSeeked(event) { - console.log(event); const recsysEvent = newRecsysEvent(RecsysData.event.scrub, this.lastTimeUpdate, this.player.currentTime()); this.log('onSeeked', recsysEvent); this.addRecsysEvent(recsysEvent); @@ -165,7 +170,9 @@ class RecsysPlugin extends Component { } log(...args) { - console.log(`Recsys Debug:`, JSON.stringify(args)); + if (this.options_.debug) { + console.log(`Recsys Debug:`, JSON.stringify(args)); + } } }