diff --git a/src/actions/history.js b/src/actions/history.js index 6a7bc0c4..a44a7758 100644 --- a/src/actions/history.js +++ b/src/actions/history.js @@ -17,15 +17,15 @@ export const onHistoryMiddleware = ({ dispatch, getState }) => (next) => (action dispatch(selectDevice(pathDongleId, false)); } - // TODO: this should redirect to a log id const pathZoom = getZoom(action.payload.location.pathname); if (pathZoom !== state.zoom) { + console.debug("TODO: this should redirect to a log id") //dispatch(pushTimelineRange(pathZoom?.start, pathZoom?.end, false)); } const pathSegmentRange = getSegmentRange(action.payload.location.pathname); - if (pathSegmentRange != state.segmentRange) { - dispatch(pushTimelineRange(pathSegmentRange?.log_id, pathSegmentRange?.start, pathSegmentRange?.end, true)); + if (pathSegmentRange !== state.segmentRange) { + dispatch(pushTimelineRange(pathSegmentRange?.log_id, pathSegmentRange?.start, pathSegmentRange?.end, false)); } const pathPrimeNav = getPrimeNav(action.payload.location.pathname); diff --git a/src/actions/history.test.js b/src/actions/history.test.js index 47ccc719..b802f11f 100644 --- a/src/actions/history.test.js +++ b/src/actions/history.test.js @@ -77,7 +77,6 @@ describe('history middleware', () => { }; invoke(action); expect(next).toHaveBeenCalledWith(action); - expect(store.dispatch).toHaveBeenCalledTimes(1); expect(store.dispatch).toHaveBeenCalledWith(fakeInner); expect(actionsIndex.selectDevice).toHaveBeenCalledWith('0000aaaa0000aaaa', false); }); @@ -96,14 +95,14 @@ describe('history middleware', () => { type: LOCATION_CHANGE, payload: { action: 'POP', - location: { pathname: '0000aaaa0000aaaa/1230/1234' }, + location: { pathname: '0000aaaa0000aaaa/00000014--55a0b1280e/1230/1234' }, }, }; invoke(action); expect(next).toHaveBeenCalledWith(action); expect(store.dispatch).toHaveBeenCalledTimes(1); expect(store.dispatch).toHaveBeenCalledWith(fakeInner); - expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(1230, 1234, false); + expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith('00000014--55a0b1280e', 1230, 1234, false); }); it('should call prime nav with history', async () => { @@ -130,7 +129,7 @@ describe('history middleware', () => { expect(store.dispatch).toHaveBeenCalledTimes(2); expect(store.dispatch).toHaveBeenCalledWith(fakeInner); expect(store.dispatch).toHaveBeenCalledWith(fakeInner2); - expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(undefined, undefined, false); + expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(undefined, undefined, undefined, false); expect(actionsIndex.primeNav).toHaveBeenCalledWith(true); }); }); diff --git a/src/actions/index.js b/src/actions/index.js index 623f0735..a21bf4de 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -305,7 +305,6 @@ export function checkRoutesData() { ...r, url: r.url.replace('chffrprivate.blob.core.windows.net', 'chffrprivate.azureedge.net'), log_id: r.fullname.split('|')[1], - //offset: Math.round(startTime), duration: endTime - startTime, start_time_utc_millis: startTime, end_time_utc_millis: endTime, diff --git a/src/actions/index.test.js b/src/actions/index.test.js index 90449a0f..f4587123 100644 --- a/src/actions/index.test.js +++ b/src/actions/index.test.js @@ -15,7 +15,7 @@ describe('timeline actions', () => { it('should push history state when editing zoom', () => { const dispatch = jest.fn(); const getState = jest.fn(); - const actionThunk = pushTimelineRange(123, 1234); + const actionThunk = pushTimelineRange("log_id", 123, 1234); getState.mockImplementationOnce(() => ({ dongleId: 'statedongle', @@ -23,6 +23,6 @@ describe('timeline actions', () => { zoom: {}, })); actionThunk(dispatch, getState); - expect(push).toBeCalledWith('/statedongle/123/1234'); + expect(push).toBeCalledWith('/statedongle/log_id/123/1234'); }); }); diff --git a/src/components/TimeDisplay/index.jsx b/src/components/TimeDisplay/index.jsx index 409292de..56720138 100644 --- a/src/components/TimeDisplay/index.jsx +++ b/src/components/TimeDisplay/index.jsx @@ -136,7 +136,7 @@ class TimeDisplay extends Component { getDisplayTime() { const offset = currentOffset(); - const { filter, currentRoute } = this.props; + const { currentRoute } = this.props; const now = new Date(offset + currentRoute.start_time_utc_millis); if (Number.isNaN(now.getTime())) { return '...'; @@ -299,7 +299,6 @@ const stateToProps = Obstruction({ currentRoute: 'currentRoute', zoom: 'zoom', desiredPlaySpeed: 'desiredPlaySpeed', - filter: 'filter', }); export default connect(stateToProps)(withStyles(styles)(TimeDisplay)); diff --git a/src/initialState.js b/src/initialState.js index 3a9b7c66..18ef0d31 100644 --- a/src/initialState.js +++ b/src/initialState.js @@ -1,4 +1,4 @@ -import { getDongleID, getZoom, getPrimeNav, getSegmentRange } from './url'; +import { getDongleID, getPrimeNav, getSegmentRange } from './url'; import * as Demo from './demo'; export function getDefaultFilter() { diff --git a/src/reducers/globalState.js b/src/reducers/globalState.js index 77541f17..d86ce267 100644 --- a/src/reducers/globalState.js +++ b/src/reducers/globalState.js @@ -336,10 +336,10 @@ export default function reducer(_state, action) { }; if (!state.currentRoute && state.segmentRange) { - const r = state.routes?.find((route) => route.log_id === state.segmentRange.log_id); - if (r) { + const curr = state.routes?.find((route) => route.log_id === state.segmentRange.log_id); + if (curr) { state.currentRoute = { - ...r, + ...curr, }; if (state.segmentRange.start && state.segmentRange.end) { state.zoom = { diff --git a/src/timeline/playback.js b/src/timeline/playback.js index 12ea4b9a..3c1a4c03 100644 --- a/src/timeline/playback.js +++ b/src/timeline/playback.js @@ -74,7 +74,7 @@ export function reducer(_state, action) { break; } - if (state.currentRoute && state.currentRoute.videoStartOffset && state.loop && state.zoom && state.filter + if (state.currentRoute && state.currentRoute.videoStartOffset && state.loop && state.zoom && state.loop.startTime === state.zoom.start && state.zoom.start === 0) { const loopRouteOffset = state.loop.startTime - state.zoom.start; if (state.currentRoute.videoStartOffset > loopRouteOffset) { diff --git a/src/timeline/playback.test.js b/src/timeline/playback.test.js index 5d56cbbc..54e02546 100644 --- a/src/timeline/playback.test.js +++ b/src/timeline/playback.test.js @@ -5,11 +5,7 @@ import { bufferVideo, pause, play, reducer, seek, selectLoop } from './playback' const makeDefaultStruct = function makeDefaultStruct() { return { - filter: { - start: Date.now(), - end: Date.now() + 100000, - }, - desiredPlaySpeed: 1, // 0 = stopped, 1 = playing, 2 = 2x speed... multiplier on speed + desiredPlaySpeed: 1, // 0 = stopped, 1 = playing, 2 = 2x speed offset: 0, // in miliseconds from the start startTime: Date.now(), // millisecond timestamp in which play began @@ -81,14 +77,14 @@ describe('playback', () => { // set up loop state = reducer(state, play()); state = reducer(state, selectLoop( - state.filter.start + 1000, - state.filter.start + 2000, + 1000, + 2000, )); - expect(state.loop.startTime).toEqual(state.filter.start + 1000); + expect(state.loop.startTime).toEqual(1000); // seek past loop end boundary a state = reducer(state, seek(3000)); - expect(state.loop.startTime).toEqual(state.filter.start + 1000); + expect(state.loop.startTime).toEqual(1000); expect(state.offset).toEqual(2000); }); @@ -99,14 +95,14 @@ describe('playback', () => { // set up loop state = reducer(state, play()); state = reducer(state, selectLoop( - state.filter.start + 1000, - state.filter.start + 2000, + 1000, + 2000, )); - expect(state.loop.startTime).toEqual(state.filter.start + 1000); + expect(state.loop.startTime).toEqual(1000); // seek past loop end boundary a state = reducer(state, seek(0)); - expect(state.loop.startTime).toEqual(state.filter.start + 1000); + expect(state.loop.startTime).toEqual(1000); expect(state.offset).toEqual(1000); }); diff --git a/src/timeline/segments.js b/src/timeline/segments.js index 54784f5d..413f3e52 100644 --- a/src/timeline/segments.js +++ b/src/timeline/segments.js @@ -1,5 +1,3 @@ -import * as Types from '../actions/types'; - export function getSegmentFetchRange(state) { // TODO: fix this for relative routes return state.filter; diff --git a/src/timeline/segments.test.js b/src/timeline/segments.test.js index 34f98410..592c5c67 100644 --- a/src/timeline/segments.test.js +++ b/src/timeline/segments.test.js @@ -1,78 +1,9 @@ /* eslint-env jest */ -import { getCurrentRoute } from '.'; import { hasRoutesData } from './segments'; -import { getSegmentNumber } from '../utils'; export const SEGMENT_LENGTH = 1000 * 60; -const routes = [{ - fullname: '99c94dc769b5d96e|2018-04-09--10-10-00', - offset: 36600000, - duration: 2558000, - segment_numbers: Array.from(Array(43).keys()), - segment_offsets: Array.from(Array(43).keys()).map((i) => i * SEGMENT_LENGTH + 36600000), - events: [{ - time: 36600123, - type: 'event', - }], -}, { - fullname: '99c94dc769b5d96e|2018-04-09--11-29-08', - offset: 41348000, - duration: 214000, - segment_numbers: Array.from(Array(4).keys()), - segment_offsets: Array.from(Array(4).keys()).map((i) => i * SEGMENT_LENGTH + 41348000), - events: [{ - time: 41348123, - type: 'event', - }], -}]; - describe('segments', () => { - it('finds current segment', async () => { - const [route] = routes; - let r = getCurrentRoute({ - routes, - offset: route.offset, - desiredPlaySpeed: 1, - startTime: Date.now(), - }); - expect(r.fullname).toBe(route.fullname); - expect(getSegmentNumber(r, route.offset)).toBe(0); - - r = getCurrentRoute({ - routes, - offset: route.offset + SEGMENT_LENGTH * 1.1, - desiredPlaySpeed: 1, - startTime: Date.now(), - }); - expect(getSegmentNumber(r, route.offset + SEGMENT_LENGTH * 1.1)).toBe(1); - }); - - it('finds last segment of a route', async () => { - const [route] = routes; - const offset = route.offset + SEGMENT_LENGTH * (route.segment_offsets.length - 1) + 1000; - const r = getCurrentRoute({ - routes, - offset, - desiredPlaySpeed: 1, - startTime: Date.now(), - }); - expect(r.fullname).toBe(route.fullname); - expect(getSegmentNumber(r, offset)).toBe(route.segment_offsets.length - 1); - }); - - it('ends last segment of a route', async () => { - const [route] = routes; - const offset = route.offset + route.duration - 10; - const r = getCurrentRoute({ - routes, - offset, - desiredPlaySpeed: 1, - startTime: Date.now() - 50, - }); - expect(getSegmentNumber(r, offset)).toBe(null); - }); - it('can check if it has segment metadata', () => { expect(hasRoutesData()).toBe(false); expect(hasRoutesData({})).toBe(false); diff --git a/src/url.js b/src/url.js index 645833b2..7c3771a3 100644 --- a/src/url.js +++ b/src/url.js @@ -43,7 +43,7 @@ export function getPrimeNav(pathname) { let parts = pathname.split('/'); parts = parts.filter((m) => m.length); - if (parts.length === 2 && parts[0] !== 'auth' && parts[1] === 'prime') { + if (parts.length === 2 && dongleIdRegex.test(parts[0]) && parts[1] === 'prime') { return true; } return false;