stream-chat-react-native-core 8.10.1 → 8.11.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/lib/commonjs/components/Attachment/AudioAttachment.js +84 -209
  2. package/lib/commonjs/components/Attachment/AudioAttachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js +8 -5
  4. package/lib/commonjs/components/Attachment/FileAttachmentGroup.js.map +1 -1
  5. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.js +7 -3
  6. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.js.map +1 -1
  7. package/lib/commonjs/components/Channel/Channel.js +20 -9
  8. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  9. package/lib/commonjs/components/Message/hooks/useMessageActionHandlers.js +4 -1
  10. package/lib/commonjs/components/Message/hooks/useMessageActionHandlers.js.map +1 -1
  11. package/lib/commonjs/components/MessageInput/MessageInput.js +2 -0
  12. package/lib/commonjs/components/MessageInput/MessageInput.js.map +1 -1
  13. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js +9 -3
  14. package/lib/commonjs/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js.map +1 -1
  15. package/lib/commonjs/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.js +44 -8
  16. package/lib/commonjs/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.js.map +1 -1
  17. package/lib/commonjs/components/MessageInput/hooks/useAudioController.js +5 -0
  18. package/lib/commonjs/components/MessageInput/hooks/useAudioController.js.map +1 -1
  19. package/lib/commonjs/components/MessageInput/hooks/useAudioPreviewManager.js.map +1 -1
  20. package/lib/commonjs/components/ProgressControl/ProgressControl.js +25 -33
  21. package/lib/commonjs/components/ProgressControl/ProgressControl.js.map +1 -1
  22. package/lib/commonjs/components/ProgressControl/WaveProgressBar.js +21 -29
  23. package/lib/commonjs/components/ProgressControl/WaveProgressBar.js.map +1 -1
  24. package/lib/commonjs/contexts/audioPlayerContext/AudioPlayerContext.js +56 -0
  25. package/lib/commonjs/contexts/audioPlayerContext/AudioPlayerContext.js.map +1 -0
  26. package/lib/commonjs/contexts/index.js +11 -0
  27. package/lib/commonjs/contexts/index.js.map +1 -1
  28. package/lib/commonjs/contexts/themeContext/utils/theme.js +4 -0
  29. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  30. package/lib/commonjs/hooks/index.js +11 -0
  31. package/lib/commonjs/hooks/index.js.map +1 -1
  32. package/lib/commonjs/hooks/useAudioPlayer.js +18 -25
  33. package/lib/commonjs/hooks/useAudioPlayer.js.map +1 -1
  34. package/lib/commonjs/hooks/useAudioPlayerControl.js +43 -0
  35. package/lib/commonjs/hooks/useAudioPlayerControl.js.map +1 -0
  36. package/lib/commonjs/hooks/useInAppNotificationsState.js +1 -1
  37. package/lib/commonjs/i18n/es.json +1 -2
  38. package/lib/commonjs/i18n/he.json +5 -5
  39. package/lib/commonjs/i18n/ru.json +0 -5
  40. package/lib/commonjs/index.js +4 -4
  41. package/lib/commonjs/index.js.map +1 -1
  42. package/lib/commonjs/native.js.map +1 -1
  43. package/lib/commonjs/state-store/audio-player-pool.js +99 -0
  44. package/lib/commonjs/state-store/audio-player-pool.js.map +1 -0
  45. package/lib/commonjs/state-store/audio-player.js +373 -0
  46. package/lib/commonjs/state-store/audio-player.js.map +1 -0
  47. package/lib/commonjs/state-store/in-app-notifications-store.js.map +1 -0
  48. package/lib/commonjs/state-store/index.js +37 -0
  49. package/lib/commonjs/state-store/index.js.map +1 -0
  50. package/lib/commonjs/version.json +1 -1
  51. package/lib/module/components/Attachment/AudioAttachment.js +84 -209
  52. package/lib/module/components/Attachment/AudioAttachment.js.map +1 -1
  53. package/lib/module/components/Attachment/FileAttachmentGroup.js +8 -5
  54. package/lib/module/components/Attachment/FileAttachmentGroup.js.map +1 -1
  55. package/lib/module/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.js +7 -3
  56. package/lib/module/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.js.map +1 -1
  57. package/lib/module/components/Channel/Channel.js +20 -9
  58. package/lib/module/components/Channel/Channel.js.map +1 -1
  59. package/lib/module/components/Message/hooks/useMessageActionHandlers.js +4 -1
  60. package/lib/module/components/Message/hooks/useMessageActionHandlers.js.map +1 -1
  61. package/lib/module/components/MessageInput/MessageInput.js +2 -0
  62. package/lib/module/components/MessageInput/MessageInput.js.map +1 -1
  63. package/lib/module/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js +9 -3
  64. package/lib/module/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.js.map +1 -1
  65. package/lib/module/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.js +44 -8
  66. package/lib/module/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.js.map +1 -1
  67. package/lib/module/components/MessageInput/hooks/useAudioController.js +5 -0
  68. package/lib/module/components/MessageInput/hooks/useAudioController.js.map +1 -1
  69. package/lib/module/components/MessageInput/hooks/useAudioPreviewManager.js.map +1 -1
  70. package/lib/module/components/ProgressControl/ProgressControl.js +25 -33
  71. package/lib/module/components/ProgressControl/ProgressControl.js.map +1 -1
  72. package/lib/module/components/ProgressControl/WaveProgressBar.js +21 -29
  73. package/lib/module/components/ProgressControl/WaveProgressBar.js.map +1 -1
  74. package/lib/module/contexts/audioPlayerContext/AudioPlayerContext.js +56 -0
  75. package/lib/module/contexts/audioPlayerContext/AudioPlayerContext.js.map +1 -0
  76. package/lib/module/contexts/index.js +11 -0
  77. package/lib/module/contexts/index.js.map +1 -1
  78. package/lib/module/contexts/themeContext/utils/theme.js +4 -0
  79. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  80. package/lib/module/hooks/index.js +11 -0
  81. package/lib/module/hooks/index.js.map +1 -1
  82. package/lib/module/hooks/useAudioPlayer.js +18 -25
  83. package/lib/module/hooks/useAudioPlayer.js.map +1 -1
  84. package/lib/module/hooks/useAudioPlayerControl.js +43 -0
  85. package/lib/module/hooks/useAudioPlayerControl.js.map +1 -0
  86. package/lib/module/hooks/useInAppNotificationsState.js +1 -1
  87. package/lib/module/i18n/es.json +1 -2
  88. package/lib/module/i18n/he.json +5 -5
  89. package/lib/module/i18n/ru.json +0 -5
  90. package/lib/module/index.js +4 -4
  91. package/lib/module/index.js.map +1 -1
  92. package/lib/module/native.js.map +1 -1
  93. package/lib/module/state-store/audio-player-pool.js +99 -0
  94. package/lib/module/state-store/audio-player-pool.js.map +1 -0
  95. package/lib/module/state-store/audio-player.js +373 -0
  96. package/lib/module/state-store/audio-player.js.map +1 -0
  97. package/lib/module/state-store/in-app-notifications-store.js.map +1 -0
  98. package/lib/module/state-store/index.js +37 -0
  99. package/lib/module/state-store/index.js.map +1 -0
  100. package/lib/module/version.json +1 -1
  101. package/lib/typescript/components/Attachment/AudioAttachment.d.ts +25 -5
  102. package/lib/typescript/components/Attachment/AudioAttachment.d.ts.map +1 -1
  103. package/lib/typescript/components/Attachment/FileAttachmentGroup.d.ts +2 -1
  104. package/lib/typescript/components/Attachment/FileAttachmentGroup.d.ts.map +1 -1
  105. package/lib/typescript/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.d.ts.map +1 -1
  106. package/lib/typescript/components/Channel/Channel.d.ts +5 -0
  107. package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
  108. package/lib/typescript/components/Message/hooks/useMessageActionHandlers.d.ts.map +1 -1
  109. package/lib/typescript/components/MessageInput/MessageInput.d.ts.map +1 -1
  110. package/lib/typescript/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.d.ts +17 -0
  111. package/lib/typescript/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.d.ts.map +1 -1
  112. package/lib/typescript/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.d.ts +18 -4
  113. package/lib/typescript/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.d.ts.map +1 -1
  114. package/lib/typescript/components/MessageInput/hooks/useAudioController.d.ts +2 -0
  115. package/lib/typescript/components/MessageInput/hooks/useAudioController.d.ts.map +1 -1
  116. package/lib/typescript/components/MessageInput/hooks/useAudioPreviewManager.d.ts +2 -0
  117. package/lib/typescript/components/MessageInput/hooks/useAudioPreviewManager.d.ts.map +1 -1
  118. package/lib/typescript/components/ProgressControl/ProgressControl.d.ts +2 -0
  119. package/lib/typescript/components/ProgressControl/ProgressControl.d.ts.map +1 -1
  120. package/lib/typescript/components/ProgressControl/WaveProgressBar.d.ts.map +1 -1
  121. package/lib/typescript/contexts/audioPlayerContext/AudioPlayerContext.d.ts +15 -0
  122. package/lib/typescript/contexts/audioPlayerContext/AudioPlayerContext.d.ts.map +1 -0
  123. package/lib/typescript/contexts/index.d.ts +1 -0
  124. package/lib/typescript/contexts/index.d.ts.map +1 -1
  125. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +4 -0
  126. package/lib/typescript/contexts/themeContext/utils/theme.d.ts.map +1 -1
  127. package/lib/typescript/hooks/index.d.ts +1 -0
  128. package/lib/typescript/hooks/index.d.ts.map +1 -1
  129. package/lib/typescript/hooks/useAudioPlayer.d.ts +3 -1
  130. package/lib/typescript/hooks/useAudioPlayer.d.ts.map +1 -1
  131. package/lib/typescript/hooks/useAudioPlayerControl.d.ts +18 -0
  132. package/lib/typescript/hooks/useAudioPlayerControl.d.ts.map +1 -0
  133. package/lib/typescript/i18n/es.json +1 -2
  134. package/lib/typescript/i18n/he.json +5 -5
  135. package/lib/typescript/i18n/ru.json +0 -5
  136. package/lib/typescript/index.d.ts +1 -1
  137. package/lib/typescript/index.d.ts.map +1 -1
  138. package/lib/typescript/native.d.ts +1 -0
  139. package/lib/typescript/native.d.ts.map +1 -1
  140. package/lib/typescript/state-store/audio-player-pool.d.ts +24 -0
  141. package/lib/typescript/state-store/audio-player-pool.d.ts.map +1 -0
  142. package/lib/typescript/state-store/audio-player.d.ts +62 -0
  143. package/lib/typescript/state-store/audio-player.d.ts.map +1 -0
  144. package/lib/typescript/state-store/in-app-notifications-store.d.ts.map +1 -0
  145. package/lib/typescript/state-store/index.d.ts +4 -0
  146. package/lib/typescript/state-store/index.d.ts.map +1 -0
  147. package/package.json +6 -5
  148. package/src/components/Attachment/AudioAttachment.tsx +118 -198
  149. package/src/components/Attachment/FileAttachmentGroup.tsx +35 -16
  150. package/src/components/AttachmentPicker/components/AttachmentPickerBottomSheetHandle.tsx +5 -2
  151. package/src/components/Channel/Channel.tsx +21 -4
  152. package/src/components/Message/hooks/useMessageActionHandlers.ts +3 -1
  153. package/src/components/MessageInput/MessageInput.tsx +6 -0
  154. package/src/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.tsx +29 -2
  155. package/src/components/MessageInput/components/AudioRecorder/AudioRecordingPreview.tsx +73 -9
  156. package/src/components/MessageInput/hooks/useAudioController.tsx +62 -1
  157. package/src/components/MessageInput/hooks/useAudioPreviewManager.tsx +28 -5
  158. package/src/components/ProgressControl/ProgressControl.tsx +45 -47
  159. package/src/components/ProgressControl/WaveProgressBar.tsx +37 -36
  160. package/src/contexts/audioPlayerContext/AudioPlayerContext.tsx +55 -0
  161. package/src/contexts/index.ts +1 -0
  162. package/src/contexts/themeContext/utils/theme.ts +8 -0
  163. package/src/hooks/index.ts +1 -0
  164. package/src/hooks/useAudioPlayer.ts +7 -8
  165. package/src/hooks/useAudioPlayerControl.ts +59 -0
  166. package/src/hooks/useInAppNotificationsState.ts +2 -2
  167. package/src/i18n/es.json +1 -2
  168. package/src/i18n/he.json +5 -5
  169. package/src/i18n/ru.json +0 -5
  170. package/src/index.ts +1 -1
  171. package/src/native.ts +1 -0
  172. package/src/state-store/audio-player-pool.ts +94 -0
  173. package/src/state-store/audio-player.ts +372 -0
  174. package/src/state-store/index.ts +3 -0
  175. package/src/version.json +1 -1
  176. package/lib/commonjs/store/in-app-notifications-store.js.map +0 -1
  177. package/lib/commonjs/store/index.js +0 -15
  178. package/lib/commonjs/store/index.js.map +0 -1
  179. package/lib/module/store/in-app-notifications-store.js.map +0 -1
  180. package/lib/module/store/index.js +0 -15
  181. package/lib/module/store/index.js.map +0 -1
  182. package/lib/typescript/store/in-app-notifications-store.d.ts.map +0 -1
  183. package/lib/typescript/store/index.d.ts +0 -2
  184. package/lib/typescript/store/index.d.ts.map +0 -1
  185. package/src/store/index.ts +0 -1
  186. /package/lib/commonjs/{store → state-store}/in-app-notifications-store.js +0 -0
  187. /package/lib/module/{store → state-store}/in-app-notifications-store.js +0 -0
  188. /package/lib/typescript/{store → state-store}/in-app-notifications-store.d.ts +0 -0
  189. /package/src/{store → state-store}/in-app-notifications-store.ts +0 -0
@@ -0,0 +1,372 @@
1
+ import { StateStore } from 'stream-chat';
2
+
3
+ import { AudioPlayerPool } from './audio-player-pool';
4
+
5
+ import { AVPlaybackStatusToSet, NativeHandlers, PlaybackStatus, SoundReturnType } from '../native';
6
+
7
+ export type AudioDescriptor = {
8
+ id: string;
9
+ uri: string;
10
+ duration: number;
11
+ mimeType: string;
12
+ type: 'voiceRecording' | 'audio';
13
+ };
14
+
15
+ export type AudioPlayerState = {
16
+ isPlaying: boolean;
17
+ duration: number;
18
+ position: number;
19
+ progress: number;
20
+ currentPlaybackRate: number;
21
+ playbackRates: number[];
22
+ };
23
+
24
+ const DEFAULT_PLAYBACK_RATES = [1.0, 1.5, 2.0];
25
+
26
+ const DEFAULT_PLAYER_SETTINGS = {
27
+ pitchCorrectionQuality: 'high',
28
+ progressUpdateIntervalMillis: 100,
29
+ shouldCorrectPitch: true,
30
+ } as AVPlaybackStatusToSet;
31
+
32
+ const INITIAL_STATE: AudioPlayerState = {
33
+ currentPlaybackRate: 1.0,
34
+ duration: 0,
35
+ isPlaying: false,
36
+ playbackRates: DEFAULT_PLAYBACK_RATES,
37
+ position: 0,
38
+ progress: 0,
39
+ };
40
+
41
+ export type AudioPlayerOptions = AudioDescriptor & {
42
+ playbackRates?: number[];
43
+ previewVoiceRecording?: boolean;
44
+ };
45
+
46
+ export class AudioPlayer {
47
+ state: StateStore<AudioPlayerState>;
48
+ playerRef: SoundReturnType | null = null;
49
+ private _id: string;
50
+ private type: 'voiceRecording' | 'audio';
51
+ private isExpoCLI: boolean;
52
+ private _pool: AudioPlayerPool | null = null;
53
+
54
+ /**
55
+ * This is a temporary flag to manage audio player for voice recording in preview as the one in message list uses react-native-video.
56
+ * We can get rid of this when we migrate to the react-native-nitro-sound everywhere.
57
+ */
58
+ private previewVoiceRecording?: boolean;
59
+
60
+ constructor(options: AudioPlayerOptions) {
61
+ this.isExpoCLI = NativeHandlers.SDK === 'stream-chat-expo';
62
+ this._id = options.id;
63
+ this.type = options.type;
64
+ this.previewVoiceRecording = options.previewVoiceRecording ?? false;
65
+ const playbackRates = options.playbackRates ?? DEFAULT_PLAYBACK_RATES;
66
+ this.state = new StateStore<AudioPlayerState>({
67
+ ...INITIAL_STATE,
68
+ currentPlaybackRate: playbackRates[0],
69
+ duration: options.duration * 1000,
70
+ playbackRates,
71
+ });
72
+ this.initPlayer({ uri: options.uri });
73
+ }
74
+
75
+ // Initialize the expo player
76
+ // In the future we will also initialize the native cli player here.
77
+ initPlayer = async ({ uri, playerRef }: { uri?: string; playerRef?: SoundReturnType }) => {
78
+ if (playerRef) {
79
+ this.playerRef = playerRef;
80
+ return;
81
+ }
82
+ if (this.previewVoiceRecording) {
83
+ if (NativeHandlers.Audio?.startPlayer) {
84
+ await NativeHandlers.Audio.startPlayer(
85
+ uri,
86
+ {},
87
+ this.onVoiceRecordingPreviewPlaybackStatusUpdate,
88
+ );
89
+ if (NativeHandlers.Audio?.pausePlayer) {
90
+ await NativeHandlers.Audio.pausePlayer();
91
+ }
92
+ }
93
+ return;
94
+ }
95
+ if (!this.isExpoCLI || !uri) {
96
+ return;
97
+ }
98
+ if (NativeHandlers.Sound?.initializeSound) {
99
+ this.playerRef = await NativeHandlers.Sound?.initializeSound(
100
+ { uri },
101
+ DEFAULT_PLAYER_SETTINGS,
102
+ this.onPlaybackStatusUpdate,
103
+ );
104
+ }
105
+ };
106
+
107
+ private onVoiceRecordingPreviewPlaybackStatusUpdate = async (playbackStatus: PlaybackStatus) => {
108
+ const currentProgress = playbackStatus.currentPosition / playbackStatus.duration;
109
+ if (currentProgress === 1) {
110
+ await this.stop();
111
+ } else {
112
+ this.progress = currentProgress;
113
+ }
114
+ };
115
+
116
+ // This should be a arrow function to avoid binding the function to the instance
117
+ private onPlaybackStatusUpdate = async (playbackStatus: PlaybackStatus) => {
118
+ if (!playbackStatus.isLoaded) {
119
+ // Update your UI for the unloaded state
120
+ if (playbackStatus.error) {
121
+ console.log(`Encountered a fatal error during playback: ${playbackStatus.error}`);
122
+ }
123
+ } else {
124
+ const { durationMillis, positionMillis } = playbackStatus;
125
+ // Update your UI for the loaded state
126
+ // This is done for Expo CLI where we don't get file duration from file picker
127
+
128
+ if (this.type !== 'voiceRecording') {
129
+ this.duration = durationMillis;
130
+ }
131
+
132
+ // Update the position of the audio player when it is playing
133
+ if (playbackStatus.isPlaying) {
134
+ // The duration given by the expo-av is not same as the one of the voice recording, so we take the actual duration for voice recording.
135
+ const duration = this.type === 'voiceRecording' ? this.duration : durationMillis;
136
+ if (positionMillis <= duration) {
137
+ this.position = positionMillis;
138
+ }
139
+ }
140
+
141
+ // Update the UI when the audio is finished playing
142
+ if (playbackStatus.didJustFinish && !playbackStatus.isLooping) {
143
+ await this.stop();
144
+ }
145
+ }
146
+ };
147
+
148
+ // Getters
149
+ get isPlaying() {
150
+ return this.state.getLatestValue().isPlaying;
151
+ }
152
+
153
+ get duration() {
154
+ return this.state.getLatestValue().duration;
155
+ }
156
+
157
+ get position() {
158
+ return this.state.getLatestValue().position;
159
+ }
160
+
161
+ get progress() {
162
+ return this.state.getLatestValue().progress;
163
+ }
164
+
165
+ get playbackRates() {
166
+ return this.state.getLatestValue().playbackRates;
167
+ }
168
+
169
+ get currentPlaybackRate() {
170
+ return this.state.getLatestValue().currentPlaybackRate;
171
+ }
172
+
173
+ get id() {
174
+ return this._id;
175
+ }
176
+
177
+ // Setters
178
+ set pool(pool: AudioPlayerPool) {
179
+ this._pool = pool;
180
+ }
181
+
182
+ set duration(duration: number) {
183
+ this.state.partialNext({
184
+ duration,
185
+ });
186
+ }
187
+
188
+ set position(position: number) {
189
+ this.state.partialNext({
190
+ position,
191
+ progress: position / this.duration,
192
+ });
193
+ }
194
+
195
+ set progress(progress: number) {
196
+ this.state.partialNext({
197
+ position: progress * this.duration,
198
+ progress,
199
+ });
200
+ }
201
+
202
+ set isPlaying(isPlaying: boolean) {
203
+ this.state.partialNext({
204
+ isPlaying,
205
+ });
206
+ }
207
+
208
+ // Methods
209
+ async changePlaybackRate() {
210
+ let currentPlaybackRateIndex = this.state
211
+ .getLatestValue()
212
+ .playbackRates.indexOf(this.currentPlaybackRate);
213
+ if (currentPlaybackRateIndex === -1) {
214
+ currentPlaybackRateIndex = 0;
215
+ }
216
+ const nextPlayBackIndex =
217
+ currentPlaybackRateIndex === this.playbackRates.length - 1 ? 0 : currentPlaybackRateIndex + 1;
218
+ const nextPlaybackRate = this.playbackRates[nextPlayBackIndex];
219
+ this.state.partialNext({
220
+ currentPlaybackRate: nextPlaybackRate,
221
+ });
222
+ if (!this.playerRef) {
223
+ return;
224
+ }
225
+ if (this.playerRef?.setRateAsync) {
226
+ await this.playerRef.setRateAsync(nextPlaybackRate, true, 'high');
227
+ }
228
+ }
229
+
230
+ play() {
231
+ if (this.isPlaying) {
232
+ return;
233
+ }
234
+
235
+ if (this._pool) {
236
+ this._pool.requestPlay(this.id);
237
+ }
238
+
239
+ if (this.previewVoiceRecording) {
240
+ if (NativeHandlers.Audio?.resumePlayer) {
241
+ NativeHandlers.Audio.resumePlayer();
242
+ }
243
+ this.state.partialNext({
244
+ isPlaying: true,
245
+ });
246
+ return;
247
+ }
248
+
249
+ if (!this.playerRef) {
250
+ return;
251
+ }
252
+
253
+ if (this.isExpoCLI) {
254
+ if (this.playerRef?.playAsync) {
255
+ this.playerRef.playAsync();
256
+ }
257
+ } else {
258
+ if (this.playerRef?.resume) {
259
+ this.playerRef.resume();
260
+ }
261
+ }
262
+ this.state.partialNext({
263
+ isPlaying: true,
264
+ });
265
+ }
266
+
267
+ pause() {
268
+ if (!this.isPlaying) {
269
+ return;
270
+ }
271
+ if (this.previewVoiceRecording) {
272
+ if (NativeHandlers.Audio?.pausePlayer) {
273
+ NativeHandlers.Audio.pausePlayer();
274
+ }
275
+ this.state.partialNext({
276
+ isPlaying: false,
277
+ });
278
+ return;
279
+ }
280
+
281
+ if (!this.playerRef) {
282
+ return;
283
+ }
284
+
285
+ if (this.isExpoCLI) {
286
+ if (this.playerRef?.pauseAsync) {
287
+ this.playerRef.pauseAsync();
288
+ }
289
+ } else {
290
+ if (this.playerRef?.pause) {
291
+ this.playerRef.pause();
292
+ }
293
+ }
294
+ this.state.partialNext({
295
+ isPlaying: false,
296
+ });
297
+
298
+ if (this._pool) {
299
+ this._pool.notifyPaused();
300
+ }
301
+ }
302
+
303
+ toggle() {
304
+ if (this.isPlaying) {
305
+ this.pause();
306
+ } else {
307
+ this.play();
308
+ }
309
+ }
310
+
311
+ async seek(positionInSeconds: number) {
312
+ if (this.previewVoiceRecording) {
313
+ this.position = positionInSeconds;
314
+ if (NativeHandlers.Audio?.seekToPlayer) {
315
+ NativeHandlers.Audio.seekToPlayer(positionInSeconds * 1000);
316
+ }
317
+ return;
318
+ }
319
+ if (!this.playerRef) {
320
+ return;
321
+ }
322
+ this.position = positionInSeconds;
323
+ if (this.isExpoCLI) {
324
+ if (positionInSeconds === 0) {
325
+ // If currentTime is 0, we should replay the video from 0th position.
326
+ if (this.playerRef?.replayAsync) {
327
+ await this.playerRef.replayAsync({});
328
+ }
329
+ } else {
330
+ if (this.playerRef?.setPositionAsync) {
331
+ await this.playerRef.setPositionAsync(positionInSeconds);
332
+ }
333
+ }
334
+ } else {
335
+ if (this.playerRef?.seek) {
336
+ this.playerRef.seek(positionInSeconds);
337
+ }
338
+ }
339
+ }
340
+
341
+ async stop() {
342
+ // First seek to 0 to stop the audio and then pause it
343
+ await this.seek(0);
344
+ this.pause();
345
+ }
346
+
347
+ onRemove() {
348
+ if (this.previewVoiceRecording) {
349
+ if (NativeHandlers.Audio?.stopPlayer) {
350
+ NativeHandlers.Audio.stopPlayer();
351
+ }
352
+ this.state.partialNext({
353
+ ...INITIAL_STATE,
354
+ currentPlaybackRate: this.playbackRates[0],
355
+ playbackRates: DEFAULT_PLAYBACK_RATES,
356
+ });
357
+ return;
358
+ }
359
+ if (this.isExpoCLI) {
360
+ if (this.playerRef?.stopAsync && this.playerRef.unloadAsync) {
361
+ this.playerRef.stopAsync();
362
+ this.playerRef.unloadAsync();
363
+ }
364
+ }
365
+ this.playerRef = null;
366
+ this.state.partialNext({
367
+ ...INITIAL_STATE,
368
+ currentPlaybackRate: this.playbackRates[0],
369
+ playbackRates: DEFAULT_PLAYBACK_RATES,
370
+ });
371
+ }
372
+ }
@@ -0,0 +1,3 @@
1
+ export * from './audio-player';
2
+ export * from './in-app-notifications-store';
3
+ export * from './audio-player-pool';
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "8.10.1"
2
+ "version": "8.11.0-beta.3"
3
3
  }
@@ -1 +0,0 @@
1
- {"version":3,"names":["_streamChat","require","INITIAL_STATE","notifications","inAppNotificationsStore","exports","StateStore","openInAppNotification","notification","id","console","warn","_inAppNotificationsSt","getLatestValue","some","n","partialNext","concat","_toConsumableArray2","default","closeInAppNotification","_inAppNotificationsSt2","filter"],"sourceRoot":"../../../src","sources":["store/in-app-notifications-store.ts"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAMA,IAAMC,aAAsC,GAAG;EAC7CC,aAAa,EAAE;AACjB,CAAC;AAEM,IAAMC,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,IAAIE,sBAAU,CAA0BJ,aAAa,CAAC;AAEtF,IAAMK,qBAAqB,GAAAF,OAAA,CAAAE,qBAAA,GAAG,SAAxBA,qBAAqBA,CAAIC,YAA0B,EAAK;EACnE,IAAI,CAACA,YAAY,CAACC,EAAE,EAAE;IACpBC,OAAO,CAACC,IAAI,CAAC,4CAA4C,CAAC;IAC1D;EACF;EACA,IAAAC,qBAAA,GAA0BR,uBAAuB,CAACS,cAAc,CAAC,CAAC;IAA1DV,aAAa,GAAAS,qBAAA,CAAbT,aAAa;EAGrB,IAAIA,aAAa,CAACW,IAAI,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC,CAACN,EAAE,KAAKD,YAAY,CAACC,EAAE;EAAA,EAAC,EAAE;IACvDC,OAAO,CAACC,IAAI,CAAC,+CAA+C,CAAC;IAC7D;EACF;EAEAP,uBAAuB,CAACY,WAAW,CAAC;IAClCb,aAAa,KAAAc,MAAA,KAAAC,mBAAA,CAAAC,OAAA,EAAMhB,aAAa,IAAEK,YAAY;EAChD,CAAC,CAAC;AACJ,CAAC;AAEM,IAAMY,sBAAsB,GAAAf,OAAA,CAAAe,sBAAA,GAAG,SAAzBA,sBAAsBA,CAAIX,EAAU,EAAK;EACpD,IAAI,CAACA,EAAE,EAAE;IACPC,OAAO,CAACC,IAAI,CAAC,2CAA2C,CAAC;IACzD;EACF;EACA,IAAAU,sBAAA,GAA0BjB,uBAAuB,CAACS,cAAc,CAAC,CAAC;IAA1DV,aAAa,GAAAkB,sBAAA,CAAblB,aAAa;EACrBC,uBAAuB,CAACY,WAAW,CAAC;IAClCb,aAAa,EAAEA,aAAa,CAACmB,MAAM,CAAC,UAACd,YAAY;MAAA,OAAKA,YAAY,CAACC,EAAE,KAAKA,EAAE;IAAA;EAC9E,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -1,15 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", {
2
- value: true
3
- });
4
- var _inAppNotificationsStore = require("./in-app-notifications-store");
5
- Object.keys(_inAppNotificationsStore).forEach(function (key) {
6
- if (key === "default" || key === "__esModule") return;
7
- if (key in exports && exports[key] === _inAppNotificationsStore[key]) return;
8
- Object.defineProperty(exports, key, {
9
- enumerable: true,
10
- get: function get() {
11
- return _inAppNotificationsStore[key];
12
- }
13
- });
14
- });
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_inAppNotificationsStore","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../src","sources":["store/index.ts"],"mappings":";;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,wBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,wBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,wBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_streamChat","require","INITIAL_STATE","notifications","inAppNotificationsStore","exports","StateStore","openInAppNotification","notification","id","console","warn","_inAppNotificationsSt","getLatestValue","some","n","partialNext","concat","_toConsumableArray2","default","closeInAppNotification","_inAppNotificationsSt2","filter"],"sourceRoot":"../../../src","sources":["store/in-app-notifications-store.ts"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAMA,IAAMC,aAAsC,GAAG;EAC7CC,aAAa,EAAE;AACjB,CAAC;AAEM,IAAMC,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,IAAIE,sBAAU,CAA0BJ,aAAa,CAAC;AAEtF,IAAMK,qBAAqB,GAAAF,OAAA,CAAAE,qBAAA,GAAG,SAAxBA,qBAAqBA,CAAIC,YAA0B,EAAK;EACnE,IAAI,CAACA,YAAY,CAACC,EAAE,EAAE;IACpBC,OAAO,CAACC,IAAI,CAAC,4CAA4C,CAAC;IAC1D;EACF;EACA,IAAAC,qBAAA,GAA0BR,uBAAuB,CAACS,cAAc,CAAC,CAAC;IAA1DV,aAAa,GAAAS,qBAAA,CAAbT,aAAa;EAGrB,IAAIA,aAAa,CAACW,IAAI,CAAC,UAACC,CAAC;IAAA,OAAKA,CAAC,CAACN,EAAE,KAAKD,YAAY,CAACC,EAAE;EAAA,EAAC,EAAE;IACvDC,OAAO,CAACC,IAAI,CAAC,+CAA+C,CAAC;IAC7D;EACF;EAEAP,uBAAuB,CAACY,WAAW,CAAC;IAClCb,aAAa,KAAAc,MAAA,KAAAC,mBAAA,CAAAC,OAAA,EAAMhB,aAAa,IAAEK,YAAY;EAChD,CAAC,CAAC;AACJ,CAAC;AAEM,IAAMY,sBAAsB,GAAAf,OAAA,CAAAe,sBAAA,GAAG,SAAzBA,sBAAsBA,CAAIX,EAAU,EAAK;EACpD,IAAI,CAACA,EAAE,EAAE;IACPC,OAAO,CAACC,IAAI,CAAC,2CAA2C,CAAC;IACzD;EACF;EACA,IAAAU,sBAAA,GAA0BjB,uBAAuB,CAACS,cAAc,CAAC,CAAC;IAA1DV,aAAa,GAAAkB,sBAAA,CAAblB,aAAa;EACrBC,uBAAuB,CAACY,WAAW,CAAC;IAClCb,aAAa,EAAEA,aAAa,CAACmB,MAAM,CAAC,UAACd,YAAY;MAAA,OAAKA,YAAY,CAACC,EAAE,KAAKA,EAAE;IAAA;EAC9E,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -1,15 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", {
2
- value: true
3
- });
4
- var _inAppNotificationsStore = require("./in-app-notifications-store");
5
- Object.keys(_inAppNotificationsStore).forEach(function (key) {
6
- if (key === "default" || key === "__esModule") return;
7
- if (key in exports && exports[key] === _inAppNotificationsStore[key]) return;
8
- Object.defineProperty(exports, key, {
9
- enumerable: true,
10
- get: function get() {
11
- return _inAppNotificationsStore[key];
12
- }
13
- });
14
- });
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_inAppNotificationsStore","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../src","sources":["store/index.ts"],"mappings":";;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,wBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,wBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,wBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"in-app-notifications-store.d.ts","sourceRoot":"","sources":["../../../src/store/in-app-notifications-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AAMF,eAAO,MAAM,uBAAuB,qCAAyD,CAAC;AAE9F,eAAO,MAAM,qBAAqB,GAAI,cAAc,YAAY,SAgB/D,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,IAAI,MAAM,SAShD,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './in-app-notifications-store';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/store/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
@@ -1 +0,0 @@
1
- export * from './in-app-notifications-store';