diff --git a/__tests__/situation/load.js b/__tests__/situation/load.js index 5fe870d0..959623e9 100644 --- a/__tests__/situation/load.js +++ b/__tests__/situation/load.js @@ -127,7 +127,7 @@ describe('load', () => { expect(player.src).toBe(''); }); - test('should not trigger switch kernel at the first auto load', () => { + test('should not block normal video event at the first auto load', () => { const fn = jest.fn(); const plugin = { name: 'test', @@ -147,4 +147,22 @@ describe('load', () => { expect(fn).toHaveBeenCalledTimes(1); player.destroy(); }); + + test('should not switch kernel at the first auto load', () => { + let originalVideo; + const plugin = { + name: 'test', + create() { + originalVideo = this.$video; + }, + }; + Chimee.install(plugin); + const player = new Chimee({ + wrapper: document.createElement('div'), + src: 'http://cdn.toxicjohann.com/lostStar.mp4', + plugins: [ plugin.name ], + }); + expect(originalVideo === player.$video).toBe(true); + player.destroy(); + }); }); diff --git a/src/dispatcher/index.js b/src/dispatcher/index.js index a9339436..a1959940 100644 --- a/src/dispatcher/index.js +++ b/src/dispatcher/index.js @@ -1,6 +1,7 @@ // @flow import { isString, camelize, deepAssign, isObject, isEmpty, isArray, isFunction, transObjectAttrIntoArray, isPromise, Log, runRejectableQueue, addEvent, removeEvent, isError, deepClone } from 'chimee-helper'; import ChimeeKernel from './kernel'; +import { getLegalBox } from './kernel'; import Plugin from './plugin'; import Dom from './dom'; import VideoConfig from 'config/video'; @@ -415,12 +416,14 @@ export default class Dispatcher { const videoConfig = this.videoConfig; const { isLive = videoConfig.isLive, - box = videoConfig.box, + 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); diff --git a/src/dispatcher/kernel.js b/src/dispatcher/kernel.js index 9741de77..e37920a2 100644 --- a/src/dispatcher/kernel.js +++ b/src/dispatcher/kernel.js @@ -6,9 +6,21 @@ const LOG_TAG = 'chimee'; const boxSuffixMap = { flv: '.flv', hls: '.m3u8', - mp4: '.mp4', + native: '.mp4', }; +// return the config box +// or choose the right one according to the src +export function getLegalBox({ src, box }: { src: string, box: string }): string { + if (isString(box) && box) return box; + src = src.toLowerCase(); + for (const key in boxSuffixMap) { + const suffix = boxSuffixMap[key]; + if (src.indexOf(suffix) > -1) return key; + } + return 'native'; +} + export default class ChimeeKernel { box: string; boxConfig: Object; @@ -34,7 +46,7 @@ export default class ChimeeKernel { initVideoKernel() { const config = this.config; - const box = this.chooseBox(config); + const box = getLegalBox(config); this.box = box; const VideoKernel = this.chooseVideoKernel(this.box, config.preset); @@ -50,18 +62,6 @@ export default class ChimeeKernel { this.videoKernel = new VideoKernel(this.videoElement, config, customConfig); } - // return the config box - // or choose the right one according to the src - chooseBox({ src, box }: { src: string, box: string }): string { - if (isString(box) && box) return box; - src = src.toLowerCase(); - for (const key in boxSuffixMap) { - const suffix = boxSuffixMap[key]; - if (src.indexOf(suffix) > -1) return key; - } - return 'native'; - } - // choose the right video kernel according to the box setting chooseVideoKernel(box: string, preset: { [string]: Function }): VideoKernel { switch (box) {