Skip to content

Commit 808bfdd

Browse files
authored
Merge branch 'main' into add-mute-functionality
2 parents 109d3a2 + e7f785a commit 808bfdd

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Layercode React SDK
22

3-
A React SDK for integrating Layercode audio pipelines into React applications.
3+
A React SDK for integrating Layercode audio agents into React applications.
44

55
## Installation
66

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Layercode",
33
"license": "MIT",
44
"name": "@layercode/react-sdk",
5-
"version": "1.0.29",
5+
"version": "2.0.4",
66
"description": "Layercode React SDK for integrating with React applications",
77
"type": "module",
88
"main": "./dist/index.js",
@@ -33,7 +33,7 @@
3333
"react"
3434
],
3535
"dependencies": {
36-
"@layercode/js-sdk": "^1.0.26"
36+
"@layercode/js-sdk": "^2.0.4"
3737
},
3838
"peerDependencies": {
3939
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"

src/index.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@ import { useState, useEffect, useCallback, useRef } from 'react';
22
import LayercodeClient from '@layercode/js-sdk';
33

44
/**
5-
* Configuration options for the useLayercodePipeline hook.
5+
* Configuration options for the useLayercodeAgent hook.
66
*/
7-
interface UseLayercodePipelineOptions {
8-
pipelineId: string;
9-
sessionId?: string;
7+
interface UseLayercodeAgentOptions {
8+
agentId: string;
9+
conversationId?: string;
1010
authorizeSessionEndpoint: string;
1111
metadata?: Record<string, any>;
12-
onConnect?: ({ sessionId }: { sessionId: string | null }) => void;
12+
onConnect?: ({ conversationId }: { conversationId: string | null }) => void;
1313
onDisconnect?: () => void;
1414
onError?: (error: Error) => void;
1515
onDataMessage?: (data: any) => void;
1616
onMuteStateChange?: (isMuted: boolean) => void;
17+
onMessage?: (data: any) => void;
1718
}
1819

1920
/**
20-
* Hook for connecting to a Layercode pipeline in a React application
21+
* Hook for connecting to a Layercode agent in a React application
2122
*
22-
* @param options - Configuration options for the pipeline
23-
* @returns An object containing methods and state for interacting with the pipeline
23+
* @param options - Configuration options for the agent
24+
* @returns An object containing methods and state for interacting with the agent
2425
*/
25-
const useLayercodePipeline = (
26+
const useLayercodeAgent = (
2627
// Accept the public options plus any other properties (for internal use)
27-
options: UseLayercodePipelineOptions & Record<string, any>
28+
options: UseLayercodeAgentOptions & Record<string, any>
2829
) => {
2930
// Extract public options
30-
const { pipelineId, sessionId, authorizeSessionEndpoint, metadata = {}, onConnect, onDisconnect, onError, onDataMessage, onMuteStateChange } = options;
31+
const { agentId, conversationId, authorizeSessionEndpoint, metadata = {}, onConnect, onDisconnect, onError, onDataMessage, onMessage, onMuteStateChange } = options;
3132

3233
const [status, setStatus] = useState('initializing');
3334
const [userAudioAmplitude, setUserAudioAmplitude] = useState(0);
@@ -41,12 +42,12 @@ const useLayercodePipeline = (
4142
// Create a new LayercodeClient instance
4243
console.log('Creating LayercodeClient instance');
4344
clientRef.current = new LayercodeClient({
44-
pipelineId,
45-
sessionId,
45+
agentId,
46+
conversationId,
4647
authorizeSessionEndpoint,
4748
metadata,
48-
onConnect: ({ sessionId }: { sessionId: string | null }) => {
49-
onConnect?.({ sessionId });
49+
onConnect: ({ conversationId }: { conversationId: string | null }) => {
50+
onConnect?.({ conversationId });
5051
},
5152
onDisconnect: () => {
5253
onDisconnect?.();
@@ -57,6 +58,9 @@ const useLayercodePipeline = (
5758
onDataMessage: (data: any) => {
5859
onDataMessage?.(data);
5960
},
61+
onMessage: (data: any) => {
62+
onMessage?.(data);
63+
},
6064
onStatusChange: (newStatus: string) => {
6165
setStatus(newStatus);
6266
},
@@ -79,10 +83,10 @@ const useLayercodePipeline = (
7983

8084
// Set initial mute state from JS SDK
8185
setIsMuted(clientRef.current.isMuted);
82-
83-
// Connect to the pipeline
86+
87+
// Connect to the agent
8488
clientRef.current.connect().catch((error: Error) => {
85-
console.error('Failed to connect to pipeline:', error);
89+
console.error('Failed to connect to agent:', error);
8690
onError?.(error);
8791
});
8892

@@ -93,7 +97,7 @@ const useLayercodePipeline = (
9397
}
9498
};
9599
// Add the internal override URL to the dependency array
96-
}, [pipelineId, sessionId, authorizeSessionEndpoint]); // Make sure metadata isn't causing unnecessary re-renders if it changes often
100+
}, [agentId, conversationId, authorizeSessionEndpoint]); // Make sure metadata isn't causing unnecessary re-renders if it changes often
97101

98102
// Class methods
99103
const mute = useCallback(() => {
@@ -135,4 +139,4 @@ const useLayercodePipeline = (
135139
};
136140
};
137141

138-
export { useLayercodePipeline, UseLayercodePipelineOptions }; // Export the type too
142+
export { useLayercodeAgent, UseLayercodeAgentOptions }; // Export the type too

0 commit comments

Comments
 (0)