@clockworkdog/cogs-client-react 3.0.0-alpha.5 → 3.0.0-alpha.7

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.
@@ -0,0 +1,6 @@
1
+ import { CogsConnection } from '@clockworkdog/cogs-client';
2
+ import React from 'react';
3
+ export interface MediaSurfaceProps {
4
+ cogsConnection: CogsConnection<any, any>;
5
+ }
6
+ export declare function MediaSurface({ cogsConnection }: MediaSurfaceProps): React.JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { SurfaceManager } from '@clockworkdog/cogs-client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ export function MediaSurface({ cogsConnection }) {
4
+ const surfaceManagerRef = useRef(undefined);
5
+ const surfaceStateRef = useRef(undefined);
6
+ const [surfaceElem, setSurfaceElem] = useState();
7
+ // Create and attach new surface manager
8
+ useEffect(() => {
9
+ const sm = new SurfaceManager(cogsConnection.getAssetUrl);
10
+ surfaceManagerRef.current = sm;
11
+ surfaceElem?.replaceChildren(sm.element);
12
+ return () => {
13
+ surfaceManagerRef.current?.setState({});
14
+ surfaceManagerRef.current = undefined;
15
+ surfaceElem?.replaceChildren( /* empty */);
16
+ };
17
+ }, [surfaceElem, cogsConnection.getAssetUrl]);
18
+ // Listen to messages
19
+ useEffect(() => {
20
+ function updateSurfaceState({ message }) {
21
+ if (message.type === 'media_state' && message.media_strategy === 'state' && surfaceManagerRef.current) {
22
+ surfaceStateRef.current = message.state;
23
+ surfaceManagerRef.current.setState(message.state);
24
+ }
25
+ }
26
+ cogsConnection.addEventListener('message', updateSurfaceState);
27
+ return () => cogsConnection.removeEventListener('message', updateSurfaceState);
28
+ }, [cogsConnection]);
29
+ return React.createElement("div", { className: "media-surface", ref: setSurfaceElem });
30
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as CogsConnectionProvider, useCogsConnection, useAudioPlayer, useVideoPlayer } from './providers/CogsConnectionProvider';
2
+ export { MediaSurface, MediaSurfaceProps } from './components/MediaSurface';
2
3
  export { default as useIsConnected } from './hooks/useIsConnected';
3
4
  export { default as useCogsConfig } from './hooks/useCogsConfig';
4
5
  export { default as useCogsEvent } from './hooks/useCogsEvent';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Utilities
2
2
  export { default as CogsConnectionProvider, useCogsConnection, useAudioPlayer, useVideoPlayer } from './providers/CogsConnectionProvider';
3
+ export { MediaSurface } from './components/MediaSurface';
3
4
  export { default as useIsConnected } from './hooks/useIsConnected';
4
5
  export { default as useCogsConfig } from './hooks/useCogsConfig';
5
6
  export { default as useCogsEvent } from './hooks/useCogsEvent';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React components and hooks to connect to COGS to build a custom Media Master",
4
4
  "author": "Clockwork Dog <info@clockwork.dog>",
5
5
  "homepage": "https://github.com/clockwork-dog/cogs-sdk/tree/main/packages/react",
6
- "version": "3.0.0-alpha.5",
6
+ "version": "3.0.0-alpha.7",
7
7
  "keywords": [],
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "prerelease": "yarn npm publish --access public --tag=next"
29
29
  },
30
30
  "dependencies": {
31
- "@clockworkdog/cogs-client": "^3.0.0-alpha.5"
31
+ "@clockworkdog/cogs-client": "^3.0.0-alpha.7"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^18.0.0 || ^19.0.0",