-
Notifications
You must be signed in to change notification settings - Fork 13
/
video.js
63 lines (57 loc) · 1.48 KB
/
video.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { handleActions } from 'redux-actions'
import {
SET_MEDIA_FILE,
SET_VIDEO_MUTED,
SET_VIDEO_PAUSED,
SET_VIDEO_PROPERTIES,
SET_VIDEO_SRC,
START_TEST,
VIDEO_EVENT
} from '../actions'
import { VIDEO_EVENT_TYPES, VIDEO_PROPERTY_NAMES } from '../constants/video'
import incrementCounter from '../util/incrementCounter'
import mapObject from '../util/mapObject'
const defaultEventCounts = () => mapObject(VIDEO_EVENT_TYPES, 0)
const defaultProperties = () => mapObject(VIDEO_PROPERTY_NAMES, '')
const defaultState = () => ({
eventCounts: defaultEventCounts(),
properties: defaultProperties(),
shared: false,
src: null,
muted: false,
paused: true
})
const reducer = handleActions(
{
[START_TEST]: defaultState,
[SET_MEDIA_FILE]: (state, { payload: { apiFramework } }) => {
const isVpaid = apiFramework != null
return {
...state,
shared: isVpaid
}
},
[SET_VIDEO_PAUSED]: (state, { payload: { paused } }) => ({
...state,
paused
}),
[SET_VIDEO_SRC]: (state, { payload: { src } }) => ({
...state,
src
}),
[SET_VIDEO_MUTED]: (state, { payload: { muted } }) => ({
...state,
muted
}),
[SET_VIDEO_PROPERTIES]: (state, { payload: { properties } }) => ({
...state,
properties
}),
[VIDEO_EVENT]: (state, { payload: { type } }) => ({
...state,
eventCounts: incrementCounter(state.eventCounts, type)
})
},
defaultState()
)
export default reducer