Skip to content

Commit

Permalink
feat(FEC-10057): move the plugin manager to kaltura player (#41)
Browse files Browse the repository at this point in the history
import the plugin infra and types from kaltura-player
Depends on kaltura/kaltura-player-js#332
  • Loading branch information
yairans authored Aug 5, 2020
1 parent 1bb7b4c commit 3380a69
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 20 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
[include]
[libs]
node_modules/@playkit-js/playkit-js/flow-typed/
node_modules/kaltura-player-js/flow-typed/
[options]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
declare module '@playkit-js/playkit-js' {
declare module 'kaltura-player-js' {
declare module.exports: any;
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@babel/preset-env": "^7.10.4",
"@babel/preset-flow": "^7.10.4",
"@babel/register": "^7.10.5",
"@playkit-js/playkit-js": "0.62.1-canary.724715e",
"@playkit-js/playkit-js": "0.63.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-istanbul": "^6.0.0",
Expand All @@ -80,6 +80,7 @@
"flow-bin": "^0.129.0",
"husky": "^4.2.5",
"istanbul": "^0.4.5",
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#v0.56.0",
"karma": "^5.1.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
Expand All @@ -106,7 +107,8 @@
"webpack-dev-server": "^3.11.0"
},
"peerDependencies": {
"@playkit-js/playkit-js": "0.62.1-canary.724715e"
"@playkit-js/playkit-js": "0.63.0",
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#v0.56.0"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion src/ima-dai-engine-decorator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @flow
import {AdBreakType, AdEventType, EventManager, FakeEvent, getLogger, Html5EventType} from '@playkit-js/playkit-js';
import {core} from 'kaltura-player-js';
import {ImaDAI} from './ima-dai';
import {ImaDAIEventManager} from './ima-dai-event-manager';

const {AdBreakType, AdEventType, EventManager, FakeEvent, getLogger, Html5EventType} = core;
/**
* Engine decorator for ima dai plugin.
* @class ImaDAIEngineDecorator
Expand Down
17 changes: 15 additions & 2 deletions src/ima-dai-event-manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @flow
import {AdBreakType, AdEventType, EventManager, FakeEvent, getLogger, Html5EventType} from '@playkit-js/playkit-js';
import {core} from 'kaltura-player-js';
import {ImaDAIEventQueue} from './ima-dai-event-queue';
import {ImaDAI} from './ima-dai';

const {AdBreakType, AdEventType, EventManager, FakeEvent, getLogger, Html5EventType} = core;

class ImaDAIEventManager {
_logger: Object;
_plugin: ImaDAI;
Expand All @@ -11,7 +13,9 @@ class ImaDAIEventManager {
_eventManager: EventManager;
_parallelEvents: Array<string> = [Html5EventType.VOLUME_CHANGE, Html5EventType.SEEKED];
_stopEventDispatchingMap: {[event: string]: boolean} = {
[Html5EventType.ENDED]: false
[Html5EventType.ENDED]: false,
[Html5EventType.SEEKING]: false,
[Html5EventType.SEEKED]: false
};

constructor(plugin: ImaDAI, dispatchEventHandler: Function) {
Expand All @@ -38,6 +42,8 @@ class ImaDAIEventManager {

reset(): void {
this._stopEventDispatchingMap[Html5EventType.ENDED] = false;
this._stopEventDispatchingMap[Html5EventType.SEEKING] = false;
this._stopEventDispatchingMap[Html5EventType.SEEKED] = false;
this._queue.empty();
this._eventManager.removeAll();
this._attachListeners();
Expand All @@ -56,6 +62,10 @@ class ImaDAIEventManager {
Html5EventType.PLAY,
() => !this._plugin.isAdBreak() && (this._stopEventDispatchingMap[Html5EventType.ENDED] = false)
);
this._eventManager.listen(this._plugin.player, Html5EventType.PAUSE, () => {
this._stopEventDispatchingMap[Html5EventType.SEEKING] = false;
this._stopEventDispatchingMap[Html5EventType.SEEKED] = false;
});
}

_onAdBreakStart(event: EventManager): void {
Expand All @@ -64,6 +74,9 @@ class ImaDAIEventManager {
this._logger.debug('Postroll is playing, trigger ENDED event');
this._stopEventDispatchingMap[Html5EventType.ENDED] = true;
this._dispatchEventHandler(new FakeEvent(Html5EventType.ENDED));
// Silence the seek events caused by the sdk once the postroll is done.
this._stopEventDispatchingMap[Html5EventType.SEEKING] = true;
this._stopEventDispatchingMap[Html5EventType.SEEKED] = true;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/ima-dai-event-queue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import {FakeEvent, getLogger, Html5EventType} from '@playkit-js/playkit-js';
import {core} from 'kaltura-player-js';
const {FakeEvent, getLogger, Html5EventType} = core;

class ImaDAIEventQueue {
_ignore: Array<string> = [Html5EventType.TIME_UPDATE, Html5EventType.PROGRESS];
Expand Down
3 changes: 2 additions & 1 deletion src/ima-dai.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @flow
import {Ad, AdBreak, AdBreakType, BasePlugin, EventType, FakeEvent, Utils, Env} from '@playkit-js/playkit-js';
import {core, BasePlugin} from 'kaltura-player-js';
import {ImaDAIState} from './ima-dai-state';
import {ImaDAIEngineDecorator} from './ima-dai-engine-decorator';
import {ImaDAIAdsController} from './ima-dai-ads-controller';
import './assets/style.css';

const {Ad, AdBreak, AdBreakType, EventType, FakeEvent, Utils, Env} = core;
const ADS_CONTAINER_CLASS: string = 'playkit-dai-ads-container';
const ADS_COVER_CLASS: string = 'playkit-dai-ads-cover';

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import {registerPlugin} from '@playkit-js/playkit-js';
import {registerPlugin} from 'kaltura-player-js';
import {ImaDAI} from './ima-dai';

declare var __VERSION__: string;
Expand Down
10 changes: 5 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ module.exports = {
modules: [path.resolve(__dirname, 'src'), 'node_modules']
},
externals: {
'@playkit-js/playkit-js': {
commonjs: '@playkit-js/playkit-js',
commonjs2: '@playkit-js/playkit-js',
amd: 'playkit-js',
root: ['KalturaPlayer', 'core']
'kaltura-player-js': {
commonjs: 'kaltura-player-js',
commonjs2: 'kaltura-player-js',
amd: 'kaltura-player-js',
root: ['KalturaPlayer']
}
}
};
Loading

0 comments on commit 3380a69

Please sign in to comment.