Skip to content
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

Feat/openmedia hotstandby heartbeat logic #105

Merged
merged 12 commits into from
Dec 5, 2024
Next Next commit
feat: Support for openMediaHotStandby disable heartbeat on secondary …
…when not used
  • Loading branch information
olzzon committed Oct 7, 2024
commit ab04e4900f1a73324a0ff7de6363421ad579bf26
15 changes: 14 additions & 1 deletion packages/connector/src/MosConnection.ts
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ export class MosConnection extends EventEmitter<MosConnectionEvents> implements
this._debug,
this.mosTypes.strict
)
let secondary = null
let secondary: NCSServerConnection | null = null
this._ncsConnections[connectionOptions.primary.host] = primary

primary.on('rawMessage', (type: string, message: string) => {
@@ -174,6 +174,19 @@ export class MosConnection extends EventEmitter<MosConnectionEvents> implements
false
)
}
// Handle that openMediaHotStandby should not check for heartbeats on
// the secondary connection when the primary is connected
if (connectionOptions.secondary?.openMediaHotStandby) {
primary.on('connectionChanged', () => {
if (secondary) {
if (primary.connected) {
secondary.disableHeartbeats()
} else {
secondary.enableHeartbeats()
}
}
})
}
}

return this._registerMosDevice(
6 changes: 6 additions & 0 deletions packages/connector/src/api.ts
Original file line number Diff line number Diff line change
@@ -663,5 +663,11 @@ export interface IMOSDeviceConnectionOptions {
* Set this to true to not use that port (will cause some methods to stop working)
*/
dontUseQueryPort?: boolean

/** (Optional) OpenMedia has a term called hot standby.
* Set this to true to treat the secondary server as OpenMedia hot-standby.
* And thus ignore the standby state unless the primary server is down.
*/
openMediaHotStandby?: boolean
}
}
14 changes: 14 additions & 0 deletions packages/connector/src/connection/NCSServerConnection.ts
Original file line number Diff line number Diff line change
@@ -106,6 +106,20 @@ export class NCSServerConnection extends EventEmitter<NCSServerConnectionEvents>
delete this._clients[clientID]
}

/** */
disableHeartbeats(): void {
for (const i in this._clients) {
this._clients[i].useHeartbeats = false
}
}

/** */
enableHeartbeats(): void {
for (const i in this._clients) {
this._clients[i].useHeartbeats = true
}
}

connect(): void {
for (const i in this._clients) {
// Connect client