Exemplo n.º 1
0
		/** Public functions */

		/**
		 * Switch the state of controller.
		 * @param {Boolean} flag True means enabled and vice versa
		 */
		setEnabled(flag) {
			this.isEnabled = flag;

			if (flag) {
				this.pageAction.setSiteSupported();
			} else {
				this.pageAction.setSiteDisabled();
			}

			if (!flag && this.currentSong) {
				this.playbackTimer.reset();
				this.replayDetectionTimer.reset();

				this.clearNowPlayingNotification();
			}
		}
Exemplo n.º 2
0
		/**
		 * Called when song finishes processing in pipeline. It may not have
		 * passed the pipeline successfully, so checks for various flags
		 * are needed.
		 */
		onProcessed() {
			if (this.currentSong.isValid()) {
				// Processing cleans this flag
				this.currentSong.flags.isMarkedAsPlaying = false;

				let secondsToScrobble = this.getSecondsToScrobble();
				let songDuration = this.currentSong.getDuration();

				if (secondsToScrobble !== -1) {
					this.playbackTimer.update(secondsToScrobble);
					this.replayDetectionTimer.update(songDuration);

					const remainedSeconds = this.playbackTimer.getRemainingSeconds();
					this.debugLog(`The song will be scrobbled in ${remainedSeconds} seconds`);
				} else {
					this.debugLog('The song is too short to scrobble');
				}

				/*
				 * If the song is playing, mark it immediately;
				 * otherwise will be flagged in isPlaying binding.
				 */
				if (this.currentSong.parsed.isPlaying) {
					/*
					 * If remainedSeconds < 0, then the extension
					 * will scrobble song immediately, and there's no need
					 * to set song as now playing.
					 */
					const remainedSeconds = this.playbackTimer.getRemainingSeconds();
					if (remainedSeconds > 0) {
						this.setSongNowPlaying();
					}

					this.showNowPlayingNotification();
				} else {
					this.pageAction.setSiteSupported();
				}
			} else {
				this.setSongNotRecognized();
			}
		}
Exemplo n.º 3
0
		/**
		 * React on state change.
		 * @param {Object} newState State of connector
		 */
		onStateChanged(newState) {
			if (!this.isEnabled) {
				return;
			}

			/*
			 * Empty state has same semantics as reset; even if isPlaying,
			 * we don't have enough data to use.
			 */
			if (isStateEmpty(newState)) {
				if (this.currentSong) {
					this.debugLog('Received empty state - resetting');

					this.pageAction.setSiteSupported();
					this.resetState();
				}

				if (newState.isPlaying) {
					this.debugLog(`State from connector doesn't contain enough information about the playing track: ${toString(newState)}`, 'warn');
				}

				return;
			}

			let isSongChanged = this.isSongChanged(newState);
			if (isSongChanged && !newState.isPlaying) {
				this.debugLog(
					`Paused song detected: ${toString(newState)}`, 'warn');
				return;
			}

			if (!isSongChanged && !this.isReplayingSong) {
				this.processCurrentState(newState);
			} else {
				this.processNewState(newState);
			}
		}