From bee0b4b6ad325656ed3e1023319144fb043d18b6 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Fri, 25 Sep 2020 08:23:32 +0000 Subject: [PATCH] [FIX] website_jitsi: fix participant count update Bug === When we implemented `website_jitsi` we didn't need to enter a pseudo. Users automatically joined the room. But now we have one more step about entering Jitsi username. During this step the room can become full so we need to check one more time if room reached its full capacity. Correctly use the option `check_full` in `website_event_track_exhibitor`. Do not wait for participant update if the room become full. Task ID-2345894 PR #58516 X-original-commit: 4aae31a7497b9f80b3c3f3d63a22bde646e09f0b --- .../views/event_meet_templates_page.xml | 3 ++- .../views/event_exhibitor_templates_page.xml | 3 ++- .../website_jitsi/static/src/js/chat_room.js | 21 +++++++++++++------ .../views/chat_room_templates.xml | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/addons/website_event_meet/views/event_meet_templates_page.xml b/addons/website_event_meet/views/event_meet_templates_page.xml index 7d0a4319cc3..c885c2e7e60 100644 --- a/addons/website_event_meet/views/event_meet_templates_page.xml +++ b/addons/website_event_meet/views/event_meet_templates_page.xml @@ -64,7 +64,8 @@ - + + diff --git a/addons/website_event_track_exhibitor/views/event_exhibitor_templates_page.xml b/addons/website_event_track_exhibitor/views/event_exhibitor_templates_page.xml index bf8b4664329..48a637aa874 100644 --- a/addons/website_event_track_exhibitor/views/event_exhibitor_templates_page.xml +++ b/addons/website_event_track_exhibitor/views/event_exhibitor_templates_page.xml @@ -73,7 +73,8 @@ - + + diff --git a/addons/website_jitsi/static/src/js/chat_room.js b/addons/website_jitsi/static/src/js/chat_room.js index df29af0329e..371438adf8a 100644 --- a/addons/website_jitsi/static/src/js/chat_room.js +++ b/addons/website_jitsi/static/src/js/chat_room.js @@ -44,6 +44,8 @@ publicWidget.registry.ChatRoom = publicWidget.Widget.extend({ this.jitsiServer = this.$el.data('jitsi-server') || 'meet.jit.si'; + this.maxCapacity = parseInt(this.$el.data('max-capacity')) || Infinity; + if (this.autoOpen) { await this._onChatRoomClick(); } @@ -70,11 +72,7 @@ publicWidget.registry.ChatRoom = publicWidget.Widget.extend({ }); if (isChatRoomFull) { - Dialog.alert(this, _t("Sorry, this room is full"), { - title: _t("Warning"), - // reload the page to refresh the participant count - confirm_callback: () => window.location.reload(), - }); + window.location.reload(); return; } } @@ -166,6 +164,10 @@ publicWidget.registry.ChatRoom = publicWidget.Widget.extend({ let timeoutCall = null; const updateParticipantCount = (joined) => { + this.allParticipantIds = Object.keys(jitsiRoom._participants).sort(); + // if we reached the maximum capacity, update immediately the participant count + const timeoutTime = this.allParticipantIds.length >= this.maxCapacity ? 0 : 2000; + // we clear the old timeout to be sure to call it only once each 2 seconds // (so if 2 participants join/leave in this interval, we will perform only // one HTTP request for both). @@ -177,7 +179,7 @@ publicWidget.registry.ChatRoom = publicWidget.Widget.extend({ // count so we avoid to send to many HTTP requests this._updateParticipantCount(this.allParticipantIds.length, joined); } - }, 2000); + }, timeoutTime); }; jitsiRoom.addEventListener('participantJoined', () => updateParticipantCount(true)); @@ -188,6 +190,13 @@ publicWidget.registry.ChatRoom = publicWidget.Widget.extend({ this.participantId = event.id; updateParticipantCount(true); $('.o_wjitsi_chat_room_loading').addClass('d-none'); + + // recheck if the room is not full + if (this.checkFull && this.allParticipantIds.length > this.maxCapacity) { + clearTimeout(timeoutCall); + jitsiRoom.executeCommand('hangup'); + window.location.reload(); + } }); return jitsiRoom; diff --git a/addons/website_jitsi/views/chat_room_templates.xml b/addons/website_jitsi/views/chat_room_templates.xml index 6d9386cf6bb..f733efa64fc 100644 --- a/addons/website_jitsi/views/chat_room_templates.xml +++ b/addons/website_jitsi/views/chat_room_templates.xml @@ -9,6 +9,7 @@ t-att-data-check-full="check_full" t-att-data-attach-to="attach_to" t-att-data-default-username="default_username" + t-att-data-max-capacity="max_capacity" t-att-data-jitsi-server="jitsi_server_domain">