Skip to content

Commit

Permalink
feat: refactor youbora implementation (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
yairans authored and Dan Ziv committed Aug 22, 2017
1 parent 4879639 commit aa864c2
Show file tree
Hide file tree
Showing 14 changed files with 1,094 additions and 623 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/src/youbora/youbora.lib.min.js
/src/youbora.lib.min.js
/flow-typed/**/*.js
/coverage
/dist
Expand Down
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"sinon": true
},
"rules": {
"mocha-no-only/mocha-no-only": [
"error"
],
"mocha-no-only/mocha-no-only": "off",
"require-jsdoc": [
"error"
],
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jspm_packages
#VSCode configuration
.vscode

dist/
.idea/
flow-typed/

/dist/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ player.play();

## Configuration

//TODO
This plugin configuration reflects Youbora options,
For full Youbora options see: http://developer.nicepeopleatwork.com/apidocs/js/$YB.data.Options.html

## Running the tests

Expand Down
27 changes: 19 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "playkit-js-youbora",
"version": "1.0.0",
"description": "",
"version": "0.0.1",
"main": "dist/playkit-youbora.js",
"scripts": {
"clean": "rm -rf ./dist",
"prebuild": "npm run clean",
"build:prod": "NODE_ENV=production webpack",
"build": "webpack",
"dev": "webpack --progress --colors --watch",
"test": "NODE_ENV=test karma start --color",
Expand All @@ -14,10 +15,17 @@
"test:safari": "NODE_ENV=test karma start --color --browsers Safari",
"test:watch": "NODE_ENV=test karma start --color --auto-watch",
"start": "webpack-dev-server",
"release": "NODE_ENV=production npm run build -- -p && git add --all dist && git commit -m 'update dist' && standard-version",
"release": "standard-version",
"publish": "git push --follow-tags --no-verify origin master",
"eslint": "eslint . --color",
"flow": "flow check",
"prepush": "npm run eslint && npm run test && npm run flow"
"eslint:flow:test": "npm run eslint && npm run flow && npm run test",
"commit:dist": "git add --force --all dist && (git commit -m 'chore: update dist' || exit 0)"
},
"standard-version": {
"scripts": {
"postbump": "yarn run build && yarn run build:prod && npm run commit:dist"
}
},
"devDependencies": {
"babel-cli": "^6.18.0",
Expand All @@ -31,6 +39,7 @@
"babel-register": "^6.23.0",
"chai": "^3.5.0",
"cross-env": "^3.1.4",
"css-loader": "^0.28.4",
"eslint": "^3.10.0",
"eslint-loader": "^1.6.1",
"eslint-plugin-flowtype": "^2.30.0",
Expand All @@ -51,19 +60,21 @@
"karma-webpack": "^2.0.2",
"mocha": "^3.2.0",
"mocha-cli": "^1.0.1",
"nyc": "^10.1.2",
"playkit-js": "https://github.com/kaltura/playkit-js.git#v0.3.0",
"pre-push": "^0.1.1",
"sinon": "^2.0.0",
"sinon-chai": "^2.8.0",
"standard-version": "^4.0.0",
"style-loader": "^0.18.2",
"uglifyjs-webpack-plugin": "^0.4.3",
"webpack": "latest",
"webpack-dev-server": "latest"
},
"peerDependencies": {
"playkit-js": "https://github.com/kaltura/playkit-js.git#v0.3.0"
},
"keywords": [],
"license": "AGPL-3.0",
"dependencies": {
"playkit-js": "https://github.com/kaltura/playkit-js.git#develop"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kaltura/playkit-js-youbora.git"
Expand Down
34 changes: 34 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./playkit-youbora.js"></script>
</head>
<body>
<div id="player-placeholder"></div>
<script>
window.p = Playkit.loadPlayer('player-placeholder', {
sources: {
"progressive": [
{
"url": "http://deslasexta.antena3.com/mp_series1/2012/09/10/00001.mp4",
"mimetype": "video/mp4",
"id": "id1",
"width": 200,
"height": 100,
"bandwidth": 100000,
"label": "label1"
}
]
},
plugins: {
youbora: {
'accountCode': 'powerdev'
}
}
});
window.p.play();
</script>
</body>
</html>
54 changes: 42 additions & 12 deletions src/youbora/youbora-plugin.js → src/youbora-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
* @author Jordi Aguilar & Dan Ziv
*/
import $YB from './youbora.lib.min'
import {VERSION} from 'playkit-js'
import * as pkg from '../../package.json'
import {VERSION, PLAYER_NAME} from 'playkit-js'
import * as pkg from '../package.json'

$YB.plugins.KalturaV3 = function (player, options) {
try {
/** Name and platform of the plugin.*/
this.pluginName = 'kalturaplaykit-js';
this.pluginName = PLAYER_NAME;

/** Version of the plugin. ie: 5.1.0-name */
this.pluginVersion = '5.3.0-' + pkg.version + '-kalturaplaykit-js';
this.pluginVersion = $YB.version + '-' + pkg.version + '-' + PLAYER_NAME;

/* Initialize YouboraJS */
this.startMonitoring(player, options);
Expand Down Expand Up @@ -61,7 +60,30 @@ $YB.plugins.KalturaV3.prototype.getResource = function () {
* @returns {string} - The current player version.
*/
$YB.plugins.KalturaV3.prototype.getPlayerVersion = function () {
return 'KalturaPlaykitJS ' + VERSION;
return PLAYER_NAME + "-" + VERSION;
};

$YB.plugins.KalturaV3.prototype.getBitrate = function () {
let activeVideo = this.player.getActiveTracks().video;
if (activeVideo && activeVideo.bandwidth) {
return activeVideo.bandwidth;
}
return -1;
};

$YB.plugins.KalturaV3.prototype.getTitle = function () {
return this.player.config.name;
};

$YB.plugins.KalturaV3.prototype.getRendition = function () {
let activeVideo = this.player.getActiveTracks().video;
if (activeVideo) {
return $YB.utils.buildRenditionString(activeVideo.width, activeVideo.height, activeVideo.bandwidth);
}
};

$YB.plugins.KalturaV3.prototype.getIsLive = function () {
return this.player.config.type === "Live";
};

/**
Expand All @@ -70,9 +92,9 @@ $YB.plugins.KalturaV3.prototype.getPlayerVersion = function () {
*/
$YB.plugins.KalturaV3.prototype.registerListeners = function () {
// save context
var context = this;
var Event = this.player.Event;
var State = this.player.State;
let context = this;
let Event = this.player.Event;
let State = this.player.State;

// Play is clicked (/start)
this.player.addEventListener(Event.PLAY, function () {
Expand Down Expand Up @@ -104,12 +126,20 @@ $YB.plugins.KalturaV3.prototype.registerListeners = function () {
context.seekingHandler();
});

// video seek end
this.player.addEventListener(Event.SEEKED, function () {
context.seekedHandler();
});

this.player.addEventListener(Event.PLAYER_STATE_CHANGED, function (e) {
var oldState = e.payload.oldState.type;
var newState = e.payload.newState.type;
if (oldState === State.PLAYING && newState === State.BUFFERING) {
let newState = e.payload.newState.type;
let oldState = e.payload.oldState.type;
if (newState === State.BUFFERING) {
context.bufferingHandler();
}
if (oldState === State.BUFFERING) {
context.bufferedHandler();
}
});
};

Expand Down
33 changes: 25 additions & 8 deletions src/youbora.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//@flow
import {registerPlugin, BasePlugin} from 'playkit-js'
import YouboraPlugin from './youbora/youbora-plugin'
//eslint-disable-next-line no-unused-vars
import sample from '../samples/index.js'
import YouboraAdapter from './youbora-adapter'

/**
* The plugin name.
Expand All @@ -15,15 +13,15 @@ const pluginName = "youbora";
* Youbora plugin for analytics.
* @classdesc
*/
class Youbora extends BasePlugin {
export default class Youbora extends BasePlugin {

/**
* The default configuration of the plugin.
* @type {Object}
* @static
*/
static defaultConfig: Object = {
accountCode: 'powerdev'
haltOnError: false
};

/**
Expand All @@ -41,13 +39,32 @@ class Youbora extends BasePlugin {
* @param {Player} player - Access to the player reference.
* @param {Object} config - The plugin configuration.
*/
constructor(name, player, config) {
constructor(name: string, player: Player, config: Object) {
super(name, player, config);
this._youbora = new YouboraPlugin(this.player, this.config);
this._addPlayerMetadata();
this._youbora = new YouboraAdapter(this.player, this.config);
this._addBindings();
this._setup();
}

/**
* Add the player metadata to the plugin config.
* @function
* @private
* @returns {void}
*/
_addPlayerMetadata(): void {
this.updateConfig({
properties: {
kalturaInfo: {
entryId: this.player.config.id,
sessionId: this.player.config.session ? this.player.config.session.id : "",
uiConfId: this.player.config.session ? this.player.config.session.uiConfID : ""
}
}
});
}

/**
* Add the necessary bindings.
* @function
Expand All @@ -56,7 +73,7 @@ class Youbora extends BasePlugin {
*/
_addBindings(): void {
// Bind the plugin logger to the youbora sdk logger
YouboraPlugin.bindLogger(this.logger);
YouboraAdapter.bindLogger(this.logger);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/youbora.lib.min.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/youbora/youbora.lib.min.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rules": {
"flowtype/no-types-missing-file-annotation": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off",
"mocha-no-only/mocha-no-only": [
"error"
]
}
}
Loading

0 comments on commit aa864c2

Please sign in to comment.