[mirotalksfu] - #22 add real-time polls

هذا الالتزام موجود في:
Miroslav Pejic
2024-07-18 08:50:57 +02:00
الأصل 55c7da49cd
التزام e5785538ef
11 ملفات معدلة مع 589 إضافات و6 حذوفات

عرض الملف

@@ -61,6 +61,9 @@ module.exports = class Room {
this.rtmpFileStreamer = null;
this.rtmpUrlStreamer = null;
this.rtmp = config.server.rtmp || false;
// Polls
this.polls = [];
}
// ####################################################
@@ -87,10 +90,30 @@ module.exports = class Room {
survey: this.survey,
redirect: this.redirect,
videoAIEnabled: this.videoAIEnabled,
thereIsPolls: this.thereIsPolls(),
peers: JSON.stringify([...this.peers]),
};
}
// ##############################################
// POLLS
// ##############################################
thereIsPolls() {
return this.polls.length > 0;
}
getPolls() {
return this.polls;
}
convertPolls(polls) {
return polls.map((poll) => {
const voters = poll.voters ? Object.fromEntries(poll.voters.entries()) : {};
return { ...poll, voters };
});
}
// ##############################################
// RTMP from FILE
// ##############################################

عرض الملف

@@ -44,7 +44,7 @@ dependencies: {
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.4.99
* @version 1.5.10
*
*/
@@ -2385,6 +2385,97 @@ function startServer() {
log.debug('endRTMPfromURL - rtmpUrlStreamsCount ---->', rtmpUrlStreamsCount);
});
socket.on('createPoll', (dataObject) => {
if (!roomList.has(socket.room_id)) return;
const data = checkXSS(dataObject);
const { question, options } = data;
const room = roomList.get(socket.room_id);
const newPoll = {
question: question,
options: options,
voters: new Map(),
};
const roomPolls = room.getPolls();
roomPolls.push(newPoll);
room.sendToAll('updatePolls', room.convertPolls(roomPolls));
log.debug('[Poll] createPoll', roomPolls);
});
socket.on('vote', (dataObject) => {
if (!roomList.has(socket.room_id)) return;
const data = checkXSS(dataObject);
const room = roomList.get(socket.room_id);
const roomPolls = room.getPolls();
const poll = roomPolls[data.pollIndex];
if (poll) {
const peer_name = getPeerName(room, false) || socket.id;
poll.voters.set(peer_name, data.option);
room.sendToAll('updatePolls', room.convertPolls(roomPolls));
log.debug('[Poll] vote', roomPolls);
}
});
socket.on('updatePoll', () => {
if (!roomList.has(socket.room_id)) return;
const room = roomList.get(socket.room_id);
const roomPolls = room.getPolls();
if (roomPolls.length > 0) {
room.sendToAll('updatePolls', room.convertPolls(roomPolls));
log.debug('[Poll] updatePoll', roomPolls);
}
});
socket.on('editPoll', (dataObject) => {
if (!roomList.has(socket.room_id)) return;
const data = checkXSS(dataObject);
const { index, question, options } = data;
const room = roomList.get(socket.room_id);
const roomPolls = room.getPolls();
if (roomPolls[index]) {
roomPolls[index].question = question;
roomPolls[index].options = options;
room.sendToAll('updatePolls', roomPolls);
log.debug('[Poll] editPoll', roomPolls);
}
});
socket.on('deletePoll', async (data) => {
if (!roomList.has(socket.room_id)) return;
const { index, peer_name, peer_uuid } = checkXSS(data);
const isPresenter = await isPeerPresenter(socket.room_id, socket.id, peer_name, peer_uuid);
if (!isPresenter) return;
const room = roomList.get(socket.room_id);
const roomPolls = room.getPolls();
if (roomPolls[index]) {
roomPolls.splice(index, 1);
room.sendToAll('updatePolls', roomPolls);
}
});
socket.on('disconnect', async () => {
if (!roomList.has(socket.room_id)) return;

عرض الملف

@@ -355,6 +355,7 @@ module.exports = {
startScreenButton: true,
swapCameraButton: true,
chatButton: true,
pollButton: true,
raiseHandButton: true,
transcriptionButton: true,
whiteboardButton: true,