All files / src/utilities configState.js

100% Statements 35/35
100% Branches 10/10
100% Functions 3/3
100% Lines 35/35
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                      31x                   160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x                   50x 8x             50x 7x           50x 35x             31x              
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Handles the state of the config object.
 *
 * @module utilities/ConfigState
 */
let ConfigState = (function() {
  /**
   * Resets the config to the default state. This is called on initialize
   * to ensure the user's config is what matters.
   *
   * Public Accessor: AmplitudeHelpers.resetConfig()
   *
   * @access public
   */
  function resetConfig() {
    config.audio = new Audio();
    config.active_metadata = {};
    config.active_album = "";
    config.active_index = 0;
    config.active_playlist = null;
    config.playback_speed = 1.0;
    config.callbacks = {};
    config.songs = [];
    config.playlists = {};
    config.start_song = "";
    config.starting_playlist = "";
    config.starting_playlist_song = "";
    config.repeat = false;
    config.shuffle_list = {};
    config.shuffle_on = false;
    config.default_album_art = "";
    config.default_playlist_art = "";
    config.debug = false;
    config.volume = 0.5;
    config.pre_mute_volume = 0.5;
    config.volume_increment = 5;
    config.volume_decrement = 5;
    config.soundcloud_client = "";
    config.soundcloud_use_art = false;
    config.soundcloud_song_count = 0;
    config.soundcloud_songs_ready = 0;
    config.continue_next = true;
  }
 
  /**
   * Sets the state of the player.
   */
  function setPlayerState() {
    /*
      If paused and the current time is 0 the player is stopped.
    */
    if (config.audio.paused && config.audio.currentTime == 0) {
      config.player_state = "stopped";
    }
 
    /*
      If paused and the current time is greater than 0 the player is
      paused.
    */
    if (config.audio.paused && config.audio.currentTime > 0) {
      config.player_state = "paused";
    }
 
    /*
      If playing, the current state is playing.
    */
    if (!config.audio.paused) {
      config.player_state = "playing";
    }
  }
 
  /*
		Returns the public facing methods
	*/
  return {
    resetConfig: resetConfig,
    setPlayerState: setPlayerState
  };
})();
 
export default ConfigState;