Skip to content

Commit

Permalink
fix: recreate removed mediaObjects after reconnecting
Browse files Browse the repository at this point in the history
mediaObject are cleared when losing connection to MSE
  • Loading branch information
ianshade committed Apr 13, 2021
1 parent dd6ea93 commit 1a7e65d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/devices/vizMSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState> implements IDevic
}
public connectionChanged (connected?: boolean) {
if (connected === true || connected === false) this._vizMSEConnected = connected
if (connected === false) {
this.emit('clearMediaObjects', this.deviceId)
}
this.emit('connectionChanged', this.getStatus())
}
/**
Expand Down Expand Up @@ -401,7 +404,6 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState> implements IDevic
if (!this._vizMSEConnected) {
statusCode = StatusCode.BAD
messages.push('Not connected')
this.emit('clearMediaObjects', this.deviceId)
} else if (this._vizmseManager) {
if (this._vizmseManager.notLoadedCount > 0 || this._vizmseManager.loadingCount > 0) {
statusCode = StatusCode.WARNING_MINOR
Expand Down Expand Up @@ -794,6 +796,7 @@ class VizMSEManager extends EventEmitter {
private _terminated: boolean = false
private _activeRundownPlaylistId: string | undefined
private _preloadedRundownPlaylistId: string | undefined
private _updateAfterReconnect: boolean = false

public get activeRundownPlaylistId () {
return this._activeRundownPlaylistId
Expand Down Expand Up @@ -1395,7 +1398,7 @@ class VizMSEManager extends EventEmitter {
isLoading: this._isElementLoading(newEl)
}
this.emit('debug', `Element ${elementRef}: ${JSON.stringify(newEl)}`)
if (this._isExternalElement(newEl) && cachedEl?.isLoaded !== this._elementsLoaded[e.hash].isLoaded) {
if (this._isExternalElement(newEl) && (this._updateAfterReconnect || cachedEl?.isLoaded !== this._elementsLoaded[e.hash].isLoaded)) {
if (this._elementsLoaded[e.hash].isLoaded) {
const mediaObject: MediaObject = {
_id: e.hash,
Expand All @@ -1419,7 +1422,7 @@ class VizMSEManager extends EventEmitter {
}
})
)

this._updateAfterReconnect = false
this.emit('debug', `Updating status of elements done, this._elementsLoaded.length=${_.keys(this._elementsLoaded).length}`)

} else {
Expand Down Expand Up @@ -1736,6 +1739,9 @@ class VizMSEManager extends EventEmitter {
private mseConnectionChanged (connected: boolean) {
if (connected !== this._mseConnected) {
this._mseConnected = connected
if (connected) {
this._updateAfterReconnect = true
}
this.onConnectionChanged()
}
}
Expand Down

0 comments on commit 1a7e65d

Please sign in to comment.