Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Implements API class that communicates with external api class
  3. * and provides interface to access Jitsi Meet features by external
  4. * applications that embed Jitsi Meet
  5. */
  6. var APIConnector = (function () {
  7. function APIConnector() { }
  8. /**
  9. * List of the available commands.
  10. * @type {{
  11. * displayName: inputDisplayNameHandler,
  12. * muteAudio: toggleAudio,
  13. * muteVideo: toggleVideo,
  14. * filmStrip: toggleFilmStrip
  15. * }}
  16. */
  17. var commands =
  18. {
  19. displayName: VideoLayout.inputDisplayNameHandler,
  20. muteAudio: toggleAudio,
  21. muteVideo: toggleVideo,
  22. filmStrip: BottomToolbar.toggleFilmStrip
  23. };
  24. /**
  25. * Check whether the API should be enabled or not.
  26. * @returns {boolean}
  27. */
  28. APIConnector.isEnabled = function () {
  29. var hash = location.hash;
  30. if(hash && hash.indexOf("external") > -1 && window.postMessage)
  31. return true;
  32. return false;
  33. };
  34. /**
  35. * Initializes the APIConnector. Setups message event listeners that will
  36. * receive information from external applications that embed Jitsi Meet.
  37. * It also sends a message to the external application that APIConnector
  38. * is initialized.
  39. */
  40. APIConnector.init = function () {
  41. if (window.addEventListener)
  42. {
  43. window.addEventListener('message',
  44. APIConnector.processMessage, false);
  45. }
  46. else
  47. {
  48. window.attachEvent('onmessage', APIConnector.processMessage);
  49. }
  50. APIConnector.sendMessage({loaded: true});
  51. };
  52. /**
  53. * Sends message to the external application.
  54. * @param object
  55. */
  56. APIConnector.sendMessage = function (object) {
  57. window.parent.postMessage(JSON.stringify(object), "*");
  58. };
  59. /**
  60. * Processes a message event from the external application
  61. * @param event the message event
  62. */
  63. APIConnector.processMessage = function(event)
  64. {
  65. var message;
  66. try {
  67. message = JSON.parse(event.data);
  68. } catch (e) {}
  69. for(var key in message)
  70. {
  71. if(commands[key])
  72. commands[key].apply(null, message[key]);
  73. }
  74. };
  75. /**
  76. * Removes the listeners.
  77. */
  78. APIConnector.dispose = function () {
  79. if(window.removeEventListener)
  80. {
  81. window.removeEventListener("message",
  82. APIConnector.processMessage, false);
  83. }
  84. else
  85. {
  86. window.detachEvent('onmessage', APIConnector.processMessage);
  87. }
  88. };
  89. return APIConnector;
  90. })();