Skip to content

Commit 7aacb67

Browse files
committed
fix: 클라이언트 수정
1 parent 0e2492a commit 7aacb67

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

test-clients/test-client.html

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,37 @@
217217
}
218218

219219
function playNextAudio() {
220+
console.log("playNextAudio 호출:", {
221+
queueLength: audioQueue.length,
222+
isPlayingAudio: isPlayingAudio
223+
});
224+
220225
if (audioQueue.length === 0) {
221226
isPlayingAudio = false;
222227
audioPlayer.style.display = "none";
228+
console.log("오디오 큐가 비어있음");
223229
return;
224230
}
225231
const blob = audioQueue.shift();
232+
console.log("오디오 재생 시작:", {
233+
blobSize: blob.size,
234+
blobType: blob.type
235+
});
236+
226237
audioPlayer.src = URL.createObjectURL(blob);
227238
audioPlayer.style.display = "";
228239
isPlayingAudio = true;
229-
audioPlayer.play();
230-
appendLog(`<i>[오디오 재생]</i>`);
240+
241+
const playPromise = audioPlayer.play();
242+
if (playPromise !== undefined) {
243+
playPromise.then(() => {
244+
console.log("오디오 재생 성공");
245+
appendLog(`<i>[오디오 재생]</i>`);
246+
}).catch(error => {
247+
console.error("오디오 재생 실패:", error);
248+
appendLog(`<i>[오디오 재생 실패: ${error.message}]</i>`);
249+
});
250+
}
231251
}
232252

233253
audioPlayer.onended = () => playNextAudio();
@@ -258,7 +278,7 @@
258278
console.log(`메시지 타입: ${data.type}`);
259279

260280
// 세션 ID 처리
261-
if (data.type === "session_id") {
281+
if (data.type === "session" || data.type === "session_id") {
262282
sessionId = data.data.session_id;
263283
appendLog(`<b>[세션 ID: ${sessionId}]</b>`);
264284
return;
@@ -274,17 +294,33 @@
274294
messageText += `<b>AI:</b> ${chatData.text}`;
275295
}
276296

277-
// 오디오 데이터가 있는 경우
278-
if (chatData.audioData) {
297+
// 오디오 데이터가 있는 경우
298+
if (chatData.audio_data) {
279299
try {
300+
console.log("오디오 데이터 수신:", {
301+
audioDataLength: chatData.audio_data.length,
302+
audioFormat: chatData.audio_format,
303+
hasAudioData: !!chatData.audio_data
304+
});
305+
280306
// Base64 디코딩
281-
const audioBytes = atob(chatData.audioData);
307+
const audioBytes = atob(chatData.audio_data);
282308
const audioArray = new Uint8Array(audioBytes.length);
283309
for (let i = 0; i < audioBytes.length; i++) {
284310
audioArray[i] = audioBytes.charCodeAt(i);
285311
}
286312

287-
const blob = new Blob([audioArray], { type: `audio/${chatData.audioFormat || 'wav'}` });
313+
console.log("오디오 배열 생성:", {
314+
arrayLength: audioArray.length,
315+
blobType: chatData.audio_format || 'audio/wav'
316+
});
317+
318+
const blob = new Blob([audioArray], { type: `audio/${chatData.audio_format || 'wav'}` });
319+
console.log("Blob 생성 완료:", {
320+
blobSize: blob.size,
321+
blobType: blob.type
322+
});
323+
288324
audioQueue.push(blob);
289325
if (!isPlayingAudio) playNextAudio();
290326

@@ -313,7 +349,7 @@
313349
}
314350

315351
// 하위 호환성을 위한 기존 구조 처리
316-
if (data.type === "session_id") {
352+
if (data.type === "session" || data.type === "session_id") {
317353
sessionId = data.session_id;
318354
appendLog(`<b>[세션 ID: ${sessionId}]</b>`);
319355
return;
@@ -328,16 +364,16 @@
328364
}
329365

330366
// 오디오 데이터가 있는 경우
331-
if (data.audioData) {
367+
if (data.audio_data) {
332368
try {
333369
// Base64 디코딩
334-
const audioBytes = atob(data.audioData);
370+
const audioBytes = atob(data.audio_data);
335371
const audioArray = new Uint8Array(audioBytes.length);
336372
for (let i = 0; i < audioBytes.length; i++) {
337373
audioArray[i] = audioBytes.charCodeAt(i);
338374
}
339375

340-
const blob = new Blob([audioArray], { type: `audio/${data.audioFormat || 'wav'}` });
376+
const blob = new Blob([audioArray], { type: data.audio_format || 'audio/wav' });
341377
audioQueue.push(blob);
342378
if (!isPlayingAudio) playNextAudio();
343379

@@ -368,6 +404,11 @@
368404
}
369405
} else if (event.data instanceof ArrayBuffer) {
370406
// 바이너리 메시지 처리
407+
console.log("바이너리 메시지 수신:", {
408+
dataLength: event.data.byteLength,
409+
dataType: typeof event.data
410+
});
411+
371412
try {
372413
// 바이너리 프로토콜 파싱 시도
373414
const result = parseBinaryMessage(event.data);

0 commit comments

Comments
 (0)