-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcisco_device_macro_code.js
More file actions
63 lines (51 loc) · 1.95 KB
/
Copy pathcisco_device_macro_code.js
File metadata and controls
63 lines (51 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import xapi from 'xapi';
const BASE_URL = "챗봇 서버 주소";
const INTERVAL = 1000;
let previousCount = 0;
function postToEndpoint(endpoint, data = {}) {
const payload = {
Url: `${BASE_URL}${endpoint}`,
Header: ['Content-Type: application/json'],
AllowInsecureHTTPS: true,
};
const body = JSON.stringify(data);
console.log(`[전송 시도] ${endpoint}로 요청:`, body);
xapi.command('HttpClient Post', payload, body)
.then(() => {
console.log(`[전송 성공] ${endpoint}`);
})
.catch(err => {
console.error(`[전송 실패] ${endpoint} 오류 발생`);
console.error('━━━━━━━━━━━━━━━━━━━━━━━');
if (err.message) console.error('메시지:', err.message);
if (err.code !== undefined) console.error('오류 코드:', err.code);
if (err.stack) console.error('스택:', err.stack);
if (err.data) {
console.error('요청 데이터 정보:', JSON.stringify(err.data, null, 2));
}
console.error('━━━━━━━━━━━━━━━━━━━━━━━');
});
}
function checkPeopleCount() {
xapi.status.get('RoomAnalytics/PeopleCount/Current')
.then(count => {
const currentCount = parseInt(count);
if (isNaN(currentCount)) {
console.warn('[카운트 없음 또는 감지 안됨]');
return;
}
console.log('[현재 감지된 인원 수]:', currentCount);
// 상태 변화 감지
if (previousCount <= 0 && currentCount > 0) {
// 인원이 처음 감지됨
postToEndpoint('/sessionStart', { count: currentCount });
} else if (previousCount > 0 && currentCount === 0) {
// 모든 인원이 사라짐
postToEndpoint('/sessionReset');
}
previousCount = currentCount;
})
.catch(err => console.error('[카운트 조회 실패]', err.message));
}
// 주기적으로 감지
setInterval(checkPeopleCount, INTERVAL);