Skip to content

Commit 7a04133

Browse files
chore(debug): log TSR resync timestamps
1 parent d49fab9 commit 7a04133

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • shared/packages/tsr-bridge/src

shared/packages/tsr-bridge/src/TSR.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@ export class TSR {
151151

152152
const device = await devicePr
153153

154+
if (newDeviceOptions.type === DeviceType.CASPARCG) {
155+
const originalPrepare = device.device.prepareForHandleState?.bind(device.device)
156+
if (originalPrepare) {
157+
device.device.prepareForHandleState = async (newStateTime: number, ...args: any[]) => {
158+
const now = this.getCurrentTime()
159+
this.log.info('TSR resync prepare', {
160+
deviceId,
161+
newStateTime,
162+
now,
163+
diff: newStateTime - now,
164+
})
165+
return originalPrepare(newStateTime, ...args)
166+
}
167+
}
168+
169+
const originalHandle = device.device.handleState?.bind(device.device)
170+
if (originalHandle) {
171+
device.device.handleState = async (newState: any, newMappings: any) => {
172+
const now = this.getCurrentTime()
173+
const stateTime = newState?.time
174+
this.log.info('TSR resync handleState', {
175+
deviceId,
176+
stateTime,
177+
now,
178+
diff: typeof stateTime === 'number' ? stateTime - now : null,
179+
})
180+
return originalHandle(newState, newMappings)
181+
}
182+
}
183+
}
184+
154185
await device.device.on('connectionChanged', (...args) => {
155186
// TODO: figure out why the arguments to this event callback lost the correct typings
156187
const status = args[0] as DeviceStatus

0 commit comments

Comments
 (0)