Skip to content

Commit

Permalink
fix: reset atem upon connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Nov 30, 2023
1 parent 006c8e8 commit 9cbb458
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ export class AtemDevice extends Device<AtemOptions, AtemDeviceState, AtemCommand
this._connected = true

this._connectionChanged()
this.context.resetResolver()

if (this._atem.state) {
// Do a state diff to get to the desired state
this._protocolVersion = this._atem.state.info.apiVersion
this.context
.resetToState(this._atem.state)
.catch((e) => this.context.logger.error('Error resetting atem state', new Error(e)))
} else {
// Do a state diff to at least send all the commands we know about
this.context.resetState().catch((e) => this.context.logger.error('Error resetting atem state', new Error(e)))
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ export class DeviceInstanceWrapper extends EventEmitter<DeviceInstanceEvents> {
},

resetState: async () => {
await this._stateHandler.setCurrentState(undefined)
await this._stateHandler.clearFutureStates()
this.emit('resetResolver')
},

resetToState: async (state: any) => {
await this._stateHandler.setCurrentState(state)
await this._stateHandler.clearFutureStates()
this.emit('resetResolver')
},
Expand Down
11 changes: 9 additions & 2 deletions packages/timeline-state-resolver/src/service/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export interface DeviceContextAPI {

/** Notify that the connection status has changed. */
connectionChanged: (status: Omit<DeviceStatus, 'active'>) => void
/** Notify the conductor that it should reset the resolver, in order to trigger it again. */
/**
* Notify the conductor that it should reset the resolver, in order to trigger it again.
* Note: this will not change anything about the current state and should technically not lead
* to any new commands being sent
*/
resetResolver: () => void

/** Something went wrong when executing a command */
Expand All @@ -148,6 +152,9 @@ export interface DeviceContextAPI {

timeTrace: (trace: FinishedTrace) => void

/** Reset the state of the State */
/** Reset the tracked device state to undefined and notify the conductor to reset the resolver */
resetState: () => Promise<void>

/** Reset the tracked device state to "state" and notify the conductor to reset the resolver */
resetToState: (state: any) => Promise<void> // todo - types?
}

0 comments on commit 9cbb458

Please sign in to comment.