You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

API.bundle.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.API=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. /**
  3. * Implements API class that communicates with external api class
  4. * and provides interface to access Jitsi Meet features by external
  5. * applications that embed Jitsi Meet
  6. */
  7. /**
  8. * List of the available commands.
  9. * @type {{
  10. * displayName: inputDisplayNameHandler,
  11. * muteAudio: toggleAudio,
  12. * muteVideo: toggleVideo,
  13. * filmStrip: toggleFilmStrip
  14. * }}
  15. */
  16. var commands =
  17. {
  18. displayName: UI.inputDisplayNameHandler,
  19. muteAudio: toggleAudio,
  20. muteVideo: toggleVideo,
  21. toggleFilmStrip: UI.toggleFilmStrip,
  22. toggleChat: UI.toggleChat,
  23. toggleContactList: UI.toggleContactList
  24. };
  25. /**
  26. * Maps the supported events and their status
  27. * (true it the event is enabled and false if it is disabled)
  28. * @type {{
  29. * incomingMessage: boolean,
  30. * outgoingMessage: boolean,
  31. * displayNameChange: boolean,
  32. * participantJoined: boolean,
  33. * participantLeft: boolean
  34. * }}
  35. */
  36. var events =
  37. {
  38. incomingMessage: false,
  39. outgoingMessage:false,
  40. displayNameChange: false,
  41. participantJoined: false,
  42. participantLeft: false
  43. };
  44. /**
  45. * Processes commands from external applicaiton.
  46. * @param message the object with the command
  47. */
  48. function processCommand(message)
  49. {
  50. if(message.action != "execute")
  51. {
  52. console.error("Unknown action of the message");
  53. return;
  54. }
  55. for(var key in message)
  56. {
  57. if(commands[key])
  58. commands[key].apply(null, message[key]);
  59. }
  60. }
  61. /**
  62. * Processes events objects from external applications
  63. * @param event the event
  64. */
  65. function processEvent(event) {
  66. if(!event.action)
  67. {
  68. console.error("Event with no action is received.");
  69. return;
  70. }
  71. var i = 0;
  72. switch(event.action)
  73. {
  74. case "add":
  75. for(; i < event.events.length; i++)
  76. {
  77. events[event.events[i]] = true;
  78. }
  79. break;
  80. case "remove":
  81. for(; i < event.events.length; i++)
  82. {
  83. events[event.events[i]] = false;
  84. }
  85. break;
  86. default:
  87. console.error("Unknown action for event.");
  88. }
  89. }
  90. /**
  91. * Sends message to the external application.
  92. * @param object
  93. */
  94. function sendMessage(object) {
  95. window.parent.postMessage(JSON.stringify(object), "*");
  96. }
  97. /**
  98. * Processes a message event from the external application
  99. * @param event the message event
  100. */
  101. function processMessage(event)
  102. {
  103. var message;
  104. try {
  105. message = JSON.parse(event.data);
  106. } catch (e) {}
  107. if(!message.type)
  108. return;
  109. switch (message.type)
  110. {
  111. case "command":
  112. processCommand(message);
  113. break;
  114. case "event":
  115. processEvent(message);
  116. break;
  117. default:
  118. console.error("Unknown type of the message");
  119. return;
  120. }
  121. }
  122. var API = {
  123. /**
  124. * Check whether the API should be enabled or not.
  125. * @returns {boolean}
  126. */
  127. isEnabled: function () {
  128. var hash = location.hash;
  129. if(hash && hash.indexOf("external") > -1 && window.postMessage)
  130. return true;
  131. return false;
  132. },
  133. /**
  134. * Initializes the APIConnector. Setups message event listeners that will
  135. * receive information from external applications that embed Jitsi Meet.
  136. * It also sends a message to the external application that APIConnector
  137. * is initialized.
  138. */
  139. init: function () {
  140. if (window.addEventListener)
  141. {
  142. window.addEventListener('message',
  143. processMessage, false);
  144. }
  145. else
  146. {
  147. window.attachEvent('onmessage', processMessage);
  148. }
  149. sendMessage({type: "system", loaded: true});
  150. },
  151. /**
  152. * Checks whether the event is enabled ot not.
  153. * @param name the name of the event.
  154. * @returns {*}
  155. */
  156. isEventEnabled: function (name) {
  157. return events[name];
  158. },
  159. /**
  160. * Sends event object to the external application that has been subscribed
  161. * for that event.
  162. * @param name the name event
  163. * @param object data associated with the event
  164. */
  165. triggerEvent: function (name, object) {
  166. if(this.isEnabled() && this.isEventEnabled(name))
  167. sendMessage({
  168. type: "event", action: "result", event: name, result: object});
  169. },
  170. /**
  171. * Removes the listeners.
  172. */
  173. dispose: function () {
  174. if(window.removeEventListener)
  175. {
  176. window.removeEventListener("message",
  177. processMessage, false);
  178. }
  179. else
  180. {
  181. window.detachEvent('onmessage', processMessage);
  182. }
  183. }
  184. };
  185. module.exports = API;
  186. },{}]},{},[1])(1)
  187. });