Skip to content

Commit 670ec3d

Browse files
committed
openvidu-speech-to-text: allow multiple rooms at the same time
1 parent 2c6c038 commit 670ec3d

File tree

1 file changed

+8
-3
lines changed
  • openvidu-agents/openvidu-speech-to-text/src

1 file changed

+8
-3
lines changed

openvidu-agents/openvidu-speech-to-text/src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ app.post("/token", async (req, res) => {
4747
return res.json({ token });
4848
});
4949

50-
// Store the agent dispatch ID to stop transcription
51-
var agentDispatchId;
50+
// Store agent dispatch IDs to stop transcriptions
51+
var agentDispatchIds = new Map();
5252

5353
// Start the agent dispatch for STT
5454
app.post("/stt", async (req, res) => {
@@ -59,7 +59,7 @@ app.post("/stt", async (req, res) => {
5959
roomName,
6060
AGENT_NAME
6161
);
62-
agentDispatchId = agentDispatch.id;
62+
agentDispatchIds.set(roomName, agentDispatch.id);
6363
return res.json({ agentDispatch });
6464
} catch (error) {
6565
console.error("Error creating agent dispatch", error);
@@ -71,7 +71,12 @@ app.post("/stt", async (req, res) => {
7171
app.delete("/stt", async (req, res) => {
7272
const { roomName } = req.body;
7373
try {
74+
const agentDispatchId = agentDispatchIds.get(roomName);
75+
if (!agentDispatchId) {
76+
return res.status(404).send("Agent dispatch not found");
77+
}
7478
await agentDispatchClient.deleteDispatch(agentDispatchId, roomName);
79+
agentDispatchIds.delete(roomName);
7580
return res.status(200).send();
7681
} catch (error) {
7782
console.error("Error deleting agent dispatch", error);

0 commit comments

Comments
 (0)