Recent searches
No recent searches
Zendesk ZAFClient API stream(스트리밍) 기능 문의
Posted Mar 17, 2025
안녕하세요. 현재 타 API 에서 stream 으로 연속해서 단어를 보내주는 API 가 있습니다.
파이썬에서는 연속으로 받는 것을 확인하였고 api 상 문제가 없으나
zendesk 쪽에서 받을려고 하니 에러가 납니다 .
밑에 코드가 stream 을 처리하는 코드인데 어떻게 처리하면 되는지 알수 있을까요?
error code : net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
var client = ZAFClient.init();
// 스트리밍 데이터 처리
async function processStream(id) {
const url = streamUrlBase + id;
// Zendesk 프록시를 통해 요청을 보내는 방법
client.request({
url: url,
type: 'GET',
//dataType: 'text',
//async: true,
//processData: true,
cors: false, // 프록시 서버를 통해 요청
timeout: 30000, // timeout을 0으로 설정하여 무제한으로 설정
success: function(data) {
// 데이터 처리 로직
processStreamData(data);
},
error: function(xhr, status, error) {
console.error('Fetch error:', error);
}
});
}
function processStreamData(data) {
const lines = data.split('\n');
let lastLineTime = new Date().getTime();
function processLine(line) {
if (line.startsWith('data: ')) {
const text = line.substring(6);
if (text.includes("[줄바꿈]")) {
//document.getElementById('output').innerHTML += text.replace("[줄바꿈]", "<br>");
console.log(text.replace("[줄바꿈]", "\n"));
} else {
//document.getElementById('output').innerHTML += text;
console.log(text);
}
lastLineTime = new Date().getTime();
}
}
for (const line of lines) {
if (line) {
console.log('=======line======');
console.log(line);
processLine(line);
}
}
// 10초 동안 새로운 줄이 없으면 종료
if (new Date().getTime() - lastLineTime > 10000) {
console.log('Timeout occurred.');
}
}
0
0 comments