Skip to content

Commit

Permalink
fix: fix load ignore video event bug
Browse files Browse the repository at this point in the history
related to #136

#136
  • Loading branch information
toxic-johann committed Jun 26, 2018
1 parent a42e916 commit 7ea5ed8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
28 changes: 28 additions & 0 deletions __tests__/situation/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,32 @@ describe('load', () => {
expect(originalVideo === player.$video).toBe(true);
player.destroy();
});

test('should not block normal video event at the load event', done => {
const plugin = {
name: 'test',
events: {
play() {
/* eslint-disable */
player.destroy();
/* eslint-enable */
done();
},
},
};
Chimee.install(plugin);
const player = new Chimee({
wrapper: document.createElement('div'),
src: 'http://cdn.toxicjohann.com/lostStar.mp4',
plugins: [ plugin.name ],
});
player.load('http://yunxianchang.live.ujne7.com/vod-system-bj/79_3041054cc65-ae8c-4b63-8937-5ccb05f79720.m3u8', {
box: 'hls',
preset: {
hls: ChimeeKernelHls,
},
}).then(() => {
player.$video.dispatchEvent(new Event('play'));
});
});
});
9 changes: 2 additions & 7 deletions src/dispatcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,11 @@ export default class Dispatcher {
box?: string,
preset?: Object,
kernels?: UserKernelsConfig,
isFirst?: boolean,
}, option: {
isLive?: boolean,
box?: string,
preset?: Object,
kernels?: UserKernelsConfig,
isFirst?: boolean,
} = {}) {
const src: string = isString(srcOrOption)
? srcOrOption
Expand All @@ -419,15 +417,12 @@ export default class Dispatcher {
box = getLegalBox({ src, box: videoConfig.box }),
preset = videoConfig.preset,
kernels = videoConfig.kernels,
isFirst,
} = option;
delete option.isFirst;
if (box !== 'native' || box !== oldBox || !isEmpty(option)) {
option.isFirst = isFirst;
const video = document.createElement('video');
const config = { isLive, box, preset, src, kernels };
const kernel = this._createKernel(video, config);
this.switchKernel({ video, kernel, config, notifyChange: isFirst });
this.switchKernel({ video, kernel, config, notifyChange: true });
}
const originAutoLoad = this.videoConfig.autoload;
this._changeUnwatchable(this.videoConfig, 'autoload', false);
Expand Down Expand Up @@ -560,7 +555,7 @@ export default class Dispatcher {
name: 'load',
target: 'plugin',
id: 'dispatcher',
}, { src: this.videoConfig.src, isFirst: true });
}, { src: this.videoConfig.src });
}
}
_changeUnwatchable(object: Object, property: string, value: any) {
Expand Down

0 comments on commit 7ea5ed8

Please sign in to comment.