Skip to content

Commit

Permalink
[update] fix autoload is false bug
Browse files Browse the repository at this point in the history
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:
  • Loading branch information
toxic-johann committed Aug 25, 2017
1 parent cd8f232 commit 028f4b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
12 changes: 12 additions & 0 deletions __tests__/silentload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
35 changes: 22 additions & 13 deletions src/dispatcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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__, {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 028f4b1

Please sign in to comment.