@solo3li/client-react 1.0.1 → 1.0.2
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.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +56 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,3 +10,11 @@ export declare const useOmniAgent: (options: OmniAgentOptions) => {
|
|
|
10
10
|
isAgentSpeaking: boolean;
|
|
11
11
|
disconnect: () => void;
|
|
12
12
|
};
|
|
13
|
+
export declare const useHumanAgent: (options: {
|
|
14
|
+
token: string;
|
|
15
|
+
livekitUrl: string;
|
|
16
|
+
}) => {
|
|
17
|
+
isConnected: boolean;
|
|
18
|
+
isCustomerSpeaking: boolean;
|
|
19
|
+
disconnect: () => void;
|
|
20
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -59,3 +59,59 @@ export const useOmniAgent = (options) => {
|
|
|
59
59
|
disconnect
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
|
+
export const useHumanAgent = (options) => {
|
|
63
|
+
const [room, setRoom] = useState(null);
|
|
64
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
65
|
+
const [isCustomerSpeaking, setIsCustomerSpeaking] = useState(false);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!options.token || !options.livekitUrl)
|
|
68
|
+
return;
|
|
69
|
+
const newRoom = new Room({
|
|
70
|
+
adaptiveStream: true,
|
|
71
|
+
dynacast: true,
|
|
72
|
+
});
|
|
73
|
+
newRoom.on(RoomEvent.Connected, () => {
|
|
74
|
+
setIsConnected(true);
|
|
75
|
+
});
|
|
76
|
+
newRoom.on(RoomEvent.Disconnected, () => {
|
|
77
|
+
setIsConnected(false);
|
|
78
|
+
});
|
|
79
|
+
newRoom.on(RoomEvent.ActiveSpeakersChanged, (speakers) => {
|
|
80
|
+
// Anyone who is not the local participant is assumed to be the customer
|
|
81
|
+
const customerSpeaking = speakers.some(s => s.identity !== newRoom.localParticipant.identity);
|
|
82
|
+
setIsCustomerSpeaking(customerSpeaking);
|
|
83
|
+
});
|
|
84
|
+
newRoom.on(RoomEvent.TrackSubscribed, (track) => {
|
|
85
|
+
if (track.kind === Track.Kind.Audio) {
|
|
86
|
+
const element = track.attach();
|
|
87
|
+
document.body.appendChild(element);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const connect = async () => {
|
|
91
|
+
try {
|
|
92
|
+
await newRoom.connect(options.livekitUrl, options.token);
|
|
93
|
+
await newRoom.localParticipant.enableCameraAndMicrophone();
|
|
94
|
+
setRoom(newRoom);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error('Failed to connect Human Agent:', error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
connect();
|
|
101
|
+
return () => {
|
|
102
|
+
newRoom.disconnect();
|
|
103
|
+
};
|
|
104
|
+
}, [options.token, options.livekitUrl]);
|
|
105
|
+
const disconnect = () => {
|
|
106
|
+
if (room) {
|
|
107
|
+
room.disconnect();
|
|
108
|
+
setRoom(null);
|
|
109
|
+
setIsConnected(false);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
isConnected,
|
|
114
|
+
isCustomerSpeaking,
|
|
115
|
+
disconnect
|
|
116
|
+
};
|
|
117
|
+
};
|