Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const ComponentTimelineSimulate = withTracker((props: ITimelineSimulateProps) => {
let now = getCurrentTimeReactive()
try {
// These properties will be exposed under this.props
// Note that these properties are reactively recalculated
let timeline = transformTimeline(
Timeline.find({
studioId: props.studioId
}, { sort: { _id: 1 } }).fetch()
)
// console.log('rerun')
// TODO - dont repeat unless changed
let tl = Resolver.resolveTimeline(timeline, { time: now })
let allStates = Resolver.resolveAllStates(tl)
let state = Resolver.getState(allStates, now)
return {
now: now,
state: state
}
} catch (e) {
return {
now: now,
errorMsg: `Failed to update timeline:\n${e}`
}
}
})(
class extends MeteorReactComponent {
if (obj.enable.start === 0) {
if (piece.infiniteId && piece.infiniteId !== piece._id) {
// Infinite coninuation, needs to start earlier otherwise it will likely end up being unresolved
obj.enable.start = 0
} else {
obj.enable.start = 100 // TODO: write a motivation for this. perhaps to try and avoid unresolved pieces, due to them never having length?
}
} else if (obj.enable.start === 'now') {
obj.enable.start = (partStarted ? now - partStarted : 0) + 100
// I think this is + 100 as 'now' will at the earliest happen in 100ms from now, so we are trying to compensate?
}
return obj
})
const tlResolved = Resolver.resolveTimeline(transformTimeline(objs), {
time: 0
})
let resolvedPieces: Array = []
let unresolvedIds: string[] = []
let unresolvedCount = tlResolved.statistics.unresolvedCount
_.each(tlResolved.objects, obj0 => {
const obj = obj0 as any as TimelineObjRundown
const pieceId = (obj.metadata || {}).pieceId
const piece = _.clone(itemMap[pieceId]) as PieceResolved
if (obj0.resolved.resolved && obj0.resolved.instances && obj0.resolved.instances.length > 0) {
piece.resolvedStart = obj0.resolved.instances[0].start || 0
piece.resolved = true
resolvedPieces.push(piece)
} else {
piece.resolvedStart = 0
const partStartTime = part.startedPlayback ? part.getLastStartedPlayback() || 0 : 0
const targetTime = part.startedPlayback ? now - partStartTime : 0
const objs: Array = pieces.map(piece => {
const obj = createPieceGroup(piece)
// If start is now, then if the part is active set it to be now, or fallback to start of the part
if (piece.enable.start === 'now') {
piece.enable.start = targetTime
}
return obj
})
const resolved = Resolver.resolveTimeline(transformTimeline(objs), {
time: targetTime
})
const state = Resolver.getState(resolved, targetTime, 1)
let unresolvedIds: string[] = []
let unresolvedCount = resolved.statistics.unresolvedCount
_.each(resolved.objects, obj0 => {
if (!obj0.resolved.resolved || !obj0.resolved.instances || obj0.resolved.instances.length === 0) {
const obj = obj0 as any as TimelineObjRundown
const pieceId = (obj.metadata || {}).pieceId
const piece = itemMap[pieceId]
if (piece && piece.virtual) {
// Virtuals always are unresolved and should be ignored
unresolvedCount -= 1
} else {
const part = rundownData.partsMap[rundownData.rundown.currentPartId]
if (part && part.autoNext) {
pieces.push(...rundownData.pieces.filter(p => p.partId === rundownData.rundown.nextPartId))
}
}
const itemMap: { [key: string]: Piece } = {}
pieces.forEach(piece => itemMap[piece._id] = piece)
objs.forEach(o => {
if (o.enable.start === 'now') {
o.enable.start = now
}
})
const tlResolved = Resolver.resolveTimeline(transformTimeline(objs), {
time: now
})
const events: Array<{
start: number
end: number | undefined
id: string
piece: Piece
}> = []
let unresolvedIds: string[] = []
_.each(tlResolved.objects, (obj0) => {
const obj = obj0 as any as TimelineObjRundown
const id = (obj.metadata || {}).pieceId
// Probably the part
if (!id) return
// TODO - was this mangled for endState and could it have broken something else?
const pieces = part.getAllPieces()
const itemMap: { [key: string]: Piece } = {}
pieces.forEach(piece => itemMap[piece._id] = piece)
const objs = pieces.map(piece => clone(createPieceGroup(piece)))
objs.forEach(o => {
if (o.enable.start === 'now' && part.getLastStartedPlayback()) {
// Emulate playout starting now. TODO - ensure didnt break other uses
o.enable.start = getCurrentTime() - (part.getLastStartedPlayback() || 0)
} else if (o.enable.start === 0 || o.enable.start === 'now') {
o.enable.start = 1
}
})
const tlResolved = Resolver.resolveTimeline(transformTimeline(objs), {
time: 0
})
const events: Array<{
start: number
end: number | undefined
id: string
piece: Piece
}> = []
let unresolvedIds: string[] = []
_.each(tlResolved.objects, (obj0) => {
const obj = obj0 as any as TimelineObjRundown
const id = (obj.metadata || {}).pieceId
if (obj0.resolved.resolved && obj0.resolved.instances && obj0.resolved.instances.length > 0) {
const firstInstance = obj0.resolved.instances[0] || {}