对不起我的英语,我在互联网上得到了这段代码并试图修改它,它可以工作但没有条件,我希望如果你在通话中不要执行演示停止命令,如果有人离开了如果正在通话,请不要停止演示。我看到下面的代码有很多废话,如果你知道改进并且可以帮助我,我将非常感谢我对xapi和语言的了解几乎为零...... =(
import xapi from 'xapi';
const maxPeople = 1; //Not to exceed occupancy for this room
const everyMinute = 10 * 1000; // In milliseconds
var emptyRoomPresentationMinuteCount = 0;
function init() {
xapi.config.set('RoomAnalytics PeopleCountOutOfCall', 'On')
.catch((error) => { console.error(error); });
console.log('RoomAnalytics PeopleCountOutOfCall Has been Enabled');
}
xapi.event.on('Conference Presentation LocalInstance 1 SendingMode: LocalOnly', (event) => {
// start checking
var timerId = setTimeout(check_presentation, everyMinute);
});
xapi.event.on('Conference Presentation LocalInstance 1 (ghost=True)', (event) => {
// stop checking
clearTimeout(timerId);
});
xapi.event.on('RoomAnalytics PeopleCount', (event) => {
if (event.Current > 0) {
emptyRoomPresentationMinuteCount = 0; // reset since we saw a face
}
});
xapi.event.on('RoomAnalytics PeoplePresence', (event) => {
if (event === 'Yes') {
emptyRoomPresentationMinuteCount = 0; // reset since we heard a person
}
});
function checkPeopleCount(people) {
if (people < 1 && callCount < 1) xapi.command('Standby Activate');
}
function checkInCall(calls) {
if (calls < 1) xapi.status.get('RoomAnalytics PeopleCount Current')
.then(checkPeopleCount)
.catch(console.error);
console.log(`Em call : , ${calls}`);
};
xapi.status.get('SystemUnit State NumberOfActiveCalls')
.then(checkInCall)
.catch(console.error);
function check_presentation() {
const p1 = xapi.status.get('RoomAnalytics PeopleCount Current', checkPeopleCount)
.catch(console.log);
const p2 = xapi.status.get('SystemUnit State NumberOfActiveCalls')
.catch(console.log);
//console.log(`ppppp222 ${p2}`);
Promise.all([p1, p2]).then(results => {
const peopleCount = results[0];
const callCount = results[1];
//if (peopleCount < 1 && callCount < 1) xapi.command('Presentation Stop');
if (everyMinute > 2 ) tempo();
});
}
function tempo(){ var timerId = setTimeout(stop1, everyMinute);}
function stoptempo(){clearTimeout(everyMinute);}
function stop1() {xapi.command('Presentation Stop')}
function checkCount(count) {
if (count < 1) {
check_presentation()
console.log('*** There are too many people in the room. ',count)
}
else
{
if (count > 0 ) {stoptempo();
//xapi.command('Presentation Start')
}
console.log(`*** Quantas pessoas na sala: ${count}`)
// xapi.command('Presentation Start')
// Se tiver uma pessoa na sala ou mais ativa compartilhamento de conteudo se a video não estiver em standby
}
}
//Run init function to setup prerequisite configurations
init();
// Fetch current count and set feedback for change in peoplecount
xapi.status
.get('RoomAnalytics PeopleCount')
.then((count) => {
console.log('Max occupancy for this room is: ' + maxPeople);
console.log(`Initial people count is: ${count.Current}`);
checkCount(count.Current);
// Listen to events
console.log('Adding feedback listener to: RoomAnalytics PeopleCount');
console.log('feedback : ', emptyRoomPresentationMinuteCount);
//console.log(`Em call feedback: , ${}`);
xapi.feedback.on('/Status/RoomAnalytics/PeopleCount', (count) => {
checkCount(count.Current);
console.log(`Updated count to: ${count.Current}`);
});
})
.catch((err) => {
console.log(`Failed to fetch PeopleCount, err: ${err.message}`);
console.log(`Are you interacting with a Room Series? exiting...`);
xapi.close();
});