選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

middleware.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // @flow
  2. import {
  3. CONFERENCE_FAILED,
  4. CONFERENCE_JOINED,
  5. KICKED_OUT
  6. } from '../base/conference';
  7. import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR } from '../base/devices';
  8. import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
  9. import {
  10. DOMINANT_SPEAKER_CHANGED,
  11. PARTICIPANT_KICKED,
  12. PARTICIPANT_LEFT,
  13. PARTICIPANT_JOINED,
  14. PARTICIPANT_ROLE_CHANGED,
  15. SET_LOADABLE_AVATAR_URL,
  16. getLocalParticipant,
  17. getParticipantById
  18. } from '../base/participants';
  19. import { MiddlewareRegistry } from '../base/redux';
  20. import { getBaseUrl } from '../base/util';
  21. import { appendSuffix } from '../display-name';
  22. import { SUBMIT_FEEDBACK_ERROR, SUBMIT_FEEDBACK_SUCCESS } from '../feedback';
  23. import { SET_FILMSTRIP_VISIBLE } from '../filmstrip';
  24. declare var APP: Object;
  25. declare var interfaceConfig: Object;
  26. /**
  27. * The middleware of the feature {@code external-api}.
  28. *
  29. * @returns {Function}
  30. */
  31. MiddlewareRegistry.register(store => next => action => {
  32. // We need to do these before executing the rest of the middelware chain
  33. switch (action.type) {
  34. case SET_LOADABLE_AVATAR_URL: {
  35. const { id, loadableAvatarUrl } = action.participant;
  36. const participant = getParticipantById(
  37. store.getState(),
  38. id
  39. );
  40. const result = next(action);
  41. if (participant) {
  42. if (loadableAvatarUrl) {
  43. participant.loadableAvatarUrl !== loadableAvatarUrl && APP.API.notifyAvatarChanged(
  44. id,
  45. loadableAvatarUrl
  46. );
  47. } else {
  48. // There is no loadable explicit URL. In this case the Avatar component would
  49. // decide to render initials or the default avatar, but the external API needs
  50. // a URL when it needs to be rendered, so if there is no initials, we return the default
  51. // Avatar URL as if it was a usual avatar URL. If there are (or may be) initials
  52. // we send undefined to signal the api user that it's not an URL that needs to be rendered.
  53. //
  54. // NOTE: we may implement a special URL format later to signal that the avatar is based
  55. // on initials, that API consumers can handle as they want, e.g. initials://jm
  56. APP.API.notifyAvatarChanged(
  57. id,
  58. participant.name ? undefined : _getDefaultAvatarUrl()
  59. );
  60. }
  61. }
  62. return result;
  63. }
  64. }
  65. const result = next(action);
  66. // These should happen after the rest of the middleware chain ran
  67. switch (action.type) {
  68. case CONFERENCE_FAILED: {
  69. if (action.conference
  70. && action.error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  71. APP.API.notifyOnPasswordRequired();
  72. }
  73. break;
  74. }
  75. case CONFERENCE_JOINED: {
  76. const state = store.getState();
  77. const { room } = state['features/base/conference'];
  78. const { loadableAvatarUrl, name, id } = getLocalParticipant(state);
  79. APP.API.notifyConferenceJoined(
  80. room,
  81. id,
  82. {
  83. displayName: name,
  84. formattedDisplayName: appendSuffix(
  85. name,
  86. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME
  87. ),
  88. avatarURL: loadableAvatarUrl
  89. }
  90. );
  91. break;
  92. }
  93. case DOMINANT_SPEAKER_CHANGED:
  94. APP.API.notifyDominantSpeakerChanged(action.participant.id);
  95. break;
  96. case KICKED_OUT:
  97. APP.API.notifyKickedOut(
  98. {
  99. id: getLocalParticipant(store.getState()).id,
  100. local: true
  101. },
  102. { id: action.participant.getId() }
  103. );
  104. break;
  105. case NOTIFY_CAMERA_ERROR:
  106. if (action.error) {
  107. APP.API.notifyOnCameraError(
  108. action.error.name, action.error.message);
  109. }
  110. break;
  111. case NOTIFY_MIC_ERROR:
  112. if (action.error) {
  113. APP.API.notifyOnMicError(action.error.name, action.error.message);
  114. }
  115. break;
  116. case PARTICIPANT_KICKED:
  117. APP.API.notifyKickedOut(
  118. {
  119. id: action.kicked,
  120. local: false
  121. },
  122. { id: action.kicker });
  123. break;
  124. case PARTICIPANT_LEFT:
  125. APP.API.notifyUserLeft(action.participant.id);
  126. break;
  127. case PARTICIPANT_JOINED: {
  128. const { participant } = action;
  129. const { id, local, name } = participant;
  130. // The version of external api outside of middleware did not emit
  131. // the local participant being created.
  132. if (!local) {
  133. APP.API.notifyUserJoined(id, {
  134. displayName: name,
  135. formattedDisplayName: appendSuffix(
  136. name || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME)
  137. });
  138. }
  139. break;
  140. }
  141. case PARTICIPANT_ROLE_CHANGED:
  142. APP.API.notifyUserRoleChanged(action.participant.id, action.participant.role);
  143. break;
  144. case SET_FILMSTRIP_VISIBLE:
  145. APP.API.notifyFilmstripDisplayChanged(action.visible);
  146. break;
  147. case SUBMIT_FEEDBACK_ERROR:
  148. APP.API.notifyFeedbackSubmitted(action.error || 'Unknown error');
  149. break;
  150. case SUBMIT_FEEDBACK_SUCCESS:
  151. APP.API.notifyFeedbackSubmitted();
  152. break;
  153. }
  154. return result;
  155. });
  156. /**
  157. * Returns the absolute URL of the default avatar.
  158. *
  159. * @returns {string}
  160. */
  161. function _getDefaultAvatarUrl() {
  162. return new URL('images/avatar.png', getBaseUrl()).href;
  163. }