- 1 :
import { WrapperObject } from '../../mel_metapage/js/lib/BaseObjects/WrapperObject.js';
- 2 :
import { FramesManager } from '../../mel_metapage/js/lib/classes/frame_manager.js';
- 3 :
import { MelObject } from '../../mel_metapage/js/lib/mel_object.js';
- 4 :
import { VisioFunctions } from './lib/helpers.js';
- 5 :
- 6 :
/**
- 7 :
* Contient les classes d'aide pour utiliser ou lancer la visioconférence correctement.
- 8 :
* @module Visio/Helper
- 9 :
* @local BnumVisio
- 10 :
* @local VisioHelper
- 11 :
*/
- 12 :
- 13 :
/**
- 14 :
* @class
- 15 :
* @classdesc Classe d'aide de la visioconférence. Donne des fonctions utile pour appeler ou utiliser la visio
- 16 :
*/
- 17 :
class BnumVisio extends MelObject {
- 18 :
/**
- 19 :
* Contient les fonctions qui permettent de récupérer les codes voxify ou de lancer une visio.
- 20 :
*/
- 21 :
constructor() {
- 22 :
super();
- 23 :
}
- 24 :
- 25 :
/**
- 26 :
*Cette fonction est appelé dans le constructeur.
- 27 :
* @override
- 28 :
*/
- 29 :
main() {
- 30 :
super.main();
- 31 :
- 32 :
this.rcmail().addEventListener('visio.start', (args) => {
- 33 :
const { room: key, workspace: wsp, locks, pass, extra } = args;
- 34 :
- 35 :
this.start({ key, wsp, locks, pass, extra });
- 36 :
});
- 37 :
}
- 38 :
- 39 :
/**
- 40 :
* Récupère l'url de voxify
- 41 :
* @returns {Promise<string>}
- 42 :
* @async
- 43 :
*/
- 44 :
async voxify_url() {
- 45 :
//Si on récupère déjà l'url, ça ne sert à rien de le redemander, on attend la résolution précédente.
- 46 :
if (this.voxify_url.waiting) {
- 47 :
let it = 0;
- 48 :
await new Promise((ok, nok) => {
- 49 :
const interval = setInterval(() => {
- 50 :
console.debug('Waiting voxify url...');
- 51 :
if (!this.voxify_url.waiting) {
- 52 :
clearInterval(interval);
- 53 :
console.debug('Voxify url ok !');
- 54 :
ok();
- 55 :
}
- 56 :
- 57 :
if (++it > 50) {
- 58 :
this.voxify_url.waiting = false;
- 59 :
console.debug('Voxify url not ok !');
- 60 :
nok();
- 61 :
}
- 62 :
}, 100);
- 63 :
});
- 64 :
}
- 65 :
- 66 :
let navigator = top ?? parent ?? window;
- 67 :
- 68 :
if (!navigator.voxify_url) {
- 69 :
this.voxify_url.waiting = true;
- 70 :
console.info('Starting get voxify url !');
- 71 :
await MelObject.Empty().http_internal_get({
- 72 :
task: 'mel_settings',
- 73 :
action: 'get',
- 74 :
params: {
- 75 :
_option: 'voxify_url',
- 76 :
_default_value: 'https://webconf.numerique.gouv.fr/voxapi',
- 77 :
},
- 78 :
on_success(data) {
- 79 :
console.info('Voxify url ok !');
- 80 :
data = JSON.parse(data);
- 81 :
navigator.voxify_url = data;
- 82 :
},
- 83 :
});
- 84 :
console.info('Finishing get voxify url !');
- 85 :
this.voxify_url.waiting = false;
- 86 :
}
- 87 :
- 88 :
return navigator.voxify_url;
- 89 :
}
- 90 :
- 91 :
/**
- 92 :
* Récupère le numéro de téléphone lié à la visioconférence
- 93 :
* @param {string} webconf Room de la visio
- 94 :
* @returns {Promise<string>}
- 95 :
* @async
- 96 :
*/
- 97 :
async getWebconfPhoneNumber(webconf) {
- 98 :
const url = `${await this.voxify_url()}/api/v1/conn/jitsi/phoneNumbers?conference=${webconf}@conference.webconf.numerique.gouv.fr`;
- 99 :
let phoneNumber = null;
- 100 :
window.disable_x_roundcube = true;
- 101 :
- 102 :
await this.http_call({
- 103 :
url,
- 104 :
on_success: (data) => {
- 105 :
const indicator = rcmail.env['mel_metapage.webconf_voxify_indicatif'];
- 106 :
if (
- 107 :
!!data &&
- 108 :
data.numbersEnabled &&
- 109 :
!!data.numbers[indicator] &&
- 110 :
data.numbers[indicator].length > 0
- 111 :
)
- 112 :
phoneNumber = data.numbers[indicator][0];
- 113 :
},
- 114 :
type: 'GET',
- 115 :
});
- 116 :
- 117 :
window.disable_x_roundcube = false;
- 118 :
- 119 :
return phoneNumber;
- 120 :
}
- 121 :
- 122 :
/**
- 123 :
* Récupère le code pin lié à la visio
- 124 :
* @param {string} webconf Room de la visio
- 125 :
* @returns {Promise<?string>}
- 126 :
* @async
- 127 :
*/
- 128 :
async getWebconfPhonePin(webconf) {
- 129 :
const url = `${await this.voxify_url()}/api/v1/conn/jitsi/conference/code?conference=${webconf}@conference.webconf.numerique.gouv.fr`;
- 130 :
let phoneNumber = null;
- 131 :
window.disable_x_roundcube = true;
- 132 :
// await mel_metapage.Functions.get(url, {}, (datas) => {
- 133 :
// if (!!datas && !!datas.id) phoneNumber = datas.id;
- 134 :
// });
- 135 :
await this.http_call({
- 136 :
url,
- 137 :
on_success: (data) => {
- 138 :
if (data?.id) phoneNumber = data.id;
- 139 :
},
- 140 :
type: 'GET',
- 141 :
});
- 142 :
- 143 :
window.disable_x_roundcube = false;
- 144 :
- 145 :
return phoneNumber;
- 146 :
}
- 147 :
- 148 :
/**
- 149 :
* Récupère les données téléphonique de la visio
- 150 :
* @param {string} webconf
- 151 :
* @returns {Promise<{number:string, pin:string, room:string}>}
- 152 :
* @async
- 153 :
*/
- 154 :
async getWebconfPhone(webconf) {
- 155 :
const [number, pin] = await Promise.allSettled([
- 156 :
this.getWebconfPhoneNumber(webconf),
- 157 :
this.getWebconfPhonePin(webconf),
- 158 :
]);
- 159 :
return { number: number.value, pin: pin.value, room: webconf };
- 160 :
}
- 161 :
- 162 :
/**
- 163 :
* Lance une visio
- 164 :
* @param {Object} [options={}]
- 165 :
* @param {?string} [options.key=null] Room de la visio. Si null, ouvre la page de choix de la room.
- 166 :
* @param {?string} [options.wsp=null] Espace de travail rattaché à la visio.
- 167 :
* @param {?string} [options.locks = null] Elements à lock
- 168 :
* @param {?string} [options.pass=null] Mot de passe de la visio
- 169 :
* @param {?string} [options.extra=null] Modes en plus
- 170 :
* @return {void}
- 171 :
*/
- 172 :
start({
- 173 :
key = null,
- 174 :
wsp = null,
- 175 :
locks = null,
- 176 :
pass = null,
- 177 :
extra = null,
- 178 :
} = {}) {
- 179 :
let config = {};
- 180 :
- 181 :
if (key) {
- 182 :
if (key === '¤random¤') key = VisioFunctions.generateWebconfRoomName();
- 183 :
config._key = key;
- 184 :
}
- 185 :
if (wsp) config._wsp = wsp;
- 186 :
if (locks) config._locks = locks;
- 187 :
if (pass) config._pass = pass;
- 188 :
if (extra) config._need_config = extra === 'need_config';
- 189 :
- 190 :
// FramesManager.Instance.start_mode(
- 191 :
// 'visio',
- 192 :
// !key || config._need_config ? null : 'visio',
- 193 :
// config,
- 194 :
// );
- 195 :
this.startVisioMode({
- 196 :
page: !key || config._need_config ? null : 'visio',
- 197 :
params: config,
- 198 :
});
- 199 :
}
- 200 :
- 201 :
async startVisioMode({ page = 'index', params = {} } = {}) {
- 202 :
if (!page) {
- 203 :
if (params) params._page = 'index';
- 204 :
- 205 :
await FramesManager.Instance.switch_frame('webconf', {
- 206 :
args: params ?? { _page: 'index' },
- 207 :
});
- 208 :
} else if (page !== 'index') {
- 209 :
params._page = page || 'init';
- 210 :
FramesManager.Instance.close_except_selected()
- 211 :
.disable_manual_multiframe()
- 212 :
.start_custom_multi_frame()
- 213 :
.get_window()
- 214 :
.hide();
- 215 :
window.current_visio = await FramesManager.Instance.open_another_window(
- 216 :
'webconf',
- 217 :
params,
- 218 :
);
- 219 :
FramesManager.Instance.get_window()
- 220 :
.set_cannot_be_select()
- 221 :
//.set_remove_on_change()
- 222 :
.add_tag('dispo-visio');
- 223 :
FramesManager.Instance.select_window(0);
- 224 :
}
- 225 :
}
- 226 :
- 227 :
stopVisio() {
- 228 :
FramesManager.Instance.enable_manual_multiframe().stop_custom_multi_frame();
- 229 :
return this;
- 230 :
}
- 231 :
- 232 :
reinitVisio() {
- 233 :
FramesManager.Instance.close_except_selected().get_window().show();
- 234 :
return this.stopVisio().startVisioMode();
- 235 :
}
- 236 :
- 237 :
/**
- 238 :
* Initialise l'helper
- 239 :
* @returns {BnumVisio} Chaînage
- 240 :
*/
- 241 :
startInstance() {
- 242 :
return this;
- 243 :
}
- 244 :
}
- 245 :
- 246 :
/**
- 247 :
* Donne des fonctions utile pour appeler ou utiliser la visio
- 248 :
* @type {WrapperObject<BnumVisio>}
- 249 :
* @constant
- 250 :
* @frommodule Visio/Helper {@linkto BnumVisio}
- 251 :
*/
- 252 :
export const VisioHelper = new WrapperObject(BnumVisio);
- 253 :
- 254 :
VisioHelper.Instance.startInstance();