@ldelia/react-media 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,5 +6,5 @@ interface Props {
6
6
  target: InnerYouTubePlayer;
7
7
  }) => void;
8
8
  }
9
- export declare const YouTubeInnerPlayer: ({ videoId, onReady }: Props) => React.JSX.Element;
9
+ export declare const YouTubeInnerPlayer: ({ videoId, onReady }: Props) => React.JSX.Element | null;
10
10
  export {};
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import YouTube from 'react-youtube';
3
3
  export const YouTubeInnerPlayer = ({ videoId, onReady }) => {
4
- const [origin, setOrigin] = useState('');
4
+ const [origin, setOrigin] = useState(null);
5
5
  useEffect(() => {
6
6
  if (typeof window !== 'undefined') {
7
7
  setOrigin(window.location.href);
@@ -17,5 +17,11 @@ export const YouTubeInnerPlayer = ({ videoId, onReady }) => {
17
17
  origin: origin,
18
18
  },
19
19
  };
20
- return (React.createElement(YouTube, { id: 'YT-' + videoId, className: 'youtube-player', videoId: videoId, opts: opts, onReady: onReady }));
20
+ if (origin === null) {
21
+ return null;
22
+ }
23
+ return (React.createElement(YouTube, { id: 'YT-' + videoId, className: 'youtube-player', videoId: videoId, opts: opts, onReady: (event) => {
24
+ console.log("on ready");
25
+ onReady(event);
26
+ } }));
21
27
  };
@@ -2,6 +2,7 @@ import { ReproductionBuilder } from './ReproductionBuilder';
2
2
  import { PlayAlongPlayer } from './Player/PlayAlongPlayer';
3
3
  import { YouTubePlayer } from './Player/YouTubePlayer';
4
4
  type Player = PlayAlongPlayer | YouTubePlayer;
5
+ type Handler = (args: object) => void;
5
6
  declare const dispatchOnReadyHandlers: unique symbol;
6
7
  declare const dispatchOnSongStartHandlers: unique symbol;
7
8
  declare const dispatchOnCountingInHandlers: unique symbol;
@@ -40,8 +41,8 @@ export declare class Reproduction {
40
41
  PAUSED: number;
41
42
  };
42
43
  constructor(player: Player, requiresCountingIn: boolean, songTempo: number);
43
- on(eventName: keyof typeof Reproduction.EVENTS, handler: () => void): number | undefined;
44
- dispatch(eventName: keyof typeof Reproduction.EVENTS): void;
44
+ on(eventName: keyof typeof Reproduction.EVENTS, handler: Handler): number | undefined;
45
+ dispatch(eventName: keyof typeof Reproduction.EVENTS, args?: {}): void;
45
46
  private countIn;
46
47
  start(): void;
47
48
  play(): void;
@@ -74,7 +74,7 @@ export class Reproduction {
74
74
  break;
75
75
  }
76
76
  }
77
- dispatch(eventName) {
77
+ dispatch(eventName, args = {}) {
78
78
  let handler, i, len;
79
79
  let ref = [];
80
80
  switch (eventName) {
@@ -104,14 +104,14 @@ export class Reproduction {
104
104
  }
105
105
  for (i = 0, len = ref.length; i < len; i++) {
106
106
  handler = ref[i];
107
- handler();
107
+ handler(args);
108
108
  // setTimeout(handler, 0);
109
109
  }
110
110
  }
111
111
  countIn(timeout, limit) {
112
- // the initial count starts instantly, no waiting
112
+ // the initial count starts instantly, no need to wait
113
113
  this.countingInCounter++;
114
- this.dispatch(Reproduction.EVENTS.COUNTING_IN);
114
+ this.dispatch(Reproduction.EVENTS.COUNTING_IN, { countingInCounter: this.countingInCounter });
115
115
  const interval = setInterval(() => {
116
116
  this.countingInCounter++;
117
117
  if (this.countingInCounter === limit) {
@@ -125,7 +125,7 @@ export class Reproduction {
125
125
  }
126
126
  }
127
127
  else {
128
- this.dispatch(Reproduction.EVENTS.COUNTING_IN);
128
+ this.dispatch(Reproduction.EVENTS.COUNTING_IN, { countingInCounter: this.countingInCounter });
129
129
  }
130
130
  }, timeout);
131
131
  }
@@ -12,5 +12,9 @@ export const Default = Template.bind({});
12
12
  Default.args = {
13
13
  trainingMode: true,
14
14
  videoId: 'jFI-RBqXzhU',
15
- onInit: (reproduction) => { reproduction.start(); }
15
+ onInit: (reproduction) => {
16
+ console.log("on init");
17
+ reproduction.on('COUNTING_IN', (args) => { console.log("counting in", args); });
18
+ reproduction.start();
19
+ }
16
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldelia/react-media",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "A React components collection for media-related features.",
5
5
  "private": false,
6
6
  "keywords": [