Add ACTIVE_TOGGLE
This commit is contained in:
parent
54c7cdad00
commit
cad9b70d50
@ -82,7 +82,7 @@ describe('App', () => {
|
|||||||
const video = node.querySelector('video')
|
const video = node.querySelector('video')
|
||||||
TestUtils.Simulate.click(video)
|
TestUtils.Simulate.click(video)
|
||||||
expect(store.getActions()).toEqual([{
|
expect(store.getActions()).toEqual([{
|
||||||
type: constants.ACTIVE_SET,
|
type: constants.ACTIVE_TOGGLE,
|
||||||
payload: { userId: 'test' }
|
payload: { userId: 'test' }
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|||||||
@ -9,10 +9,9 @@ import { play, iceServers } from '../window.js'
|
|||||||
const debug = _debug('peercalls')
|
const debug = _debug('peercalls')
|
||||||
|
|
||||||
class PeerHandler {
|
class PeerHandler {
|
||||||
constructor ({ socket, user, stream, dispatch, getState }) {
|
constructor ({ socket, user, dispatch, getState }) {
|
||||||
this.socket = socket
|
this.socket = socket
|
||||||
this.user = user
|
this.user = user
|
||||||
this.stream = stream
|
|
||||||
this.dispatch = dispatch
|
this.dispatch = dispatch
|
||||||
this.getState = getState
|
this.getState = getState
|
||||||
}
|
}
|
||||||
@ -91,7 +90,6 @@ export function createPeer ({ socket, user, initiator, stream }) {
|
|||||||
const handler = new PeerHandler({
|
const handler = new PeerHandler({
|
||||||
socket,
|
socket,
|
||||||
user,
|
user,
|
||||||
stream,
|
|
||||||
dispatch,
|
dispatch,
|
||||||
getState
|
getState
|
||||||
})
|
})
|
||||||
|
|||||||
@ -17,3 +17,8 @@ export const setActive = userId => ({
|
|||||||
type: constants.ACTIVE_SET,
|
type: constants.ACTIVE_SET,
|
||||||
payload: { userId }
|
payload: { userId }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const toggleActive = userId => ({
|
||||||
|
type: constants.ACTIVE_TOGGLE,
|
||||||
|
payload: { userId }
|
||||||
|
})
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export default class App extends React.Component {
|
|||||||
dismissAlert: PropTypes.func.isRequired,
|
dismissAlert: PropTypes.func.isRequired,
|
||||||
streams: PropTypes.objectOf(PropTypes.string).isRequired,
|
streams: PropTypes.objectOf(PropTypes.string).isRequired,
|
||||||
alerts: PropTypes.arrayOf(AlertPropType).isRequired,
|
alerts: PropTypes.arrayOf(AlertPropType).isRequired,
|
||||||
setActive: PropTypes.func.isRequired,
|
toggleActive: PropTypes.func.isRequired,
|
||||||
active: PropTypes.string,
|
active: PropTypes.string,
|
||||||
init: PropTypes.func.isRequired,
|
init: PropTypes.func.isRequired,
|
||||||
notify: PropTypes.func.isRequired,
|
notify: PropTypes.func.isRequired,
|
||||||
@ -30,7 +30,7 @@ export default class App extends React.Component {
|
|||||||
notifications,
|
notifications,
|
||||||
notify,
|
notify,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
setActive,
|
toggleActive,
|
||||||
streams
|
streams
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
@ -41,11 +41,11 @@ export default class App extends React.Component {
|
|||||||
<div className="videos">
|
<div className="videos">
|
||||||
{_.map(streams, (stream, userId) => (
|
{_.map(streams, (stream, userId) => (
|
||||||
<Video
|
<Video
|
||||||
setActive={setActive}
|
|
||||||
active={userId === active}
|
active={userId === active}
|
||||||
key={userId}
|
key={userId}
|
||||||
userId={userId}
|
onClick={toggleActive}
|
||||||
stream={stream}
|
stream={stream}
|
||||||
|
userId={userId}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,15 +5,15 @@ import { ME } from '../constants.js'
|
|||||||
|
|
||||||
export default class Video extends React.Component {
|
export default class Video extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
setActive: PropTypes.func.isRequired,
|
onClick: PropTypes.func,
|
||||||
active: PropTypes.bool.isRequired,
|
active: PropTypes.bool.isRequired,
|
||||||
stream: PropTypes.string.isRequired,
|
stream: PropTypes.string.isRequired,
|
||||||
userId: PropTypes.string.isRequired
|
userId: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
setActive = e => {
|
handleClick = e => {
|
||||||
const { setActive, userId } = this.props
|
const { onClick, userId } = this.props
|
||||||
this.play(e)
|
this.play(e)
|
||||||
setActive(userId)
|
onClick(userId)
|
||||||
}
|
}
|
||||||
play = e => {
|
play = e => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -26,7 +26,7 @@ export default class Video extends React.Component {
|
|||||||
<div className={className}>
|
<div className={className}>
|
||||||
<video
|
<video
|
||||||
muted={userId === ME}
|
muted={userId === ME}
|
||||||
onClick={this.setActive}
|
onClick={this.handleClick}
|
||||||
onLoadedMetadata={this.play}
|
onLoadedMetadata={this.play}
|
||||||
src={stream}
|
src={stream}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
export const ACTIVE_SET = 'ACTIVE_SET'
|
export const ACTIVE_SET = 'ACTIVE_SET'
|
||||||
|
export const ACTIVE_TOGGLE = 'ACTIVE_TOGGLE'
|
||||||
|
|
||||||
export const ALERT = 'ALERT'
|
export const ALERT = 'ALERT'
|
||||||
export const ALERT_DISMISS = 'ALERT_DISMISS'
|
export const ALERT_DISMISS = 'ALERT_DISMISS'
|
||||||
|
|||||||
@ -11,13 +11,13 @@ function mapStateToProps (state) {
|
|||||||
streams: state.streams,
|
streams: state.streams,
|
||||||
alerts: state.alerts,
|
alerts: state.alerts,
|
||||||
notifications: state.notifications,
|
notifications: state.notifications,
|
||||||
active: state.streams.active
|
active: state.active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps (dispatch) {
|
function mapDispatchToProps (dispatch) {
|
||||||
return {
|
return {
|
||||||
setActive: bindActionCreators(StreamActions.setActive, dispatch),
|
toggleActive: bindActionCreators(StreamActions.toggleActive, dispatch),
|
||||||
sendMessage: bindActionCreators(PeerActions.sendMessage, dispatch),
|
sendMessage: bindActionCreators(PeerActions.sendMessage, dispatch),
|
||||||
dismissAlert: bindActionCreators(NotifyActions.dismissAlert, dispatch),
|
dismissAlert: bindActionCreators(NotifyActions.dismissAlert, dispatch),
|
||||||
init: bindActionCreators(CallActions.init, dispatch),
|
init: bindActionCreators(CallActions.init, dispatch),
|
||||||
|
|||||||
@ -1,16 +1,28 @@
|
|||||||
import * as constants from '../../constants.js'
|
import * as StreamActions from '../../actions/StreamActions.js'
|
||||||
import active from '../active.js'
|
import active from '../active.js'
|
||||||
|
|
||||||
describe('reducers/active', () => {
|
describe('reducers/active', () => {
|
||||||
|
|
||||||
it('sets active to userId', () => {
|
describe('setActive', () => {
|
||||||
const userId = 'test'
|
it('sets active to userId', () => {
|
||||||
let state = active()
|
const userId = 'test'
|
||||||
state = active(state, {
|
let state = active()
|
||||||
type: constants.ACTIVE_SET,
|
state = active(state, StreamActions.setActive(userId))
|
||||||
payload: { userId }
|
expect(state).toBe(userId)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('toggleActive', () => {
|
||||||
|
it('sets active to userId', () => {
|
||||||
|
const userId = 'test'
|
||||||
|
let state = active()
|
||||||
|
state = active(state, StreamActions.toggleActive(userId))
|
||||||
|
expect(state).toBe(userId)
|
||||||
|
state = active(state, StreamActions.toggleActive(userId))
|
||||||
|
expect(state).toBe(null)
|
||||||
|
state = active(state, StreamActions.toggleActive(userId))
|
||||||
|
expect(state).toBe(userId)
|
||||||
})
|
})
|
||||||
expect(state).toBe(userId)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,7 +3,10 @@ import * as constants from '../constants.js'
|
|||||||
export default function active (state = null, action) {
|
export default function active (state = null, action) {
|
||||||
switch (action && action.type) {
|
switch (action && action.type) {
|
||||||
case constants.ACTIVE_SET:
|
case constants.ACTIVE_SET:
|
||||||
|
case constants.STREAM_ADD:
|
||||||
return action.payload.userId
|
return action.payload.userId
|
||||||
|
case constants.ACTIVE_TOGGLE:
|
||||||
|
return state === action.payload.userId ? null : action.payload.userId
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user