Skip to content

Commit

Permalink
chore: prettier (#33)
Browse files Browse the repository at this point in the history
Add prettier settings for code style.
  • Loading branch information
Dan Ziv authored Jul 16, 2018
1 parent da85e60 commit 5782c2f
Show file tree
Hide file tree
Showing 17 changed files with 1,124 additions and 225 deletions.
20 changes: 5 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"plugins": [
"import",
"flowtype",
"mocha-no-only"
],
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"plugins": ["prettier", "import", "flowtype", "mocha-no-only"],
"env": {
"browser": true,
"es6": true,
Expand All @@ -23,12 +16,9 @@
"__NAME__": true
},
"rules": {
"prettier/prettier": "error",
"mocha-no-only/mocha-no-only": "off",
"require-jsdoc": [
"error"
],
"valid-jsdoc": [
"error"
]
"require-jsdoc": ["error"],
"valid-jsdoc": ["error"]
}
}
4 changes: 1 addition & 3 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[ignore]
.*/node_modules/conventional-changelog-core/test/fixtures/_malformation.json
.*/node_modules/playkit-js/src/
.*/node_modules/playkit-js-providers/src/
.*/node_modules
[include]
[libs]
node_modules/playkit-js/flow-typed/
Expand Down
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/dist
/src/index.html
CHANGELOG.md
yarn.lock
yarn-error.log
LICENSE
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 150,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"jsxBracketSameLine": true,
"arrowParens": "avoid",
"proseWrap": "preserve"
}
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# PlayKit JS KAnalytics - Kaltura Analytics plugin for the [PlayKit JS Player]

[![Build Status](https://travis-ci.org/kaltura/playkit-js-kanalytics.svg?branch=master)](https://travis-ci.org/kaltura/playkit-js-kanalytics)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

PlayKit JS KAnalytics plugin integrates Kaltura analytics with the [PlayKit JS Player].

PlayKit JS KAnalytics is written in [ECMAScript6], statically analysed using [Flow] and transpiled in ECMAScript5 using [Babel].

More info about Kaltura Analytics:
* [Video-Analytics]
* [Creating and tracking analytics KMC]
More info about Kaltura Analytics:

- [Video-Analytics]
- [Creating and tracking analytics KMC]

[Video-Analytics]: https://corp.kaltura.com/Products/Features/Video-Analytics
[Creating and tracking analytics KMC]: https://knowledge.kaltura.com/creating-and-tracking-analytics-kmc-0
[Flow]: https://flow.org/
[ECMAScript6]: https://github.com/ericdouglas/ES6-Learning#articles--tutorials
[Babel]: https://babeljs.io
[video-analytics]: https://corp.kaltura.com/Products/Features/Video-Analytics
[creating and tracking analytics kmc]: https://knowledge.kaltura.com/creating-and-tracking-analytics-kmc-0
[flow]: https://flow.org/
[ecmascript6]: https://github.com/ericdouglas/ES6-Learning#articles--tutorials
[babel]: https://babeljs.io

## Getting Started

### Prerequisites

The plugin requires [PlayKit JS Player] to be loaded first.

[Playkit JS Player]: https://github.com/kaltura/playkit-js
[playkit js player]: https://github.com/kaltura/playkit-js

### Installing

Expand Down Expand Up @@ -56,7 +59,7 @@ var playerContainer = document.querySelector("#player-placeholder");
var config = {
...
plugins: {
kanalytics: {
kanalytics: {
serviceUrl: 'http://stats.kaltura.com/api_v3/index.php'
}
}
Expand All @@ -70,20 +73,22 @@ player.play();

## Configuration

| Settings | Type | Required | Description |
|---------- |-------- |-------------------- |---------------------------- |
| serviceUrl | string | :white_check_mark: | The Kaltura API server url |
| Settings | Type | Required | Description |
| ---------- | ------ | ------------------ | -------------------------- |
| serviceUrl | string | :white_check_mark: | The Kaltura API server url |

## Running the tests

Tests can be run locally via [Karma], which will run on Chrome, Firefox and Safari

[Karma]: https://karma-runner.github.io/1.0/index.html
[karma]: https://karma-runner.github.io/1.0/index.html

```
yarn run test
```

You can test individual browsers:

```
yarn run test:chrome
yarn run test:firefox
Expand All @@ -98,7 +103,6 @@ See [ESLint config](.eslintrc.json) for full configuration.

We also use [.editorconfig](.editorconfig) to maintain consistent coding styles and settings, please make sure you comply with the styling.


## Compatibility

TBD
Expand All @@ -109,7 +113,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/kaltura/playkit-js-kanalytics/tags).
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/kaltura/playkit-js-kanalytics/tags).

## License

Expand Down
4 changes: 4 additions & 0 deletions flow-typed/modules/playkit-js-providers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow
declare module 'playkit-js-providers/dist/playkit-stats-service' {
declare module.exports: any;
}
4 changes: 4 additions & 0 deletions flow-typed/modules/playkit-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow
declare module 'playkit-js' {
declare module.exports: any;
}
34 changes: 8 additions & 26 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,20 @@ const customLaunchers = {
}
};

module.exports = function (config) {
module.exports = function(config) {
let karmaConf = {
logLevel: config.LOG_INFO,
browsers: [
'Chrome',
'Firefox'
],
browsers: ['Chrome', 'Firefox'],
concurrency: 1,
singleRun: true,
colors: true,
frameworks: [
'mocha'
],
files: [
'test/setup/karma.js'
],
frameworks: ['mocha'],
files: ['test/setup/karma.js'],
preprocessors: {
'src/**/*.js': [
'webpack',
'sourcemap'
],
'test/setup/karma.js': [
'webpack',
'sourcemap'
]
'src/**/*.js': ['webpack', 'sourcemap'],
'test/setup/karma.js': ['webpack', 'sourcemap']
},
reporters: [
'progress',
'coverage'
],
reporters: ['progress', 'coverage'],
webpack: webpackConfig,
webpackServer: {
noInfo: true
Expand All @@ -56,9 +40,7 @@ module.exports = function (config) {

if (process.env.TRAVIS) {
karmaConf.customLaunchers = customLaunchers;
karmaConf.browsers = [
'Chrome_travis_ci'
];
karmaConf.browsers = ['Chrome_travis_ci'];
} else {
if (isWindows) {
karmaConf.browsers.push('IE');
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
"publish": "git push --follow-tags --no-verify origin master",
"eslint": "eslint . --color",
"flow": "flow check",
"commit:dist": "git add --force --all dist && (git commit -m 'chore: update dist' || exit 0)"
"commit:dist": "git add --force --all dist && (git commit -m 'chore: update dist' || exit 0)",
"precommit": "lint-staged"
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{json,md,scss}": [
"prettier --write",
"git add"
]
},
"standard-version": {
"scripts": {
Expand All @@ -34,11 +45,14 @@
"chai": "^3.5.0",
"cross-env": "^3.1.4",
"eslint": "^3.10.0",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "^1.6.1",
"eslint-plugin-flowtype": "^2.30.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-mocha-no-only": "^0.0.5",
"eslint-plugin-prettier": "^2.6.2",
"flow-bin": "latest",
"husky": "^0.14.3",
"istanbul": "^0.4.5",
"karma": "^1.5.0",
"karma-chai": "^0.1.0",
Expand All @@ -51,11 +65,12 @@
"karma-safari-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.2",
"lint-staged": "^7.2.0",
"mocha": "^3.2.0",
"mocha-cli": "^1.0.1",
"playkit-js": "https://github.com/kaltura/playkit-js.git#v0.29.0",
"playkit-js-providers": "https://github.com/kaltura/playkit-js-providers.git#v2.5.0",
"pre-push": "^0.1.1",
"prettier": "^1.13.7",
"sinon": "^2.0.0",
"sinon-chai": "^2.8.0",
"standard-version": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/event-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@flow
const EVENT_TYPES: { [event: string]: number } = {
const EVENT_TYPES: {[event: string]: number} = {
WIDGET_LOADED: 1,
MEDIA_LOADED: 2,
PLAY: 3,
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow
import {registerPlugin} from 'playkit-js'
import KAnalytics from './kanalytics'
import {registerPlugin} from 'playkit-js';
import KAnalytics from './kanalytics';

declare var __VERSION__: string;
declare var __NAME__: string;

export default KAnalytics;
export {__VERSION__ as VERSION, __NAME__ as NAME};

const pluginName = "kanalytics";
const pluginName = 'kanalytics';
/**
* Register the plugin in the playkit-js plugin framework.
*/
Expand Down
38 changes: 20 additions & 18 deletions src/kanalytics.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@flow
import {BasePlugin} from 'playkit-js'
import {OVPStatsService, RequestBuilder} from 'playkit-js-providers/dist/playkit-stats-service'
import EventTypes from './event-types'
import Event from './event'
import {BasePlugin} from 'playkit-js';
import {OVPStatsService, RequestBuilder} from 'playkit-js-providers/dist/playkit-stats-service';
import EventTypes from './event-types';
import Event from './event';

const SEEK_OFFSET: number = 2000;
const LIVE: string = 'Live';
Expand Down Expand Up @@ -47,12 +47,12 @@ export default class KAnalytics extends BasePlugin {
* The Kaltura session
* @private
*/
_ks: string = "";
_ks: string = '';
/**
* Indicate whether time percent event already sent
* @private
*/
_timePercentEvent: { [event: string]: boolean } = {};
_timePercentEvent: {[event: string]: boolean} = {};
/**
* Indicate whether widget loaded event already sent
* @private
Expand All @@ -77,7 +77,7 @@ export default class KAnalytics extends BasePlugin {
reset(): void {
this._hasSeeked = false;
this._ended = false;
this._ks = "";
this._ks = '';
this._timePercentEvent = {};
}

Expand Down Expand Up @@ -113,7 +113,7 @@ export default class KAnalytics extends BasePlugin {
_onSourceSelected(): void {
if (!this._widgetLoadedEventSent) {
this._sendAnalytics(EventTypes.WIDGET_LOADED);
this._widgetLoadedEventSent = true
this._widgetLoadedEventSent = true;
}
this.player.ready().then(() => {
this._sendAnalytics(EventTypes.MEDIA_LOADED);
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class KAnalytics extends BasePlugin {
*/
_sendSeekAnalytic(): void {
const now = new Date().getTime();
if ((this._lastSeekEvent + SEEK_OFFSET < now) && (this.player.config.type !== LIVE || this.player.config.dvr)) {
if (this._lastSeekEvent + SEEK_OFFSET < now && (this.player.config.type !== LIVE || this.player.config.dvr)) {
// avoid sending lots of seeking while scrubbing
this._sendAnalytics(EventTypes.SEEK);
this._hasSeeked = true;
Expand All @@ -179,15 +179,15 @@ export default class KAnalytics extends BasePlugin {
_sendTimePercentAnalytic(): void {
if (this.player.config.type !== LIVE) {
const percent = this.player.currentTime / this.player.duration;
if (!this._timePercentEvent.PLAY_REACHED_25 && percent >= .25) {
if (!this._timePercentEvent.PLAY_REACHED_25 && percent >= 0.25) {
this._timePercentEvent.PLAY_REACHED_25 = true;
this._sendAnalytics(EventTypes.PLAY_REACHED_25);
}
if (!this._timePercentEvent.PLAY_REACHED_50 && percent >= .50) {
if (!this._timePercentEvent.PLAY_REACHED_50 && percent >= 0.5) {
this._timePercentEvent.PLAY_REACHED_50 = true;
this._sendAnalytics(EventTypes.PLAY_REACHED_50);
}
if (!this._timePercentEvent.PLAY_REACHED_75 && percent >= .75) {
if (!this._timePercentEvent.PLAY_REACHED_75 && percent >= 0.75) {
this._timePercentEvent.PLAY_REACHED_75 = true;
this._sendAnalytics(EventTypes.PLAY_REACHED_75);
}
Expand All @@ -211,7 +211,7 @@ export default class KAnalytics extends BasePlugin {
sessionId: this.config.sessionId,
uiConfId: this.config.uiConfId || 0,
partnerId: this.config.partnerId,
widgetId: this.config.partnerId ? "_" + this.config.partnerId : "",
widgetId: this.config.partnerId ? '_' + this.config.partnerId : '',
referrer: this.config.referrer
};
}
Expand All @@ -232,13 +232,15 @@ export default class KAnalytics extends BasePlugin {
statsEvent.seek = this._hasSeeked;
statsEvent.hasKanalony = this.config.hasKanalony;
Object.assign(statsEvent, this._playerParams);
const request: RequestBuilder = OVPStatsService.collect(this.config.serviceUrl, this._ks, this.config.playerVersion, {"event": statsEvent});
request.doHttpRequest()
.then(() => {
const request: RequestBuilder = OVPStatsService.collect(this.config.serviceUrl, this._ks, this.config.playerVersion, {event: statsEvent});
request.doHttpRequest().then(
() => {
this.logger.debug(`Analytics event sent `, statsEvent);
}, err => {
},
err => {
this.logger.error(`Failed to send analytics event `, statsEvent, err);
});
}
);
}

_validate(): boolean {
Expand Down
Loading

0 comments on commit 5782c2f

Please sign in to comment.