UNPKG

@aller/blink

Version:

A library for tracking user behaviour.

47 lines (42 loc) 1.3 kB
import { VideoTimeEvent } from '../utils/video-event-time'; import { VIDEO_PLAY, VIDEO_STOP, PAGE_INIT } from '../actions'; export interface VideoState { events: VideoTimeEvent[]; } function videoEvents(state: VideoTimeEvent[] = [], action: any) { switch (action.type) { case PAGE_INIT: return []; case VIDEO_PLAY: return state.concat({ reason: action.payload.reason, muted: action.payload.muted, position: action.payload.position, volume: action.payload.volume, time: action.payload.time || new Date(), videoId: action.payload.videoId, playerId: action.payload.playerId, type: 'start', }); case VIDEO_STOP: return state.concat({ reason: action.payload.reason, muted: action.payload.muted, position: action.payload.position, volume: action.payload.volume, time: action.payload.time || new Date(), videoId: action.payload.videoId, playerId: action.payload.playerId, type: 'stop', }); default: return state; } } export default function video(state: VideoState = { events: [] }, action: any) { const ev = state ? state.events || [] : []; return { ...state, events: videoEvents(ev, action), }; }