Skip to content

Commit

Permalink
Use seek interval length to decide seek event
Browse files Browse the repository at this point in the history
  • Loading branch information
itotallyrock committed Jun 28, 2017
1 parent cd88f43 commit b48c52a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var FAKE_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537
var ORIGIN_HEADER = {Origin: 'https://open.spotify.com'};
var KEEPALIVE_HEADER = {Connection: 'keep-alive', Origin: 'https://open.spotify.com'};

var SEEK_INTERVAL_LENGTH = 250;

function getJSON(obj) {
return new Promise(function (resolve, reject) {
if (obj.params) {
Expand Down Expand Up @@ -241,8 +243,8 @@ function SpotifyWebHelper(opts) {
var seekingInterval = null;
var startSeekingInterval = function () {
seekingInterval = setInterval(() => {
this.status.playing_position += 0.25; // eslint-disable-line camelcase
}, 250);
this.status.playing_position += SEEK_INTERVAL_LENGTH / 1000; // eslint-disable-line camelcase
}, SEEK_INTERVAL_LENGTH);
};
var stopSeekingInterval = function () {
clearInterval(seekingInterval);
Expand Down Expand Up @@ -281,6 +283,8 @@ function SpotifyWebHelper(opts) {
}
}
if (Math.abs(this.status.playing_position - status.playing_position) > 5) {
// Guarantee seekingInterval won't affect the seek event
if (Math.abs(this.status.playing_position - status.playing_position) > (2 * SEEK_INTERVAL_LENGTH) / 1000) {
this.player.emit('seek', status.playing_position);
}
};
Expand Down

0 comments on commit b48c52a

Please sign in to comment.