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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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
  119. * undefined (or no param) is passed.
  120. *
  121. * @param {?number} uid - The UID of the notification.
  122. * redux.
  123. * @returns {{
  124. * type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  125. * uid: number
  126. * }}
  127. */
  128. export function setPendingTranscribingNotificationUid(uid: ?number) {
  129. return {
  130. type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  131. uid
  132. };
  133. }
  134. /**
  135. * Signals that the pending transcribing notification should be removed from the
  136. * screen.
  137. *
  138. * @returns {Function}
  139. */
  140. export function hidePendingTranscribingNotification() {
  141. return (dispatch: Function, getState: Function) => {
  142. const { pendingNotificationUid } = getState()['features/transcribing'];
  143. if (pendingNotificationUid) {
  144. dispatch(hideNotification(pendingNotificationUid));
  145. dispatch(setPendingTranscribingNotificationUid());
  146. }
  147. };
  148. }
  149. /**
  150. * Signals that the stopped transcribing notification should be shown on the
  151. * screen for a 2500 ms.
  152. *
  153. * @returns {showNotification}
  154. */
  155. export function showStoppedTranscribingNotification() {
  156. return showNotification({
  157. descriptionKey: 'transcribing.off',
  158. titleKey: 'dialog.transcribing'
  159. }, 2500);
  160. }
  161. /**
  162. * Signals that the transcribing error notification should be shown.
  163. *
  164. * @returns {showErrorNotification}
  165. */
  166. export function showTranscribingError() {
  167. return showErrorNotification({
  168. descriptionKey: 'transcribing.error',
  169. titleKey: 'transcribing.failedToStart'
  170. });
  171. }