Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleMediaSrcrequest(e) {
const { playlist } = this.props;
const sources = getTrackSources(playlist, this.state.activeTrackIndex);
if (arrayFindIndex(sources, s => s.src === e.srcRequested) !== -1) {
// we're good! nothing to update.
return;
}
// looks like 'src' was set from outside our component.
// let's see if we can use it.
const newTrackIndex = findTrackIndexByUrl(playlist, e.srcRequested);
if (newTrackIndex === -1) {
logError(
`Source '${e.srcRequested}' does not exist in the loaded playlist. ` +
`Make sure you've updated the 'playlist' prop to ` +
`PlayerContextProvider before you select this track!`
);
return;
}
this.selectTrackIndex(newTrackIndex);
}
export default function filterByBitrate(
representations : Representation[],
bitrate : number
) : Representation[] {
const firstSuperiorBitrate = arrayFindIndex(
representations,
(representation) => representation.bitrate > bitrate
);
if (firstSuperiorBitrate === -1) {
return representations; // All representations have a lower bitrates.
}
return representations.slice(0, firstSuperiorBitrate);
}
this.audio.crossOrigin = nextProps.crossOrigin;
const newPlaylist = nextProps.playlist;
if (!newPlaylist || !newPlaylist.length) {
if (this.audio) {
this.audio.src = '';
}
this.currentTrackIndex = 0;
return this.setState(this.defaultState);
}
const oldPlaylist = this.props.playlist;
const currentTrackUrl = ((oldPlaylist || [])[this.currentTrackIndex] || {}).url;
this.currentTrackIndex = arrayFindIndex(newPlaylist, track => {
return track.url && currentTrackUrl === track.url;
});
/* if the track we're already playing is in the new playlist, update the
* activeTrackIndex.
*/
if (this.currentTrackIndex !== -1) {
this.setState({
activeTrackIndex: this.currentTrackIndex
});
}
}
removeEventListener(type: string, handler: Function): void {
invariant(
eventTypes.indexOf(type) !== -1,
'Trying to unsubscribe from unknown event: "%s"',
type
);
if (type === 'change') {
console.warn('Listening to event `change` is deprecated. Use `connectionChange` instead.');
}
const listenerIndex = findIndex(netInfoListeners, pair => pair[0] === handler);
invariant(listenerIndex !== -1, 'Trying to remove NetInfo listener for unregistered handler');
const [, wrappedHandler] = netInfoListeners[listenerIndex];
connection.removeEventListener(eventTypesMap[type], wrappedHandler);
netInfoListeners.splice(listenerIndex, 1);
},
removeEventListener(type: string, handler: Function): void {
invariant(
eventTypes.indexOf(type) !== -1,
'Trying to subscribe to unknown event: "%s"',
type
);
if (type === 'change') {
console.warn('Listening to event `change` is deprecated. Use `connectionChange` instead.');
}
const listenerIndex = findIndex(connectionListeners, pair => pair[0] === handler);
invariant(
listenerIndex !== -1,
'Trying to remove NetInfo connection listener for unregistered handler'
);
const [, onlineCallback, offlineCallback] = connectionListeners[listenerIndex];
window.removeEventListener('online', onlineCallback, false);
window.removeEventListener('offline', offlineCallback, false);
connectionListeners.splice(listenerIndex, 1);
},
function mapStateToProps(state, props) {
const routeIndex = findIndex(state.router.routes, panel => panel.context === props.route.context);
const app = state.apps[props.route.app] || {
isLoading: true
};
const panel = state.panels[getPanelPathFromRoute(props.route)] || {
isLoading: true
};
const isLoading = app.isLoading || panel.isLoading;
const isReady = app.isReady && panel.isReady;
const error = app.error || panel.error;
return {
app,
error,
isLoading,
isReady,
function findTrackIndexByUrl(playlist, url) {
return arrayFindIndex(playlist, track => {
if (track.sources) {
return arrayFindIndex(track.sources, source => source.src === url) !== -1;
}
return track.url && url === track.url;
});
}
const register = () => {
let i = -1;
if (item.props.index == null) {
i = findIndex(
this._listItems,
_item =>
(item.el.compareDocumentPosition(_item.el)&Node.DOCUMENT_POSITION_PRECEDING) === 0
);
} else {
i = findIndex(
this._listItems,
_item => _item.props.index != null && item.props.index < _item.props.index
);
}
if (i < 0) {
this._listItems.push(item);
} else {
this._listItems.splice(i, 0, item);
if (this._naturalHighlightedIndex != null && i <= this._naturalHighlightedIndex) {
this._naturalHighlightedIndex++;
static removeEventListener(type: string, handler: Function) {
if (AppState.isAvailable) {
invariant(
EVENT_TYPES.indexOf(type) !== -1,
'Trying to remove listener for unknown event: "%s"',
type
);
const listenerIndex = findIndex(listeners, pair => pair[0] === handler);
invariant(
listenerIndex !== -1,
'Trying to remove AppState listener for unregistered handler'
);
const callback = listeners[listenerIndex][1];
document.removeEventListener(VISIBILITY_CHANGE_EVENT, callback, false);
listeners.splice(listenerIndex, 1);
}
}
}
[types.REMOVE_FROM_CART]: function (state, item) {
var index = arrayFindIndex(state.cart, (elm) => elm.item === item)
if (index !== -1) {
if (state.cart[index].quantity > 1) {
state.cart[index].quantity--
} else {
state.cart.splice(index, 1)
}
}
},
[types.DISCARD_CART]: function (state) {