您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BoshAddressChoice.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const logger = require("jitsi-meet-logger").getLogger(__filename);
  2. var JSSHA = require('jssha');
  3. module.exports = {
  4. /**
  5. * Looks for a list of possible BOSH addresses in 'config.boshList' and
  6. * sets the value of 'config.bosh' based on that list and 'roomName'.
  7. * @param config the configuration object.
  8. * @param roomName the name of the room/conference.
  9. */
  10. chooseAddress: function(config, roomName) {
  11. if (!roomName || !config.boshList || !Array.isArray(config.boshList) ||
  12. !config.boshList.length) {
  13. return;
  14. }
  15. // This implements the actual choice of an entry in the list based on
  16. // roomName. Please consider the implications for existing deployments
  17. // before introducing changes.
  18. var hash = (new JSSHA(roomName, 'TEXT')).getHash('SHA-1', 'HEX');
  19. var n = parseInt("0x"+hash.substr(-6));
  20. var idx = n % config.boshList.length;
  21. var attemptFirstAddress;
  22. config.bosh = config.boshList[idx];
  23. logger.log('Setting config.bosh to ' + config.bosh +
  24. ' (idx=' + idx + ')');
  25. if (config.boshAttemptFirstList &&
  26. Array.isArray(config.boshAttemptFirstList) &&
  27. config.boshAttemptFirstList.length > 0) {
  28. idx = n % config.boshAttemptFirstList.length;
  29. attemptFirstAddress = config.boshAttemptFirstList[idx];
  30. if (attemptFirstAddress != config.bosh) {
  31. config.boshAttemptFirst = attemptFirstAddress;
  32. logger.log('Setting config.boshAttemptFirst=' +
  33. attemptFirstAddress + ' (idx=' + idx + ')');
  34. } else {
  35. logger.log('Not setting boshAttemptFirst, address matches.');
  36. }
  37. }
  38. }
  39. };