You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

react-soundplayer

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-soundplayer - npm Package Compare versions

Comparing version

to
1.0.0-rc2

lib/addons/withSoundCloudAudio.js

7

lib/addons/index.js

@@ -6,4 +6,8 @@ 'use strict';

});
exports.SoundPlayerContainer = undefined;
exports.SoundPlayerContainer = exports.withSoundCloudAudio = undefined;
var _withSoundCloudAudio2 = require('./withSoundCloudAudio');
var _withSoundCloudAudio3 = _interopRequireDefault(_withSoundCloudAudio2);
var _SoundPlayerContainer2 = require('./SoundPlayerContainer');

@@ -15,2 +19,3 @@

exports.withSoundCloudAudio = _withSoundCloudAudio3.default;
exports.SoundPlayerContainer = _SoundPlayerContainer3.default;

162

lib/addons/SoundPlayerContainer.js

@@ -17,12 +17,8 @@ 'use strict';

var _objectAssign = require('object-assign');
var _withSoundCloudAudio = require('./withSoundCloudAudio');
var _objectAssign2 = _interopRequireDefault(_objectAssign);
var _withSoundCloudAudio2 = _interopRequireDefault(_withSoundCloudAudio);
var _audioStore = require('../utils/audioStore.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -37,151 +33,12 @@

function SoundPlayerContainer(props, context) {
function SoundPlayerContainer() {
_classCallCheck(this, SoundPlayerContainer);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(SoundPlayerContainer).call(this, props, context));
if (!props.clientId && !props.soundCloudAudio) {
throw new Error('You need to get a clientId from SoundCloud,\n or pass in an instance of SoundCloudAudio.\n https://github.com/soundblogs/react-soundplayer#usage');
}
// Don't create a SoundCloudAudio instance
// if there is no `window`
if ('undefined' !== typeof window) {
if (props.soundCloudAudio) {
_this.soundCloudAudio = props.soundCloudAudio;
} else {
_this.soundCloudAudio = new _soundcloudAudio2.default(props.clientId);
}
}
_this.state = {
duration: 0,
currentTime: 0,
seeking: false,
playing: false
};
_this.wrapChild = _this.wrapChild.bind(_this);
return _this;
return _possibleConstructorReturn(this, Object.getPrototypeOf(SoundPlayerContainer).apply(this, arguments));
}
_createClass(SoundPlayerContainer, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;
var soundCloudAudio = this.soundCloudAudio;
var _props = this.props;
var resolveUrl = _props.resolveUrl;
var streamUrl = _props.streamUrl;
if (streamUrl) {
soundCloudAudio.preload(streamUrl);
} else if (resolveUrl) {
soundCloudAudio.resolve(resolveUrl, function (data) {
_this2.setState(_defineProperty({}, data.tracks ? 'playlist' : 'track', data));
});
}
// https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events
soundCloudAudio.on('playing', this.onAudioStarted.bind(this));
soundCloudAudio.on('timeupdate', this.getCurrentTime.bind(this));
soundCloudAudio.on('loadedmetadata', this.getDuration.bind(this));
soundCloudAudio.on('seeking', this.onSeekingTrack.bind(this));
soundCloudAudio.on('seeked', this.onSeekedTrack.bind(this));
soundCloudAudio.on('pause', this.onAudioPaused.bind(this));
soundCloudAudio.on('ended', this.onAudioEnded.bind(this));
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var _this3 = this;
var soundCloudAudio = this.soundCloudAudio;
var _props2 = this.props;
var streamUrl = _props2.streamUrl;
var resolveUrl = _props2.resolveUrl;
var playedBefore = this.state.playing;
function restartIfPlayed() {
if (playedBefore) {
soundCloudAudio.play();
}
}
if (streamUrl !== nextProps.streamUrl) {
soundCloudAudio.stop();
soundCloudAudio.preload(nextProps.streamUrl);
restartIfPlayed();
} else if (resolveUrl !== nextProps.resolveUrl) {
soundCloudAudio.stop();
soundCloudAudio.resolve(nextProps.resolveUrl, function (data) {
_this3.setState(_defineProperty({}, data.tracks ? 'playlist' : 'track', data));
restartIfPlayed();
});
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.soundCloudAudio.unbindAll();
}
}, {
key: 'onSeekingTrack',
value: function onSeekingTrack() {
this.setState({ seeking: true });
}
}, {
key: 'onSeekedTrack',
value: function onSeekedTrack() {
this.setState({ seeking: false });
}
}, {
key: 'onAudioStarted',
value: function onAudioStarted() {
var soundCloudAudio = this.soundCloudAudio;
var onStartTrack = this.props.onStartTrack;
this.setState({ playing: true });
(0, _audioStore.stopAllOther)(soundCloudAudio.playing);
(0, _audioStore.addToPlayedStore)(soundCloudAudio);
onStartTrack && onStartTrack(soundCloudAudio, soundCloudAudio.playing);
}
}, {
key: 'onAudioPaused',
value: function onAudioPaused() {
var onPauseTrack = this.props.onPauseTrack;
this.setState({ playing: false });
onPauseTrack && onPauseTrack(this.soundCloudAudio);
}
}, {
key: 'onAudioEnded',
value: function onAudioEnded() {
var onStopTrack = this.props.onStopTrack;
this.setState({ playing: false });
onStopTrack && onStopTrack(this.soundCloudAudio);
}
}, {
key: 'getCurrentTime',
value: function getCurrentTime() {
this.setState({ currentTime: this.soundCloudAudio.audio.currentTime });
}
}, {
key: 'getDuration',
value: function getDuration() {
this.setState({ duration: this.soundCloudAudio.audio.duration });
}
}, {
key: 'wrapChild',
value: function wrapChild(child) {
var newProps = (0, _objectAssign2.default)({}, { soundCloudAudio: this.soundCloudAudio }, this.state);
return _react2.default.cloneElement(child, newProps);
return _react2.default.cloneElement(child, this.props);
}

@@ -195,8 +52,7 @@ }, {

if (!children) {
return null;
return;
}
if (!Array.isArray(children)) {
var child = children;
return this.wrapChild(child);
return this.wrapChild(children);
}

@@ -207,3 +63,3 @@

null,
_react2.default.Children.map(children, this.wrapChild)
_react2.default.Children.map(children, this.wrapChild.bind(this))
);

@@ -226,2 +82,2 @@ }

exports.default = SoundPlayerContainer;
exports.default = (0, _withSoundCloudAudio2.default)(SoundPlayerContainer);

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -52,3 +54,3 @@

'div',
{ className: classNames, style: Object.assign(style, { backgroundImage: 'url(' + backgroundUrl + ')' }) },
{ className: classNames, style: _extends(style, { backgroundImage: 'url(' + backgroundUrl + ')' }) },
_react2.default.createElement(

@@ -55,0 +57,0 @@ 'div',

@@ -63,3 +63,2 @@ 'use strict';

var classNames = (0, _classnames2.default)('sb-soundplayer-play-btn', className);

@@ -66,0 +65,0 @@

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -58,9 +60,10 @@

var _props2 = this.props;
var value = _props2.value;
var className = _props2.className;
var innerClassName = _props2.innerClassName;
var style = _props2.style;
var innerStyle = _props2.innerStyle;
var currentTime = _props2.currentTime;
var duration = _props2.duration;
var _props3 = this.props;
var value = _props3.value;
var innerStyle = _props3.innerStyle;

@@ -87,3 +90,3 @@

innerStyle = Object.assign(innerStyle, { width: value + '%' });
innerStyle = _extends(innerStyle, { width: value + '%' });

@@ -90,0 +93,0 @@ return _react2.default.createElement(

@@ -38,3 +38,2 @@ 'use strict';

var _props = this.props;
var duration = _props.duration;
var currentTime = _props.currentTime;

@@ -44,6 +43,7 @@ var className = _props.className;

var soundCloudAudio = _props.soundCloudAudio;
var duration = this.props.duration;
var classNames = (0, _classnames2.default)('sb-soundplayer-timer', className);
if (!duration && soundCloudAudio.duration) {
if (!duration && soundCloudAudio && soundCloudAudio.duration) {
duration = soundCloudAudio.duration;

@@ -50,0 +50,0 @@ }

{
"name": "react-soundplayer",
"version": "1.0.0-rc1",
"version": "1.0.0-rc2",
"description": "Create custom SoundCloud players with React",

@@ -33,2 +33,3 @@ "main": "index.js",

"classnames": "^2.1.2",
"hoist-non-react-statics": "^1.2.0",
"object-assign": "^4.0.1",

@@ -41,2 +42,3 @@ "react": "^15.3.0",

"babel-eslint": "^6.1.2",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.13.1",

@@ -43,0 +45,0 @@ "babel-preset-react": "^6.11.1",

Sorry, the diff of this file is not supported yet