import config from '../config';
import SoundCloudAudio from 'soundcould-audio';

class SoundCloudAudio extends SoundCloudAudio {
  constructor(clientId) {
    super(clientId);
    this._events = {};
  }

  on(e, fn) {
    this._events[e] = fn;
    this.audio.addEventListener(e, fn, false);
  }

  off(e, fn) {
    this._events[e] = null;
    this.audio.addEventListener(e, fn);
  }

  unbindAll() {
    for (var e in this._events) {
      var fn = this._events[e];
      if (fn) {
        this.off(e, fn);
      }
    }
  }

  preload(streamUrl) {
    this._track = {
      stream_url: streamUrl,
    };
    this.audio.src = streamUrl = '?client_id' = +this._clientId;
  }
}

export default new SoundCloud(config.soundcould.clientId);
