Skip to content

Commit

Permalink
fix(mse): expose HLS errorData in self healing function (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalina authored Jul 16, 2019
1 parent c4ae209 commit f265f45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,26 @@ describe(FloHlsModule.name, () => {
const client = new Hls()
const spyConsole = spyOn(console, 'log')
const spyHls = spyOn(client, 'startLoad').and.callThrough()
selfHealSwitch(client, { type: Hls.ErrorTypes.NETWORK_ERROR, fatal: true } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal network error encountered, trying to recover')
selfHealSwitch(client, { type: Hls.ErrorTypes.NETWORK_ERROR, fatal: true, details: 'info' } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal network error encountered, trying to recover', 'info')
expect(spyHls).toHaveBeenCalled()
})

it('should handle Hls.ErrorTypes.MEDIA_ERROR', () => {
const client = new Hls()
const spyConsole = spyOn(console, 'log')
const spyHls = spyOn(client, 'recoverMediaError').and.callThrough()
selfHealSwitch(client, { type: Hls.ErrorTypes.MEDIA_ERROR, fatal: true } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal media error encountered, trying to recover')
selfHealSwitch(client, { type: Hls.ErrorTypes.MEDIA_ERROR, fatal: true, details: 'info' } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal media error encountered, trying to recover', 'info')
expect(spyHls).toHaveBeenCalled()
})

it('should handle Hls.ErrorTypes.OTHERS', () => {
const client = new Hls()
const spyConsole = spyOn(console, 'log')
const spyHls = spyOn(client, 'destroy').and.callThrough()
selfHealSwitch(client, { type: 'other', fatal: true } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal error, hls client destroyed')
selfHealSwitch(client, { type: 'other', fatal: true, details: 'info' } as any)
expect(spyConsole).toHaveBeenCalledWith('Fatal error, hls client destroyed', 'info')
expect(spyHls).toHaveBeenCalled()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ export function defaultHlsSupportedNativelyFunction(): IVideoElementSupportsTarg
}
}

export const selfHealSwitch = (client: Hls, type: Hls.errorData) => {
export const selfHealSwitch = (client: Hls, errorData: Hls.errorData) => {
// tslint:disable-next-line: no-if-statement
if (!type.fatal) { return }
switch (type.type) {
if (!errorData.fatal) { return }

switch (errorData.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
console.log('Fatal network error encountered, trying to recover')
console.log('Fatal network error encountered, trying to recover', errorData.details)
client.startLoad()
break
case Hls.ErrorTypes.MEDIA_ERROR:
console.log('Fatal media error encountered, trying to recover')
console.log('Fatal media error encountered, trying to recover', errorData.details)
client.recoverMediaError()
break
default:
console.log('Fatal error, hls client destroyed')
console.log('Fatal error, hls client destroyed', errorData.details)
client.destroy()
break
}
Expand Down

0 comments on commit f265f45

Please sign in to comment.