Skip to content

Commit

Permalink
Add flvjs error handling, pass it to props onError method. (#1426)
Browse files Browse the repository at this point in the history
Co-authored-by: Miķelis Jankovskis <mikelis.jankovskis@mapon.com>
  • Loading branch information
mjankovskis and Miķelis Jankovskis committed May 7, 2022
1 parent 1cfea87 commit bc8fe6b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export default class FilePlayer extends Component {
getSDK(FLV_SDK_URL.replace('VERSION', flvVersion), FLV_GLOBAL).then(flvjs => {
this.flv = flvjs.createPlayer({ type: 'flv', url })
this.flv.attachMediaElement(this.player)
this.flv.on(flvjs.Events.ERROR, (e, data) => {
this.props.onError(e, data, this.flv, flvjs)
})
this.flv.load()
this.props.onLoaded()
})
Expand Down
39 changes: 39 additions & 0 deletions test/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,45 @@ test('onError - hls', t => {
})
})

test('onError - flv', t => {
return new Promise(resolve => {
const onError = () => {
t.pass()
resolve()
}

class FlvPlayer {
attachMediaElement () {

};

on = (event, cb) => {
if (event === 'error') {
setTimeout(cb, 100)
}
};

load = () => {}
}

class flvjs {
static Events = { ERROR: 'error' }

loadSource = () => null
attachMedia = () => null
static createPlayer = () => new FlvPlayer()
}
const url = 'file.flv'
const getSDK = sinon.stub(utils, 'getSDK').resolves(flvjs)
const onLoaded = () => null
const instance = shallow(
<FilePlayer url={url} config={config} onLoaded={onLoaded} onError={onError} />
).instance()
instance.load(url)
getSDK.restore()
})
})

test('load - dash', async t => {
const dashjs = {
MediaPlayer: () => ({
Expand Down

0 comments on commit bc8fe6b

Please sign in to comment.