lib/hooks.js
/**
 * Poll for track progress for the given interval (in miliseconds)
 * @param interval - ms interval
 */
Poll for track progress for the given interval (in miliseconds)
@param interval - ms interval
Poll for track progress for the given interval ( in miliseconds ) @param interval - ms interval
function useProgress(updateInterval) {
    var _this = this;
    var _a = react_1.useState({ position: 0, duration: 0, buffered: 0 }), state = _a[0], setState = _a[1];
    var playerState = exports.usePlaybackState();
    var getProgress = function () { return __awaiter(_this, void 0, void 0, function () {
        var _a, position, duration, buffered;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0: return [4 , Promise.all([
                        index_1.default.getPosition(),
                        index_1.default.getDuration(),
                        index_1.default.getBufferedPosition(),
                    ])];
                case 1:
                    _a = _b.sent(), position = _a[0], duration = _a[1], buffered = _a[2];
                    setState({ position: position, duration: duration, buffered: buffered });
                    return [2 ];
            }
        });
    }); };
    react_1.useEffect(function () {
        if (playerState !== index_1.State.Playing && playerState !== index_1.State.Buffering)
            return;
        var poll = setInterval(getProgress, updateInterval || 1000);
        return function () { return clearInterval(poll); };
    }, [playerState]);
    return state;
}
function useProgress ( updateInterval ) { var _this = this ; var _a = react_1 . useState ( { position : 0 , duration : 0 , buffered : 0 } ) , state = _a [ 0 ] , setState = _a [ 1 ] ; var playerState = exports . usePlaybackState ( ) ; var getProgress = function ( ) { return __awaiter ( _this , void 0 , void 0 , function ( ) { var _a , position , duration , buffered ; return __generator ( this , function ( _b ) { switch ( _b . label ) { case 0 : return [ 4 , Promise . all ( [ index_1 . default . getPosition ( ) , index_1 . default . getDuration ( ) , index_1 . default . getBufferedPosition ( ) , ] ) ] ; case 1 : _a = _b . sent ( ) , position = _a [ 0 ] , duration = _a [ 1 ] , buffered = _a [ 2 ] ; setState ( { position : position , duration : duration , buffered : buffered } ) ; return [ 2 ] ; } } ) ; } ) ; } ; react_1 . useEffect ( function ( ) { if ( playerState !== index_1 . State . Playing && playerState !== index_1 . State . Buffering ) return ; var poll = setInterval ( getProgress , updateInterval || 1000 ) ; return function ( ) { return clearInterval ( poll ) ; } ; } , [ playerState ] ) ; return state ; }
Poll for track progress for the given interval (in miliseconds)
 @param interval - ms interval
Poll for track progress for the given interval ( in miliseconds ) @param interval - ms interval
/*yield*/ /*return*/