From 43001ccbbde1378bb92a6bfa0f37c0c5daf3f780 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 10 Jul 2020 06:36:57 +0100 Subject: [PATCH] Ensure api method `.play()` can be called by external code without worrying about the internal state of the finite state machine (#236) --- src/replay/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index c62a6d4a..acc2b011 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -178,7 +178,14 @@ export class Replayer { * @param timeOffset number */ public play(timeOffset = 0) { - this.service.send({ type: 'PLAY', payload: { timeOffset } }); + if (this.service.state.value == 'ended') { + this.service.send({ type: 'REPLAY'}); + } + if (this.service.state.value == 'paused') { + this.service.send({ type: 'RESUME', payload: { timeOffset } }); + } else { + this.service.send({ type: 'PLAY', payload: { timeOffset } }); + } this.emitter.emit(ReplayerEvents.Start); }