1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * JS actions for the rooms page for mod_bigbluebuttonbn.
19 * @module mod_bigbluebuttonbn/rooms
20 * @copyright 2021 Blindside Networks Inc
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 import * as repository from './repository';
26 import * as roomUpdater from './roomupdater';
28 exception as displayException,
30 } from 'core/notification';
31 import Pending from 'core/pending';
32 import {getString} from 'core/str';
33 import {add as addToast} from 'core/toast';
34 import {eventTypes, notifyCurrentSessionEnded} from './events';
39 * @param {Number} bigbluebuttonbnid bigblubeutton identifier
40 * @param {Number} pollInterval poll interval in miliseconds
42 export const init = (bigbluebuttonbnid, pollInterval) => {
43 const completionElement = document.querySelector('a[href*=completion_validate]');
44 if (completionElement) {
45 completionElement.addEventListener("click", event => {
46 event.preventDefault();
48 const pendingPromise = new Pending('mod_bigbluebuttonbn/completion:validate');
50 repository.completionValidate(bigbluebuttonbnid)
51 .then(() => getString('completionvalidatestatetriggered', 'mod_bigbluebuttonbn'))
52 .then(str => addToast(str))
53 .then(() => pendingPromise.resolve())
54 .catch(displayException);
58 document.addEventListener('click', e => {
59 const joinButton = e.target.closest('[data-action="join"]');
61 window.open(joinButton.href, 'bigbluebutton_conference');
63 // Gives the user a bit of time to go into the meeting before polling the room.
65 roomUpdater.updateRoom(true);
70 document.addEventListener(eventTypes.sessionEnded, () => {
72 roomUpdater.updateRoom();
76 window.addEventListener(eventTypes.currentSessionEnded, () => {
78 roomUpdater.updateRoom();
82 roomUpdater.start(pollInterval);
86 * Auto close child windows when clicking the End meeting button.
87 * @param {Number} closeDelay time to wait in miliseconds before closing the window
89 export const setupWindowAutoClose = (closeDelay = 2000) => {
90 notifyCurrentSessionEnded(window.opener);
91 window.addEventListener('onbeforeunload', () => {
92 window.opener.setTimeout(() => {
93 roomUpdater.updateRoom(true);
99 window.close(); // This does not work as scripts can only close windows that are opened by themselves.