Skip to content

Commit

Permalink
Merge branch 'fix/restore-timelines-on-startup'
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jan 24, 2024
2 parents f27cbd4 + f0f81c1 commit 58d829b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
18 changes: 18 additions & 0 deletions apps/app/src/electron/SuperConductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { ActiveAnalog } from '../models/rundown/Analog'
import { AnalogHandler } from './analogHandler'
import { AnalogInput } from '../models/project/AnalogInput'
import { SystemMessageOptions } from '../ipc/IPCAPI'
import { getTimelineForGroup } from '../lib/timeline'
import { TSRTimeline } from 'timeline-state-resolver-types'

export class SuperConductor {
ipcServer: IPCServer
Expand Down Expand Up @@ -256,6 +258,8 @@ export class SuperConductor {
} else {
this.httpAPI = new HTTPAPI(this.internalHttpApiPort, this.ipcServer, this.log)
}

this._restoreTimelines()
}
sendSystemMessage(message: string, options: SystemMessageOptions): void {
this.clients.forEach((clients) => clients.ipcClient.systemMessage(message, options))
Expand Down Expand Up @@ -509,6 +513,20 @@ export class SuperConductor {

return updateTimeline(this.storage, this.bridgeHandler, group)
}
private _restoreTimelines() {
const project = this.storage.getProject()

const openRundowns = this.storage.getAllRundowns()

for (const openRundown of openRundowns) {
for (const group of openRundown.groups) {
const timeline = getTimelineForGroup(group, group.preparedPlayData, undefined) as TSRTimeline
this.bridgeHandler.updateTimeline(group.id, timeline)
}
}

this.bridgeHandler.updateMappings(project.mappings)
}

/**
* Is called when the app is starting to shut down.
Expand Down
38 changes: 28 additions & 10 deletions apps/app/src/electron/bridgeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export const SERVER_PORT = 5400

type AnyBridgeConnection = WebsocketBridgeConnection | LocalBridgeConnection

interface BridgeHandlerCallbacks {
updatedResources: (deviceId: string, resources: ResourceAny[]) => void
onVersionMismatch: (bridgeId: string, bridgeVersion: string, ourVersion: string) => void
onDeviceRefreshStatus: (deviceId: string, refreshing: boolean) => void
}

/** This handles connected bridges */
export class BridgeHandler {
server: WebsocketServer
Expand Down Expand Up @@ -55,7 +61,7 @@ export class BridgeHandler {
private log: LoggerLike,
private session: SessionHandler,
private storage: StorageHandler,
private callbacks: BridgeConnectionCallbacks
private callbacks: BridgeHandlerCallbacks
) {
this.server = new WebsocketServer(this.log, SERVER_PORT, (connection: WebsocketConnection) => {
// On connection:
Expand All @@ -65,7 +71,7 @@ export class BridgeHandler {
this.session,
this.storage,
connection,
this.callbacks
this.getBridgeConnectionCallbacks()
)

// Lookup and set the bridgeId, if it is an outgoing
Expand Down Expand Up @@ -106,7 +112,12 @@ export class BridgeHandler {
if (this.closed) return
if (project.settings.enableInternalBridge) {
if (!this.internalBridge) {
this.internalBridge = new LocalBridgeConnection(this.log, this.session, this.storage, this.callbacks)
this.internalBridge = new LocalBridgeConnection(
this.log,
this.session,
this.storage,
this.getBridgeConnectionCallbacks()
)
this.connectedBridges.push(this.internalBridge)
}
} else {
Expand Down Expand Up @@ -292,12 +303,18 @@ export class BridgeHandler {
bridgeConnection.refreshResources()
}
}
private getBridgeConnectionCallbacks(): BridgeConnectionCallbacks {
return {
...this.callbacks,
getTimelines: () => this.timelines,
getMappings: () => this.mappings,
}
}
}

interface BridgeConnectionCallbacks {
updatedResources: (deviceId: string, resources: ResourceAny[]) => void
onVersionMismatch: (bridgeId: string, bridgeVersion: string, ourVersion: string) => void
onDeviceRefreshStatus: (deviceId: string, refreshing: boolean) => void
interface BridgeConnectionCallbacks extends BridgeHandlerCallbacks {
getTimelines: () => { [timelineId: string]: TSRTimeline }
getMappings: () => Mappings
}

abstract class AbstractBridgeConnection {
Expand Down Expand Up @@ -399,10 +416,11 @@ abstract class AbstractBridgeConnection {
} else {
this.log.error(`Error: Settings bridge "${this.bridgeId}" not found`)
}
if (this.sentMappings) {
this.setMappings(this.sentMappings, true)
const mappings = this.callbacks.getMappings()
if (mappings) {
this.setMappings(mappings, true)
}
for (const [timelineId, timeline] of Object.entries(this.sentTimelines)) {
for (const [timelineId, timeline] of Object.entries<TSRTimeline>(this.callbacks.getTimelines())) {
this.addTimeline(timelineId, timeline)
}
// Sync timelineIds:
Expand Down

0 comments on commit 58d829b

Please sign in to comment.