Sha256: 15b42598e7db352e05c8465da936b0a5661f7c40b2269c097d0c5ec862fcf646

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

#= require trix/watchdog/recording

class Trix.Watchdog.Player
  constructor: (@recording) ->
    @playing = false
    @index = -1
    @length = @recording.getFrameCount()

  play: ->
    return if @playing
    @index = -1 if @hasEnded()
    @playing = true
    @delegate?.playerDidStartPlaying?()
    @tick()

  tick: =>
    if @hasEnded()
      @stop()
    else
      @seek(@index + 1)
      duration = @getTimeToNextFrame()
      @timeout = setTimeout(@tick, duration)

  seek: (index) ->
    previousIndex = @index

    if index < 0
      @index = 0
    else if index >= @length
      @index = @length - 1
    else
      @index = index

    if @index isnt previousIndex
      @delegate?.playerDidSeekToIndex?(index)

  stop: ->
    return unless @playing
    clearTimeout(@timeout)
    @timeout = null
    @playing = false
    @delegate?.playerDidStopPlaying?()

  isPlaying: ->
    @playing

  hasEnded: ->
    @index >= @length - 1

  getSnapshot: ->
    @recording.getSnapshotAtFrameIndex(@index)

  getEvents: ->
    @recording.getEventsUpToFrameIndex(@index)

  getTimeToNextFrame: ->
    current = @recording.getTimestampAtFrameIndex(@index)
    next = @recording.getTimestampAtFrameIndex(@index + 1)
    duration = if current? and next? then next - current else 0
    Math.min(duration, 500)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee