@clockworkdog/cogs-client-react 2.1.2 → 2.2.0

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { CogsConnection } from '@clockworkdog/cogs-client';
3
3
  export default function Hint({ connection: customConnection, }: {
4
- connection: CogsConnection<any>;
4
+ connection?: CogsConnection<any>;
5
5
  }): JSX.Element | null;
@@ -7,8 +7,7 @@ const react_1 = __importDefault(require("react"));
7
7
  const useHint_1 = __importDefault(require("../hooks/useHint"));
8
8
  const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
9
9
  function Hint({ connection: customConnection, }) {
10
- const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
11
- const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
10
+ const connection = (0, CogsConnectionProvider_1.useCogsConnection)(customConnection);
12
11
  const hint = (0, useHint_1.default)(connection);
13
12
  return hint ? react_1.default.createElement(react_1.default.Fragment, null, hint) : null;
14
13
  }
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  export default function Images({ className, style, connection: customConnection, fullscreen, }: {
4
4
  className?: string;
5
5
  style?: React.CSSProperties;
6
- connection: CogsConnection<any>;
6
+ connection?: CogsConnection<any>;
7
7
  fullscreen?: boolean | {
8
8
  style: React.CSSProperties;
9
9
  };
@@ -7,8 +7,7 @@ const react_1 = __importDefault(require("react"));
7
7
  const useImages_1 = __importDefault(require("../hooks/useImages"));
8
8
  const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
9
9
  function Images({ className, style, connection: customConnection, fullscreen, }) {
10
- const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
11
- const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
10
+ const connection = (0, CogsConnectionProvider_1.useCogsConnection)(customConnection);
12
11
  const images = (0, useImages_1.default)(connection);
13
12
  const fullscreenCustomStyle = typeof fullscreen === 'object' ? fullscreen.style : undefined;
14
13
  const imageElements = images.map((image, index) => {
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  export default function Timer({ className, style, connection: customConnection, separator, center, }: {
4
4
  className?: string;
5
5
  style?: React.CSSProperties;
6
- connection: CogsConnection<any>;
6
+ connection?: CogsConnection<any>;
7
7
  separator?: string;
8
8
  center?: boolean;
9
9
  }): JSX.Element;
@@ -44,8 +44,7 @@ function formatTime(time, countingUp) {
44
44
  }
45
45
  function Timer({ className, style, connection: customConnection, separator = ':', center, }) {
46
46
  var _a, _b, _c, _d, _e, _f;
47
- const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
48
- const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
47
+ const connection = (0, CogsConnectionProvider_1.useCogsConnection)(customConnection);
49
48
  const [timerElapsed, setTimerElapsed] = (0, react_1.useState)(0);
50
49
  const [timerStartedAt, setTimerStartedAt] = (0, react_1.useState)((_b = (_a = connection.timerState) === null || _a === void 0 ? void 0 : _a.startedAt) !== null && _b !== void 0 ? _b : 0);
51
50
  const [timerTotalMillis, setTimerTotalMillis] = (0, react_1.useState)((_d = (_c = connection.timerState) === null || _c === void 0 ? void 0 : _c.durationMillis) !== null && _d !== void 0 ? _d : 0);
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  export default function VideoContainer({ className, style, videoPlayer: customVideoPlayer, fullscreen, }: {
4
4
  className?: string;
5
5
  style?: React.CSSProperties;
6
- videoPlayer: CogsVideoPlayer | null;
6
+ videoPlayer?: CogsVideoPlayer | null;
7
7
  fullscreen?: boolean | {
8
8
  style: React.CSSProperties;
9
9
  };
@@ -27,8 +27,7 @@ const react_1 = __importStar(require("react"));
27
27
  const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
28
28
  function VideoContainer({ className, style, videoPlayer: customVideoPlayer, fullscreen, }) {
29
29
  const containerRef = (0, react_1.useRef)(null);
30
- const providerVideoPlayer = (0, CogsConnectionProvider_1.useVideoPlayer)();
31
- const videoPlayer = customVideoPlayer !== null && customVideoPlayer !== void 0 ? customVideoPlayer : providerVideoPlayer;
30
+ const videoPlayer = (0, CogsConnectionProvider_1.useVideoPlayer)(customVideoPlayer !== null && customVideoPlayer !== void 0 ? customVideoPlayer : undefined);
32
31
  (0, react_1.useEffect)(() => {
33
32
  if (videoPlayer && containerRef.current) {
34
33
  videoPlayer.setParentElement(containerRef.current);
@@ -1,2 +1,2 @@
1
1
  import { CogsAudioPlayer } from '@clockworkdog/cogs-client';
2
- export default function useIsAudioPlaying(audioPlayer: CogsAudioPlayer | null): boolean;
2
+ export default function useIsAudioPlaying(customAudioPlayer?: CogsAudioPlayer | null): boolean;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
- function useIsAudioPlaying(audioPlayer) {
4
+ const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
5
+ function useIsAudioPlaying(customAudioPlayer) {
5
6
  const [isAudioPlaying, setAudioPlaying] = (0, react_1.useState)(false);
7
+ const audioPlayer = (0, CogsConnectionProvider_1.useAudioPlayer)(customAudioPlayer !== null && customAudioPlayer !== void 0 ? customAudioPlayer : undefined);
6
8
  (0, react_1.useEffect)(() => {
7
9
  const listener = (event) => setAudioPlaying(event.detail.isPlaying);
8
10
  audioPlayer === null || audioPlayer === void 0 ? void 0 : audioPlayer.addEventListener('state', listener);
@@ -59,12 +59,12 @@ export default function CogsConnectionProvider<Manifest extends CogsPluginManife
59
59
  /**
60
60
  * Get the connection from `<CogsConnectionProvider>`
61
61
  */
62
- export declare function useCogsConnection<Manifest extends CogsPluginManifest>(): CogsConnection<Manifest>;
62
+ export declare function useCogsConnection<Manifest extends CogsPluginManifest>(customConnection?: CogsConnection<Manifest>): CogsConnection<Manifest>;
63
63
  /**
64
64
  * Get the audio player from `<CogsConnectionProvider audioPlayer>`
65
65
  */
66
- export declare function useAudioPlayer<Manifest extends CogsPluginManifest>(): CogsAudioPlayer | null;
66
+ export declare function useAudioPlayer<Manifest extends CogsPluginManifest>(customAudioPlayer?: CogsAudioPlayer): CogsAudioPlayer | null;
67
67
  /**
68
68
  * Get the video player from `<CogsConnectionProvider videoPlayer>`
69
69
  */
70
- export declare function useVideoPlayer<Manifest extends CogsPluginManifest>(): CogsVideoPlayer | null;
70
+ export declare function useVideoPlayer<Manifest extends CogsPluginManifest>(customVideoPlayer?: CogsVideoPlayer): CogsVideoPlayer | null;
@@ -27,14 +27,23 @@ exports.useVideoPlayer = exports.useAudioPlayer = exports.useCogsConnection = vo
27
27
  const cogs_client_1 = require("@clockworkdog/cogs-client");
28
28
  const react_1 = __importStar(require("react"));
29
29
  const CogsConnectionContext = react_1.default.createContext({
30
- useCogsConnection: () => {
31
- throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
30
+ useCogsConnection: (customConnection) => {
31
+ if (!customConnection) {
32
+ throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
33
+ }
34
+ return customConnection;
32
35
  },
33
- useAudioPlayer: () => {
34
- throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
36
+ useAudioPlayer: (customAudioPlayer) => {
37
+ if (!customAudioPlayer) {
38
+ throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
39
+ }
40
+ return customAudioPlayer;
35
41
  },
36
- useVideoPlayer: () => {
37
- throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
42
+ useVideoPlayer: (customVideoPlayer) => {
43
+ if (!customVideoPlayer) {
44
+ throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
45
+ }
46
+ return customVideoPlayer;
38
47
  },
39
48
  });
40
49
  /**
@@ -115,9 +124,9 @@ function CogsConnectionProvider({ manifest, hostname, port, children, audioPlaye
115
124
  }
116
125
  const value = {
117
126
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
- useCogsConnection: () => connectionRef.current,
119
- useAudioPlayer: () => { var _a; return (_a = audioPlayerRef.current) !== null && _a !== void 0 ? _a : null; },
120
- useVideoPlayer: () => { var _a; return (_a = videoPlayerRef.current) !== null && _a !== void 0 ? _a : null; },
127
+ useCogsConnection: (customConnection) => customConnection !== null && customConnection !== void 0 ? customConnection : connectionRef.current,
128
+ useAudioPlayer: (customAudioPlayer) => { var _a; return (_a = customAudioPlayer !== null && customAudioPlayer !== void 0 ? customAudioPlayer : audioPlayerRef.current) !== null && _a !== void 0 ? _a : null; },
129
+ useVideoPlayer: (customVideoPlayer) => { var _a; return (_a = customVideoPlayer !== null && customVideoPlayer !== void 0 ? customVideoPlayer : videoPlayerRef.current) !== null && _a !== void 0 ? _a : null; },
121
130
  };
122
131
  return react_1.default.createElement(CogsConnectionContext.Provider, { value: value }, children);
123
132
  }
@@ -125,21 +134,21 @@ exports.default = CogsConnectionProvider;
125
134
  /**
126
135
  * Get the connection from `<CogsConnectionProvider>`
127
136
  */
128
- function useCogsConnection() {
129
- return (0, react_1.useContext)(CogsConnectionContext).useCogsConnection();
137
+ function useCogsConnection(customConnection) {
138
+ return (0, react_1.useContext)(CogsConnectionContext).useCogsConnection(customConnection);
130
139
  }
131
140
  exports.useCogsConnection = useCogsConnection;
132
141
  /**
133
142
  * Get the audio player from `<CogsConnectionProvider audioPlayer>`
134
143
  */
135
- function useAudioPlayer() {
136
- return (0, react_1.useContext)(CogsConnectionContext).useAudioPlayer();
144
+ function useAudioPlayer(customAudioPlayer) {
145
+ return (0, react_1.useContext)(CogsConnectionContext).useAudioPlayer(customAudioPlayer);
137
146
  }
138
147
  exports.useAudioPlayer = useAudioPlayer;
139
148
  /**
140
149
  * Get the video player from `<CogsConnectionProvider videoPlayer>`
141
150
  */
142
- function useVideoPlayer() {
143
- return (0, react_1.useContext)(CogsConnectionContext).useVideoPlayer();
151
+ function useVideoPlayer(customVideoPlayer) {
152
+ return (0, react_1.useContext)(CogsConnectionContext).useVideoPlayer(customVideoPlayer);
144
153
  }
145
154
  exports.useVideoPlayer = useVideoPlayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clockworkdog/cogs-client-react",
3
- "version": "v2.1.2",
3
+ "version": "v2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",