Skip to content

Commit

Permalink
chore: add onChildClose handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Sep 11, 2024
1 parent 004243e commit cf0e82b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/timeline-state-resolver/src/service/ConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
// set up event handlers
await this._setupDeviceListeners(id, container)

container.onChildClose = () => {
this.emit('error', 'Connection ' + id + ' closed')
this._connections.delete(id)
this.emit('connectionRemoved', id)

container
.terminate()
.catch((e) => this.emit('warning', `Failed to initialise ${id} (${e})`))
.finally(() => {
this._updateConnections()
})
}

this._connections.set(id, container)
this.emit('connectionAdded', id, container)

Expand All @@ -231,13 +244,13 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
this.emit('connectionInitialised', id)
})
.catch((e) => {
this.emit('error', 'Connection ' + id + ' failed to initialise')
this.emit('error', 'Connection ' + id + ' failed to initialise', e)
this._connections.delete(id)
this.emit('connectionRemoved', id)

container
.terminate()
.catch(() => this.emit('warning', `Failed to initialise ${id} (${e})`))
.catch((e) => this.emit('warning', `Failed to initialise ${id} (${e})`))
.finally(() => {
this._updateConnections()
})
Expand Down

0 comments on commit cf0e82b

Please sign in to comment.