Skip to content

fix: suppress quantel disconnect shortly #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface QuantelOptions {
* If set: If a clip turns out to be on the wrong server, an attempt to copy the clip will be done
*/
allowCloneClips?: boolean
/**
* If the ISA goes down the gateway will temporarily emit a disconnection warning, this is a false flag when a backup ISA is available. This option will suppress the disconnection warning for a number of ms to give the system time to switch without warnings.
*/
suppressDisconnectTime?: number
}

export interface MappingQuantelPort {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"ui:title": "Allow cloning of clips if on wrong server/pool",
"description": "If set: If a clip turns out to be on the wrong server, an attempt to copy the clip will be done",
"default": false
},
"suppressDisconnectTime": {
"type": "integer",
"ui:title": "Time to suppress disconnection warnings for",
"description": "If the ISA goes down the gateway will temporarily emit a disconnection warning, this is a false flag when a backup ISA is available. This option will suppress the disconnection warning for a number of ms to give the system time to switch without warnings."
}
},
"required": ["gatewayUrl", "ISAUrlMaster", "serverId"],
Expand Down
25 changes: 22 additions & 3 deletions packages/timeline-state-resolver/src/integrations/quantel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export interface QuantelCommandWithContext {
export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelCommandWithContext> {
private _quantel: QuantelGateway
private _quantelManager: QuantelManager
private options: QuantelOptions

private _disconnectedSince: number | undefined = undefined

async init(options: QuantelOptions): Promise<boolean> {
this.options = options
this._quantel = new QuantelGateway()
this._quantel.on('error', (e) => this.context.logger.error('Quantel.QuantelGateway', e))
this._quantelManager = new QuantelManager(this._quantel, () => this.context.getCurrentTime(), {
Expand All @@ -66,7 +70,20 @@ export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelC
this._quantel
.init(options.gatewayUrl, isaURLs, options.zoneId, options.serverId)
.then(() => {
this._quantel.monitorServerStatus((_connected: boolean) => {
this._quantel.monitorServerStatus((connected: boolean) => {
if (!this._disconnectedSince && connected === false && options.suppressDisconnectTime) {
this._disconnectedSince = Date.now()

// trigger another update after debounce
setTimeout(() => {
if (!this._quantel.connected) {
this.context.connectionChanged(this.getStatus())
}
}, options.suppressDisconnectTime)
} else if (connected === true) {
this._disconnectedSince = undefined
}

this.context.connectionChanged(this.getStatus())
})
})
Expand Down Expand Up @@ -136,12 +153,14 @@ export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelC
getStatus(): Omit<DeviceStatus, 'active'> {
let statusCode = StatusCode.GOOD
const messages: Array<string> = []
const suppressServerDownWarning =
Date.now() < (this._disconnectedSince ?? 0) + (this.options?.suppressDisconnectTime ?? 0)

if (!this._quantel.connected) {
if (!this._quantel.connected && !suppressServerDownWarning) {
statusCode = StatusCode.BAD
messages.push('Not connected')
}
if (this._quantel.statusMessage) {
if (this._quantel.statusMessage && !suppressServerDownWarning) {
statusCode = StatusCode.BAD
messages.push(this._quantel.statusMessage)
}
Expand Down