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

middleware.js 5.1KB

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