From 028f4b1a80dd0c946417ac408a75a5acec5439b9 Mon Sep 17 00:00:00 2001 From: toxic-johann Date: Fri, 25 Aug 2017 10:03:41 +0800 Subject: [PATCH] [update] fix autoload is false bug What: fix autoload bug by set the videoconfig's src when load Why: the kernel's config is not the same as videoConfig. we must maintain in How: --- __tests__/silentload.js | 12 ++++++++++++ src/dispatcher/index.js | 35 ++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/__tests__/silentload.js b/__tests__/silentload.js index c69c2ab1..28b537ee 100644 --- a/__tests__/silentload.js +++ b/__tests__/silentload.js @@ -264,6 +264,18 @@ describe('load', () => { expect(player.$video).toBe(video); expect(player.__dispatcher.kernel).not.toBe(oldKernel); }); + test('load with different box', async () => { + player.load('http://yunxianchang.live.ujne7.com/vod-system-bj/79_3041054cc65-ae8c-4b63-8937-5ccb05f79720.m3u8', { + box: 'hls', + preset: { + hls: ChimeeKernelHls + } + }); + await Promise.resolve(); + expect(player.$video).not.toBe(oldVideo); + expect(player.$video).toBe(video); + expect(player.__dispatcher.kernel).not.toBe(oldKernel); + }); test('load with different preset', async () => { player.load('http://cdn.toxicjohann.com/%E4%BA%8E%E6%98%AF.mp4', { preset: { diff --git a/src/dispatcher/index.js b/src/dispatcher/index.js index 4af6bd3d..13a1f7bf 100644 --- a/src/dispatcher/index.js +++ b/src/dispatcher/index.js @@ -5,7 +5,7 @@ import Bus from './bus'; import Plugin from './plugin'; import Dom from './dom'; import VideoConfig from './video-config'; -import {before, applyDecorators, accessor} from 'toxic-decorators'; +import {before} from 'toxic-decorators'; const pluginConfigSet: PluginConfigSet = {}; function convertNameIntoId (name: string): string { if(!isString(name)) throw new Error(`Plugin's name must be a string, but not "${name}" in ${typeof name}`); @@ -345,7 +345,11 @@ export default class Dispatcher { const kernel = new Kernel(video, config); this.switchKernel({video, kernel, config}); } - this.kernel.load(src); + const originAutoLoad = this.videoConfig.autoload; + this._changeUnwatchable(this.videoConfig, 'autoload', false); + this.videoConfig.src = src || this.videoConfig.src; + this.kernel.load(this.videoConfig.src); + this._changeUnwatchable(this.videoConfig, 'autoload', originAutoLoad); } switchKernel ({video, kernel, config}: { video: HTMLVideoElement, @@ -373,17 +377,17 @@ export default class Dispatcher { }); this.videoConfig.changeWatchable = true; // bind the new config in new kernel to the videoConfig - applyDecorators(config, { - src: accessor({ - get: value => { - return this.videoConfig.src; - }, - set: value => { - this.videoConfig.src = value; - return value; - } - }) - }, {self: true}); + // applyDecorators(config, { + // src: accessor({ + // get: value => { + // return this.videoConfig.src; + // }, + // set: value => { + // this.videoConfig.src = value; + // return value; + // } + // }) + // }, {self: true}); // the kernel's inner config would not be change according what we do // so we have to load that // applyDecorators(kernel.__proto__, { @@ -460,6 +464,11 @@ export default class Dispatcher { _autoloadVideoSrcAtFirst () { if(this.videoConfig.autoload) this.bus.emit('load', this.videoConfig.src); } + _changeUnwatchable (object: Object, property: string, value: any) { + this.changeWatchable = false; + object[property] = value; + this.changeWatchable = true; + } /** * static method to install plugin * we will store the plugin config