Skip to content

Commit

Permalink
Server updates
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-karlsson committed Apr 19, 2024
1 parent 6960792 commit 32dd360
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
22 changes: 19 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ io.on("connection", (socket) => {
//A rolling index of the message number, so that audio can be played in the right order etc.
const message_index = conversation.length - 1;

socket.emit("conversation_update", conversation);
// TEST: Emit only one message instead of whole conversation
// socket.emit("conversation_update", conversation);

console.log("emitting message:", completion.id);

socket.emit("conversation_update", {
id: completion.id,
speaker: chair.name,
text: response,
});

//This is an async function, and since we are not waiting for the response, it will run in a paralell thread.
//The result will be emitted to the socket when it's ready
Expand All @@ -147,7 +156,11 @@ io.on("connection", (socket) => {
// message.type = 'human';
message.id = "human-" + conversationCounter + "-" + conversation.length;
conversation.push(message);
socket.emit("conversation_update", conversation);

// TEST: Emit only one message instead of whole conversation
// socket.emit("conversation_update", conversation);
socket.emit("conversation_update", message);

//Don't read human messages for now
//Otherwise, generate audio here
socket.emit("audio_update", {
Expand Down Expand Up @@ -212,6 +225,7 @@ io.on("connection", (socket) => {
trimmed: trimmed,
pretrimmed: pretrimmed,
};

//If a character has completely answered for someone else, skip it, and go to the next
if (response == "") {
message.type = "skipped";
Expand All @@ -224,7 +238,9 @@ io.on("connection", (socket) => {
//A rolling index of the message number, so that audio can be played in the right order etc.
const message_index = conversation.length - 1;

socket.emit("conversation_update", conversation);
// TEST: Emit only one message instead of whole conversation
// socket.emit("conversation_update", conversation);
socket.emit("conversation_update", message);

//This is an async function, and since we are not waiting for the response, it will run in a paralell thread.
//The result will be emitted to the socket when it's ready
Expand Down
23 changes: 20 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ io.on("connection", (socket) => {
//A rolling index of the message number, so that audio can be played in the right order etc.
const message_index = conversation.length - 1;

socket.emit("conversation_update", conversation);
// TEST: Emit only one message instead of the whole conversation
// socket.emit("conversation_update", conversation);
socket.emit("conversation_update", {
id: completion.id,
speaker: chair.name,
text: response,
});

//This is an async function, and since we are not waiting for the response, it will run in a paralell thread.
//The result will be emitted to the socket when it's ready
Expand All @@ -147,7 +153,11 @@ io.on("connection", (socket) => {
// message.type = 'human';
message.id = "human-" + conversationCounter + "-" + conversation.length;
conversation.push(message);
socket.emit("conversation_update", conversation);

// TEST: Emit only one message instead of the whole conversation
// socket.emit("conversation_update", conversation);
socket.emit("conversation_update", message);

//Don't read human messages for now
//Otherwise, generate audio here
socket.emit("audio_update", {
Expand Down Expand Up @@ -216,7 +226,14 @@ io.on("connection", (socket) => {
//A rolling index of the message number, so that audio can be played in the right order etc.
const message_index = conversation.length - 1;

socket.emit("conversation_update", conversation);
// TEST: Emit only one message instead of the whole conversation
// socket.emit("conversation_update", conversation);
socket.emit("conversation_update", {
id: id,
speaker: characters[currentSpeaker].name,
text: response,
trimmed: trimmed,
});

//This is an async function, and since we are not waiting for the response, it will run in a paralell thread.
//The result will be emitted to the socket when it's ready
Expand Down

0 comments on commit 32dd360

Please sign in to comment.