您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 4.4KB

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