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.

actions.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // @flow
  2. import {
  3. _DIAL_ERROR,
  4. _POTENTIAL_TRANSCRIBER_JOINED,
  5. _TRANSCRIBER_JOINED,
  6. _TRANSCRIBER_LEFT,
  7. DIAL_TRANSCRIBER,
  8. SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  9. STOP_TRANSCRIBING
  10. } from './actionTypes';
  11. import {
  12. hideNotification,
  13. showErrorNotification,
  14. showNotification
  15. } from '../notifications';
  16. /**
  17. * Dial the transcriber into the room.
  18. *
  19. * @public
  20. * @returns {{
  21. * type: DIAL_TRANSCRIBER
  22. * }}
  23. */
  24. export function dialTranscriber() {
  25. return {
  26. type: DIAL_TRANSCRIBER
  27. };
  28. }
  29. /**
  30. * Stop the transcribing by kicking the transcriber participant.
  31. *
  32. * @returns {{
  33. * type: STOP_TRANSCRIBING
  34. * }}
  35. */
  36. export function stopTranscribing() {
  37. return {
  38. type: STOP_TRANSCRIBING
  39. };
  40. }
  41. /**
  42. * Notify that the transcriber, with a unique ID, has joined.
  43. *
  44. * @param {string} participantId - The participant id of the transcriber.
  45. * @returns {{
  46. * type: _TRANSCRIBER_JOINED,
  47. * participantId: string
  48. * }}
  49. */
  50. export function transcriberJoined(participantId: string) {
  51. return {
  52. type: _TRANSCRIBER_JOINED,
  53. transcriberJID: participantId
  54. };
  55. }
  56. /**
  57. * Notify that the transcriber, with a unique ID, has left.
  58. *
  59. * @param {string} participantId - The participant id of the transcriber.
  60. * @returns {{
  61. * type: _TRANSCRIBER_LEFT,
  62. * participantId: string
  63. * }}
  64. */
  65. export function transcriberLeft(participantId: string) {
  66. return {
  67. type: _TRANSCRIBER_LEFT,
  68. transcriberJID: participantId
  69. };
  70. }
  71. /**
  72. * Notify that a potential transcriber, with a unique ID, has joined.
  73. *
  74. * @param {string} participantId - The participant id of the transcriber.
  75. * @returns {{
  76. * type: _POTENTIAL_TRANSCRIBER_JOINED,
  77. * participantId: string
  78. * }}
  79. */
  80. export function potentialTranscriberJoined(participantId: string) {
  81. return {
  82. type: _POTENTIAL_TRANSCRIBER_JOINED,
  83. transcriberJID: participantId
  84. };
  85. }
  86. /**
  87. * Notify that dialing the transcriber resulted in an error.
  88. *
  89. * @returns {{
  90. * type: _DIAL_ERROR
  91. * }}
  92. */
  93. export function dialError() {
  94. return {
  95. type: _DIAL_ERROR
  96. };
  97. }
  98. /**
  99. * Signals that the pending transcribing notification should be shown on the
  100. * screen.
  101. *
  102. * @returns {Function}
  103. */
  104. export function showPendingTranscribingNotification() {
  105. return (dispatch: Function) => {
  106. const showNotificationAction = showNotification({
  107. descriptionKey: 'transcribing.pending',
  108. isDismissAllowed: false,
  109. titleKey: 'dialog.transcribing'
  110. });
  111. dispatch(showNotificationAction);
  112. dispatch(setPendingTranscribingNotificationUid(
  113. showNotificationAction.uid));
  114. };
  115. }
  116. /**
  117. * Sets UID of the the pending transcribing notification to use it when hiding
  118. * the notification is necessary, or unsets it when undefined (or no param) is
  119. * passed.
  120. *
  121. * @param {?number} uid - The UID of the notification.
  122. * @returns {{
  123. * type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  124. * uid: number
  125. * }}
  126. */
  127. export function setPendingTranscribingNotificationUid(uid: ?number) {
  128. return {
  129. type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  130. uid
  131. };
  132. }
  133. /**
  134. * Signals that the pending transcribing notification should be removed from the
  135. * screen.
  136. *
  137. * @returns {Function}
  138. */
  139. export function hidePendingTranscribingNotification() {
  140. return (dispatch: Function, getState: Function) => {
  141. const { pendingNotificationUid } = getState()['features/transcribing'];
  142. if (pendingNotificationUid) {
  143. dispatch(hideNotification(pendingNotificationUid));
  144. dispatch(setPendingTranscribingNotificationUid());
  145. }
  146. };
  147. }
  148. /**
  149. * Signals that the stopped transcribing notification should be shown on the
  150. * screen for a 2500 ms.
  151. *
  152. * @returns {showNotification}
  153. */
  154. export function showStoppedTranscribingNotification() {
  155. return showNotification({
  156. descriptionKey: 'transcribing.off',
  157. titleKey: 'dialog.transcribing'
  158. }, 2500);
  159. }
  160. /**
  161. * Signals that the transcribing error notification should be shown.
  162. *
  163. * @returns {showErrorNotification}
  164. */
  165. export function showTranscribingError() {
  166. return showErrorNotification({
  167. descriptionKey: 'transcribing.error',
  168. titleKey: 'transcribing.failedToStart'
  169. });
  170. }