Skip to content

ES6 integration (?) #85

Open
Open

Description

@DalerAsrorov

Hello, thanks a lot for building the API.

Is there any plans to have an ES6 wrapper of the API? So we could do something like:

import SC from 'soundcloud'; 

SC.init({ ... }); 
SC.get('/tracks', { genres: 'rock' }); 

Activity

  1. ProLoser commented on Aug 1, 2018

    @ProLoser

    I don't know why this wouldn't work but it doesn't.

    sdk.js:23 Uncaught TypeError: Cannot read property 'AudioContext' of undefined

    import SC from 'soundcloud';
    import EVENTS from '../Events';
    
    let track = `/tracks/${window.location.search.substr(1)}`;
    
    const SOUNDCLOUD_STATES = {
      'playing': EVENTS.PLAYING,
      'paused': EVENTS.PAUSED,
      'loading': EVENTS.LOADING,
      'ended': EVENTS.COMPLETE,
      'error': EVENTS.ERROR
    };
    
    SC.stream(track).then(function(player){
      player.play();
    
    
      player.on('state-change', event => {
        window.postMessageNative(SOUNDCLOUD_STATES[event], '*');
      });
    
    
      document.addEventListener('message', window.listener = function(event) {
        let data = JSON.parse(event.data);
        switch (data.type) {
          case EVENTS.PLAY:
            player.play();
            break;
          case EVENTS.PAUSE:
            player.pause();
            break;
          case EVENTS.VOLUME:
            player.setVolume(.5);
            break;
        }
      });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions