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.

middleware.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. getAvatarURLByParticipantId,
  13. getLocalParticipant,
  14. getParticipantById
  15. } from '../base/participants';
  16. import { MiddlewareRegistry } from '../base/redux';
  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.loadableAvatarUrl !== loadableAvatarUrl) {
  38. APP.API.notifyAvatarChanged(
  39. id,
  40. loadableAvatarUrl
  41. );
  42. }
  43. return result;
  44. }
  45. }
  46. const result = next(action);
  47. // These should happen after the rest of the middleware chain ran
  48. switch (action.type) {
  49. case CONFERENCE_FAILED: {
  50. if (action.conference
  51. && action.error.name === JitsiConferenceErrors.PASSWORD_REQUIRED) {
  52. APP.API.notifyOnPasswordRequired();
  53. }
  54. break;
  55. }
  56. case CONFERENCE_JOINED: {
  57. const state = store.getState();
  58. const { room } = state['features/base/conference'];
  59. const { name, id } = getLocalParticipant(state);
  60. APP.API.notifyConferenceJoined(
  61. room,
  62. id,
  63. {
  64. displayName: name,
  65. formattedDisplayName: appendSuffix(
  66. name,
  67. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME
  68. ),
  69. avatarURL: getAvatarURLByParticipantId(state, id)
  70. }
  71. );
  72. break;
  73. }
  74. case KICKED_OUT:
  75. APP.API.notifyKickedOut(
  76. {
  77. id: getLocalParticipant(store.getState()).id,
  78. local: true
  79. },
  80. { id: action.participant.getId() }
  81. );
  82. break;
  83. case NOTIFY_CAMERA_ERROR:
  84. if (action.error) {
  85. APP.API.notifyOnCameraError(
  86. action.error.name, action.error.message);
  87. }
  88. break;
  89. case NOTIFY_MIC_ERROR:
  90. if (action.error) {
  91. APP.API.notifyOnMicError(action.error.name, action.error.message);
  92. }
  93. break;
  94. case PARTICIPANT_KICKED:
  95. APP.API.notifyKickedOut(
  96. {
  97. id: action.kicked,
  98. local: false
  99. },
  100. { id: action.kicker });
  101. break;
  102. case SET_FILMSTRIP_VISIBLE:
  103. APP.API.notifyFilmstripDisplayChanged(action.visible);
  104. break;
  105. case SUBMIT_FEEDBACK:
  106. APP.API.notifyFeedbackSubmitted();
  107. break;
  108. }
  109. return result;
  110. });