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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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: UI.toggleAudio,
  20. muteVideo: UI.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. function setupListeners() {
  123. xmpp.addListener(XMPPEvents.MUC_ENTER, function (from) {
  124. API.triggerEvent("participantJoined", {jid: from});
  125. });
  126. xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, function (from, nick, txt, myjid) {
  127. if (from != myjid)
  128. API.triggerEvent("incomingMessage",
  129. {"from": from, "nick": nick, "message": txt});
  130. });
  131. xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
  132. API.triggerEvent("participantLeft", {jid: jid});
  133. });
  134. }
  135. var API = {
  136. /**
  137. * Check whether the API should be enabled or not.
  138. * @returns {boolean}
  139. */
  140. isEnabled: function () {
  141. var hash = location.hash;
  142. if(hash && hash.indexOf("external") > -1 && window.postMessage)
  143. return true;
  144. return false;
  145. },
  146. /**
  147. * Initializes the APIConnector. Setups message event listeners that will
  148. * receive information from external applications that embed Jitsi Meet.
  149. * It also sends a message to the external application that APIConnector
  150. * is initialized.
  151. */
  152. init: function () {
  153. if (window.addEventListener)
  154. {
  155. window.addEventListener('message',
  156. processMessage, false);
  157. }
  158. else
  159. {
  160. window.attachEvent('onmessage', processMessage);
  161. }
  162. sendMessage({type: "system", loaded: true});
  163. setupListeners();
  164. },
  165. /**
  166. * Checks whether the event is enabled ot not.
  167. * @param name the name of the event.
  168. * @returns {*}
  169. */
  170. isEventEnabled: function (name) {
  171. return events[name];
  172. },
  173. /**
  174. * Sends event object to the external application that has been subscribed
  175. * for that event.
  176. * @param name the name event
  177. * @param object data associated with the event
  178. */
  179. triggerEvent: function (name, object) {
  180. if(this.isEnabled() && this.isEventEnabled(name))
  181. sendMessage({
  182. type: "event", action: "result", event: name, result: object});
  183. },
  184. /**
  185. * Removes the listeners.
  186. */
  187. dispose: function () {
  188. if(window.removeEventListener)
  189. {
  190. window.removeEventListener("message",
  191. processMessage, false);
  192. }
  193. else
  194. {
  195. window.detachEvent('onmessage', processMessage);
  196. }
  197. }
  198. };
  199. module.exports = API;
  200. },{}]},{},[1])(1)
  201. });