cleanup recsys code

This commit is contained in:
DispatchCommit 2021-06-21 15:59:01 -07:00 committed by jessopb
parent aec52dc6cb
commit bff5e7116a

View file

@ -58,18 +58,22 @@ function sendRecsysEvents(recsys) {
body: JSON.stringify(recsys), body: JSON.stringify(recsys),
}; };
try {
fetch(recsysEndpoint, requestOptions) fetch(recsysEndpoint, requestOptions)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
console.log(`Recsys response data:`, data); // console.log(`Recsys response data:`, data);
}); });
} catch (error) {
// console.error(`Recsys Error`, error);
}
} }
const defaults = { const defaults = {
endpoint: recsysEndpoint, endpoint: recsysEndpoint,
recsysId: recsysId, recsysId: recsysId,
videoId: '0', videoId: null,
userId: '0', userId: 0,
debug: false, debug: false,
}; };
@ -81,7 +85,9 @@ class RecsysPlugin extends Component {
super(player, options); super(player, options);
// Plugin started // 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 // To help with debugging, we'll add a global vjs object with the video js player
window.vjs = player; window.vjs = player;
@ -101,6 +107,7 @@ class RecsysPlugin extends Component {
player.on('timeupdate', (event) => this.onTimeUpdate(event)); player.on('timeupdate', (event) => this.onTimeUpdate(event));
player.on('seeked', (event) => this.onSeeked(event)); player.on('seeked', (event) => this.onSeeked(event));
// Event trigger to send recsys event
player.on('dispose', (event) => this.onDispose(event)); player.on('dispose', (event) => this.onDispose(event));
} }
@ -120,7 +127,6 @@ class RecsysPlugin extends Component {
this.loadedAt, this.loadedAt,
false false
); );
console.log(event);
sendRecsysEvents(event); sendRecsysEvents(event);
} }
@ -154,7 +160,6 @@ class RecsysPlugin extends Component {
} }
onSeeked(event) { onSeeked(event) {
console.log(event);
const recsysEvent = newRecsysEvent(RecsysData.event.scrub, this.lastTimeUpdate, this.player.currentTime()); const recsysEvent = newRecsysEvent(RecsysData.event.scrub, this.lastTimeUpdate, this.player.currentTime());
this.log('onSeeked', recsysEvent); this.log('onSeeked', recsysEvent);
this.addRecsysEvent(recsysEvent); this.addRecsysEvent(recsysEvent);
@ -165,8 +170,10 @@ class RecsysPlugin extends Component {
} }
log(...args) { log(...args) {
if (this.options_.debug) {
console.log(`Recsys Debug:`, JSON.stringify(args)); console.log(`Recsys Debug:`, JSON.stringify(args));
} }
}
} }
videojs.registerComponent('recsys', RecsysPlugin); videojs.registerComponent('recsys', RecsysPlugin);