Skip to content

Instantly share code, notes, and snippets.

@danbovey
Last active April 16, 2017 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbovey/cef602e21d2f1aa50c701293d80e13da to your computer and use it in GitHub Desktop.
Save danbovey/cef602e21d2f1aa50c701293d80e13da to your computer and use it in GitHub Desktop.
// import action types here
const emitActions = [
PLAYQUEUE_ADD,
PLAYQUEUE_REMOVE,
PLAYQUEUE_MOVE,
PLAYQUEUE_REPLACEDECK,
PLAYQUEUE_REPLACE,
PLAYQUEUE_CLEAR
];
const emitAndPreventActions = [
PLAYER_TOGGLEPLAY,
PLAYER_VOLUME,
PLAYER_SEEK
];
const createEmitActionsMiddleware = ({ getState }) => next => action => {
const allActions = emitActions.concat(emitAndPreventActions);
if (action.type && allActions.indexOf(action.type) > -1) {
if (window.io) {
window.io.emit('state', { action });
}
// The action should be prevented on this device if we are a slave!
const master = getState().device.master;
if (master == false && emitAndPreventActions.indexOf(action.type) > -1) {
return null;
}
}
return next(action);
};
export default createEmitActionsMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment