|
|
@@ -246,103 +246,138 @@ Moderator.prototype.parseConfigOptions = function (resultIq) {
|
|
246
|
246
|
logger.info("Sip gateway enabled: " + this.sipGatewayEnabled);
|
|
247
|
247
|
};
|
|
248
|
248
|
|
|
249
|
|
-// FIXME = we need to show the fact that we're waiting for the focus
|
|
250
|
|
-// to the user(or that focus is not available)
|
|
|
249
|
+// FIXME We need to show the fact that we're waiting for the focus to the user
|
|
|
250
|
+// (or that the focus is not available)
|
|
|
251
|
+/**
|
|
|
252
|
+ * Allocates the conference focus.
|
|
|
253
|
+ *
|
|
|
254
|
+ * @param {Function} callback - the function to be called back upon the
|
|
|
255
|
+ * successful allocation of the conference focus
|
|
|
256
|
+ */
|
|
251
|
257
|
Moderator.prototype.allocateConferenceFocus = function (callback) {
|
|
252
|
258
|
// Try to use focus user JID from the config
|
|
253
|
259
|
this.setFocusUserJid(this.xmppService.options.focusUserJid);
|
|
254
|
260
|
// Send create conference IQ
|
|
255
|
|
- var iq = this.createConferenceIq();
|
|
256
|
261
|
var self = this;
|
|
257
|
262
|
this.connection.sendIQ(
|
|
258
|
|
- iq,
|
|
|
263
|
+ this.createConferenceIq(),
|
|
259
|
264
|
function (result) {
|
|
260
|
|
-
|
|
261
|
|
- // Setup config options
|
|
262
|
|
- self.parseConfigOptions(result);
|
|
263
|
|
-
|
|
264
|
|
- if ('true' === $(result).find('conference').attr('ready')) {
|
|
265
|
|
- // Reset both timers
|
|
266
|
|
- self.getNextTimeout(true);
|
|
267
|
|
- self.getNextErrorTimeout(true);
|
|
268
|
|
- // Exec callback
|
|
269
|
|
- callback();
|
|
270
|
|
- } else {
|
|
271
|
|
- var waitMs = self.getNextTimeout();
|
|
272
|
|
- logger.info("Waiting for the focus... " + waitMs);
|
|
273
|
|
- // Reset error timeout
|
|
274
|
|
- self.getNextErrorTimeout(true);
|
|
275
|
|
- window.setTimeout(
|
|
276
|
|
- function () {
|
|
277
|
|
- self.allocateConferenceFocus(callback);
|
|
278
|
|
- }, waitMs);
|
|
279
|
|
- }
|
|
|
265
|
+ self._allocateConferenceFocusSuccess(result, callback);
|
|
280
|
266
|
},
|
|
281
|
267
|
function (error) {
|
|
282
|
|
- // Invalid session ? remove and try again
|
|
283
|
|
- // without session ID to get a new one
|
|
284
|
|
- var invalidSession
|
|
285
|
|
- = $(error).find('>error>session-invalid').length;
|
|
286
|
|
- if (invalidSession) {
|
|
287
|
|
- logger.info("Session expired! - removing");
|
|
288
|
|
- self.settings.clearSessionId();
|
|
289
|
|
- }
|
|
290
|
|
- if ($(error).find('>error>graceful-shutdown').length) {
|
|
291
|
|
- self.eventEmitter.emit(XMPPEvents.GRACEFUL_SHUTDOWN);
|
|
292
|
|
- return;
|
|
293
|
|
- }
|
|
294
|
|
- // Check for error returned by the reservation system
|
|
295
|
|
- var reservationErr = $(error).find('>error>reservation-error');
|
|
296
|
|
- if (reservationErr.length) {
|
|
297
|
|
- // Trigger error event
|
|
298
|
|
- var errorCode = reservationErr.attr('error-code');
|
|
299
|
|
- var errorMsg;
|
|
300
|
|
- if ($(error).find('>error>text')) {
|
|
301
|
|
- errorMsg = $(error).find('>error>text').text();
|
|
302
|
|
- }
|
|
303
|
|
- self.eventEmitter.emit(
|
|
304
|
|
- XMPPEvents.RESERVATION_ERROR, errorCode, errorMsg);
|
|
305
|
|
- return;
|
|
306
|
|
- }
|
|
307
|
|
- // Not authorized to create new room
|
|
308
|
|
- if ($(error).find('>error>not-authorized').length) {
|
|
309
|
|
- logger.warn("Unauthorized to start the conference", error);
|
|
310
|
|
- var toDomain
|
|
311
|
|
- = Strophe.getDomainFromJid(error.getAttribute('to'));
|
|
312
|
|
- if (toDomain !==
|
|
313
|
|
- self.xmppService.options.hosts.anonymousdomain) {
|
|
314
|
|
- //FIXME: "is external" should come either from
|
|
315
|
|
- // the focus or config.js
|
|
316
|
|
- self.externalAuthEnabled = true;
|
|
317
|
|
- }
|
|
318
|
|
- self.eventEmitter.emit(
|
|
319
|
|
- XMPPEvents.AUTHENTICATION_REQUIRED,
|
|
320
|
|
- function () {
|
|
321
|
|
- self.allocateConferenceFocus(
|
|
322
|
|
- callback);
|
|
323
|
|
- });
|
|
324
|
|
- return;
|
|
325
|
|
- }
|
|
326
|
|
- var waitMs = self.getNextErrorTimeout();
|
|
327
|
|
- logger.error("Focus error, retry after " + waitMs, error);
|
|
328
|
|
- // Show message
|
|
329
|
|
- var focusComponent = self.getFocusComponent();
|
|
330
|
|
- var retrySec = waitMs / 1000;
|
|
331
|
|
- //FIXME: message is duplicated ?
|
|
332
|
|
- // Do not show in case of session invalid
|
|
333
|
|
- // which means just a retry
|
|
334
|
|
- if (!invalidSession) {
|
|
335
|
|
- self.eventEmitter.emit(XMPPEvents.FOCUS_DISCONNECTED,
|
|
336
|
|
- focusComponent, retrySec);
|
|
337
|
|
- }
|
|
338
|
|
- // Reset response timeout
|
|
339
|
|
- self.getNextTimeout(true);
|
|
340
|
|
- window.setTimeout(
|
|
|
268
|
+ self._allocateConferenceFocusError(error);
|
|
|
269
|
+ });
|
|
|
270
|
+ // XXX We're pressed for time here because we're beginning a complex and/or
|
|
|
271
|
+ // lengthy conference-establishment process which supposedly involves
|
|
|
272
|
+ // multiple RTTs. We don't have the time to wait for Strophe to decide to
|
|
|
273
|
+ // send our IQ.
|
|
|
274
|
+ this.connection.flush();
|
|
|
275
|
+};
|
|
|
276
|
+
|
|
|
277
|
+/**
|
|
|
278
|
+ * Invoked by {@link #allocateConferenceFocus} upon its request receiving an
|
|
|
279
|
+ * error result.
|
|
|
280
|
+ *
|
|
|
281
|
+ * @param error - the error result of the request that
|
|
|
282
|
+ * {@link #allocateConferenceFocus} sent
|
|
|
283
|
+ * @param {Function} callback - the function to be called back upon the
|
|
|
284
|
+ * successful allocation of the conference focus
|
|
|
285
|
+ */
|
|
|
286
|
+Moderator.prototype._allocateConferenceFocusError = function (error, callback) {
|
|
|
287
|
+ var self = this;
|
|
|
288
|
+
|
|
|
289
|
+ // If the session is invalid, remove and try again without session ID to get
|
|
|
290
|
+ // a new one
|
|
|
291
|
+ var invalidSession = $(error).find('>error>session-invalid').length;
|
|
|
292
|
+ if (invalidSession) {
|
|
|
293
|
+ logger.info("Session expired! - removing");
|
|
|
294
|
+ self.settings.clearSessionId();
|
|
|
295
|
+ }
|
|
|
296
|
+ if ($(error).find('>error>graceful-shutdown').length) {
|
|
|
297
|
+ self.eventEmitter.emit(XMPPEvents.GRACEFUL_SHUTDOWN);
|
|
|
298
|
+ return;
|
|
|
299
|
+ }
|
|
|
300
|
+ // Check for error returned by the reservation system
|
|
|
301
|
+ var reservationErr = $(error).find('>error>reservation-error');
|
|
|
302
|
+ if (reservationErr.length) {
|
|
|
303
|
+ // Trigger error event
|
|
|
304
|
+ var errorCode = reservationErr.attr('error-code');
|
|
|
305
|
+ var errorTextNode = $(error).find('>error>text');
|
|
|
306
|
+ var errorMsg;
|
|
|
307
|
+ if (errorTextNode) {
|
|
|
308
|
+ errorMsg = errorTextNode.text();
|
|
|
309
|
+ }
|
|
|
310
|
+ self.eventEmitter.emit(
|
|
|
311
|
+ XMPPEvents.RESERVATION_ERROR, errorCode, errorMsg);
|
|
|
312
|
+ return;
|
|
|
313
|
+ }
|
|
|
314
|
+ // Not authorized to create new room
|
|
|
315
|
+ if ($(error).find('>error>not-authorized').length) {
|
|
|
316
|
+ logger.warn("Unauthorized to start the conference", error);
|
|
|
317
|
+ var toDomain = Strophe.getDomainFromJid(error.getAttribute('to'));
|
|
|
318
|
+ if (toDomain !== self.xmppService.options.hosts.anonymousdomain) {
|
|
|
319
|
+ //FIXME "is external" should come either from the focus or config.js
|
|
|
320
|
+ self.externalAuthEnabled = true;
|
|
|
321
|
+ }
|
|
|
322
|
+ self.eventEmitter.emit(
|
|
|
323
|
+ XMPPEvents.AUTHENTICATION_REQUIRED,
|
|
341
|
324
|
function () {
|
|
342
|
325
|
self.allocateConferenceFocus(callback);
|
|
343
|
|
- }, waitMs);
|
|
344
|
|
- }
|
|
345
|
|
- );
|
|
|
326
|
+ });
|
|
|
327
|
+ return;
|
|
|
328
|
+ }
|
|
|
329
|
+ var waitMs = self.getNextErrorTimeout();
|
|
|
330
|
+ logger.error("Focus error, retry after " + waitMs, error);
|
|
|
331
|
+ // Show message
|
|
|
332
|
+ var focusComponent = self.getFocusComponent();
|
|
|
333
|
+ var retrySec = waitMs / 1000;
|
|
|
334
|
+ //FIXME: message is duplicated ? Do not show in case of session invalid
|
|
|
335
|
+ // which means just a retry
|
|
|
336
|
+ if (!invalidSession) {
|
|
|
337
|
+ self.eventEmitter.emit(
|
|
|
338
|
+ XMPPEvents.FOCUS_DISCONNECTED, focusComponent, retrySec);
|
|
|
339
|
+ }
|
|
|
340
|
+ // Reset response timeout
|
|
|
341
|
+ self.getNextTimeout(true);
|
|
|
342
|
+ window.setTimeout(
|
|
|
343
|
+ function () {
|
|
|
344
|
+ self.allocateConferenceFocus(callback);
|
|
|
345
|
+ },
|
|
|
346
|
+ waitMs);
|
|
|
347
|
+};
|
|
|
348
|
+
|
|
|
349
|
+/**
|
|
|
350
|
+ * Invoked by {@link #allocateConferenceFocus} upon its request receiving a
|
|
|
351
|
+ * success (i.e. non-error) result.
|
|
|
352
|
+ *
|
|
|
353
|
+ * @param result - the success (i.e. non-error) result of the request that
|
|
|
354
|
+ * {@link #allocateConferenceFocus} sent
|
|
|
355
|
+ * @param {Function} callback - the function to be called back upon the
|
|
|
356
|
+ * successful allocation of the conference focus
|
|
|
357
|
+ */
|
|
|
358
|
+Moderator.prototype._allocateConferenceFocusSuccess = function (
|
|
|
359
|
+ result,
|
|
|
360
|
+ callback) {
|
|
|
361
|
+ // Setup config options
|
|
|
362
|
+ this.parseConfigOptions(result);
|
|
|
363
|
+
|
|
|
364
|
+ // Reset the error timeout (because we haven't failed here).
|
|
|
365
|
+ this.getNextErrorTimeout(true);
|
|
|
366
|
+ if ('true' === $(result).find('conference').attr('ready')) {
|
|
|
367
|
+ // Reset the non-error timeout (because we've succeeded here).
|
|
|
368
|
+ this.getNextTimeout(true);
|
|
|
369
|
+ // Exec callback
|
|
|
370
|
+ callback();
|
|
|
371
|
+ } else {
|
|
|
372
|
+ var waitMs = this.getNextTimeout();
|
|
|
373
|
+ logger.info("Waiting for the focus... " + waitMs);
|
|
|
374
|
+ var self = this;
|
|
|
375
|
+ window.setTimeout(
|
|
|
376
|
+ function () {
|
|
|
377
|
+ self.allocateConferenceFocus(callback);
|
|
|
378
|
+ },
|
|
|
379
|
+ waitMs);
|
|
|
380
|
+ }
|
|
346
|
381
|
};
|
|
347
|
382
|
|
|
348
|
383
|
Moderator.prototype.authenticate = function () {
|