Last active
April 16, 2017 00:09
-
-
Save danbovey/cef602e21d2f1aa50c701293d80e13da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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