close #161 support "addEvent" in any state
This commit is contained in:
@@ -102,6 +102,10 @@ export function createPlayerService(
|
|||||||
target: 'paused',
|
target: 'paused',
|
||||||
actions: ['resetLastPlayedEvent', 'pause'],
|
actions: ['resetLastPlayedEvent', 'pause'],
|
||||||
},
|
},
|
||||||
|
ADD_EVENT: {
|
||||||
|
target: 'playing',
|
||||||
|
actions: ['addEvent'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
paused: {
|
paused: {
|
||||||
@@ -118,6 +122,10 @@ export function createPlayerService(
|
|||||||
target: 'live',
|
target: 'live',
|
||||||
actions: ['startLive'],
|
actions: ['startLive'],
|
||||||
},
|
},
|
||||||
|
ADD_EVENT: {
|
||||||
|
target: 'paused',
|
||||||
|
actions: ['addEvent'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
live: {
|
live: {
|
||||||
@@ -232,6 +240,9 @@ export function createPlayerService(
|
|||||||
},
|
},
|
||||||
delay: event.delay!,
|
delay: event.delay!,
|
||||||
});
|
});
|
||||||
|
if (!timer.isActive()) {
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { ...ctx, events };
|
return { ...ctx, events };
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class Timer {
|
|||||||
public speed: number;
|
public speed: number;
|
||||||
|
|
||||||
private actions: actionWithDelay[];
|
private actions: actionWithDelay[];
|
||||||
private raf: number;
|
private raf: number | null = null;
|
||||||
private liveMode: boolean;
|
private liveMode: boolean;
|
||||||
|
|
||||||
constructor(actions: actionWithDelay[] = [], speed: number) {
|
constructor(actions: actionWithDelay[] = [], speed: number) {
|
||||||
@@ -61,6 +61,7 @@ export class Timer {
|
|||||||
public clear() {
|
public clear() {
|
||||||
if (this.raf) {
|
if (this.raf) {
|
||||||
cancelAnimationFrame(this.raf);
|
cancelAnimationFrame(this.raf);
|
||||||
|
this.raf = null;
|
||||||
}
|
}
|
||||||
this.actions.length = 0;
|
this.actions.length = 0;
|
||||||
}
|
}
|
||||||
@@ -73,6 +74,10 @@ export class Timer {
|
|||||||
this.liveMode = mode;
|
this.liveMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isActive() {
|
||||||
|
return this.raf !== null;
|
||||||
|
}
|
||||||
|
|
||||||
private findActionIndex(action: actionWithDelay): number {
|
private findActionIndex(action: actionWithDelay): number {
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let end = this.actions.length - 1;
|
let end = this.actions.length - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user