Skip to content

Commit 71d9a88

Browse files
committed
feat: expose event log via debug
1 parent 7160ed1 commit 71d9a88

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Usage](#usage)
77
* [Events](#events)
88
* [Examples](#examples)
9+
* [Debugging](#debugging)
910
* [Download](#download)
1011
* [Running the Examples](#running-the-examples)
1112

@@ -89,13 +90,16 @@ player
8990
player.on('stateChange', (event) => {
9091
// event.data
9192
});
92-
```
93-
93+
94+
```
95+
9496
`player.off` removes a previously added event listener, e.g.
9597

9698
```js
9799
var listener = player.on(/* ... */);
98-
player.off(listener)
100+
101+
player.off(listener);
102+
99103
```
100104

101105
## Examples
@@ -104,6 +108,19 @@ player.off(listener)
104108
* [Multiple players](./examples/src/multiple-players/index.html).
105109
* [Registering events handlers](./examples/src/registering-event-handlers/index.html).
106110

111+
## Debugging
112+
113+
`youtube-player` is using [`debug`](https://www.npmjs.com/package/debug) module to expose debugging information.
114+
115+
The `debug` namespace is "youtube-player".
116+
117+
To display `youtube-player` logs configure `localStorage.debug`, e.g.
118+
119+
```js
120+
localStorage.debug = 'youtube-player:*';
121+
122+
```
123+
107124
## Download
108125

109126
Using [NPM](https://www.npmjs.org/):

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"babel-runtime": "^6.23.0",
15+
"debug": "^2.6.6",
1516
"load-script": "^1.0.0",
1617
"lodash": "^4.17.4",
1718
"sister": "^3.0.0"

src/YouTubePlayer.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import _ from 'lodash';
4+
import createDebug from 'debug';
45
import functionNames from './functionNames';
56
import eventNames from './eventNames';
67
import FunctionStateMap from './FunctionStateMap';
@@ -9,6 +10,8 @@ import type {
910
YouTubePlayerType
1011
} from './types';
1112

13+
const debug = createDebug('youtube-player');
14+
1215
const YouTubePlayer = {};
1316

1417
type EventHandlerMapType = {
@@ -29,6 +32,8 @@ YouTubePlayer.proxyEvents = (emitter: EmitterType): EventHandlerMapType => {
2932
const onEventName = 'on' + _.upperFirst(eventName);
3033

3134
events[onEventName] = (event) => {
35+
debug('event "%s"', onEventName, event);
36+
3237
emitter.trigger(eventName, event);
3338
};
3439
}

0 commit comments

Comments
 (0)