@sendbird/uikit-react-native 3.10.3 → 3.11.1

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 (73) hide show
  1. package/README.md +9 -7
  2. package/lib/commonjs/components/ChannelInput/VoiceMessageInput.js +1 -1
  3. package/lib/commonjs/components/ChannelInput/VoiceMessageInput.js.map +1 -1
  4. package/lib/commonjs/components/ChannelInput/index.js +2 -25
  5. package/lib/commonjs/components/ChannelInput/index.js.map +1 -1
  6. package/lib/commonjs/hooks/useVoiceMessageInput.js +10 -2
  7. package/lib/commonjs/hooks/useVoiceMessageInput.js.map +1 -1
  8. package/lib/commonjs/platform/createFileService.native.js +1 -1
  9. package/lib/commonjs/platform/createFileService.native.js.map +1 -1
  10. package/lib/commonjs/platform/createMediaService.expo.js +83 -12
  11. package/lib/commonjs/platform/createMediaService.expo.js.map +1 -1
  12. package/lib/commonjs/platform/createPlayerService.expo.js +214 -113
  13. package/lib/commonjs/platform/createPlayerService.expo.js.map +1 -1
  14. package/lib/commonjs/platform/createPlayerService.native.js +191 -114
  15. package/lib/commonjs/platform/createPlayerService.native.js.map +1 -1
  16. package/lib/commonjs/platform/createRecorderService.expo.js +248 -127
  17. package/lib/commonjs/platform/createRecorderService.expo.js.map +1 -1
  18. package/lib/commonjs/platform/createRecorderService.native.js +212 -129
  19. package/lib/commonjs/platform/createRecorderService.native.js.map +1 -1
  20. package/lib/commonjs/platform/types.js.map +1 -1
  21. package/lib/commonjs/utils/expoBackwardUtils.js +23 -0
  22. package/lib/commonjs/utils/expoBackwardUtils.js.map +1 -1
  23. package/lib/commonjs/utils/expoPermissionGranted.js.map +1 -1
  24. package/lib/commonjs/version.js +1 -1
  25. package/lib/commonjs/version.js.map +1 -1
  26. package/lib/module/components/ChannelInput/VoiceMessageInput.js +1 -1
  27. package/lib/module/components/ChannelInput/VoiceMessageInput.js.map +1 -1
  28. package/lib/module/components/ChannelInput/index.js +3 -26
  29. package/lib/module/components/ChannelInput/index.js.map +1 -1
  30. package/lib/module/hooks/useVoiceMessageInput.js +10 -2
  31. package/lib/module/hooks/useVoiceMessageInput.js.map +1 -1
  32. package/lib/module/platform/createFileService.native.js +1 -1
  33. package/lib/module/platform/createFileService.native.js.map +1 -1
  34. package/lib/module/platform/createMediaService.expo.js +82 -13
  35. package/lib/module/platform/createMediaService.expo.js.map +1 -1
  36. package/lib/module/platform/createPlayerService.expo.js +214 -113
  37. package/lib/module/platform/createPlayerService.expo.js.map +1 -1
  38. package/lib/module/platform/createPlayerService.native.js +191 -114
  39. package/lib/module/platform/createPlayerService.native.js.map +1 -1
  40. package/lib/module/platform/createRecorderService.expo.js +249 -128
  41. package/lib/module/platform/createRecorderService.expo.js.map +1 -1
  42. package/lib/module/platform/createRecorderService.native.js +212 -129
  43. package/lib/module/platform/createRecorderService.native.js.map +1 -1
  44. package/lib/module/platform/types.js.map +1 -1
  45. package/lib/module/utils/expoBackwardUtils.js +23 -0
  46. package/lib/module/utils/expoBackwardUtils.js.map +1 -1
  47. package/lib/module/utils/expoPermissionGranted.js.map +1 -1
  48. package/lib/module/version.js +1 -1
  49. package/lib/module/version.js.map +1 -1
  50. package/lib/typescript/src/containers/SendbirdUIKitContainer.d.ts +1 -1
  51. package/lib/typescript/src/platform/createMediaService.expo.d.ts +2 -2
  52. package/lib/typescript/src/platform/createPlayerService.expo.d.ts +2 -2
  53. package/lib/typescript/src/platform/createPlayerService.native.d.ts +5 -3
  54. package/lib/typescript/src/platform/createRecorderService.expo.d.ts +2 -2
  55. package/lib/typescript/src/platform/createRecorderService.native.d.ts +5 -3
  56. package/lib/typescript/src/platform/types.d.ts +4 -0
  57. package/lib/typescript/src/utils/expoBackwardUtils.d.ts +10 -0
  58. package/lib/typescript/src/utils/expoPermissionGranted.d.ts +1 -1
  59. package/lib/typescript/src/version.d.ts +1 -1
  60. package/package.json +29 -5
  61. package/src/components/ChannelInput/VoiceMessageInput.tsx +1 -1
  62. package/src/components/ChannelInput/index.tsx +6 -36
  63. package/src/hooks/useVoiceMessageInput.ts +7 -2
  64. package/src/platform/createFileService.native.ts +1 -1
  65. package/src/platform/createMediaService.expo.tsx +87 -9
  66. package/src/platform/createPlayerService.expo.tsx +242 -109
  67. package/src/platform/createPlayerService.native.tsx +237 -113
  68. package/src/platform/createRecorderService.expo.tsx +268 -107
  69. package/src/platform/createRecorderService.native.tsx +240 -118
  70. package/src/platform/types.ts +5 -0
  71. package/src/utils/expoBackwardUtils.ts +29 -0
  72. package/src/utils/expoPermissionGranted.ts +3 -1
  73. package/src/version.ts +1 -1
@@ -2,148 +2,269 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  import { Platform } from 'react-native';
5
- import { matchesOneOf, sleep } from '@sendbird/uikit-utils';
5
+ import { Logger, matchesOneOf, sleep } from '@sendbird/uikit-utils';
6
6
  import VoiceMessageConfig from '../libs/VoiceMessageConfig';
7
+ import expoBackwardUtils from '../utils/expoBackwardUtils';
7
8
  import expoPermissionGranted from '../utils/expoPermissionGranted';
8
- const createExpoRecorderService = ({
9
- avModule
10
- }) => {
11
- class VoiceRecorder {
12
- constructor() {
13
- _defineProperty(this, "uri", undefined);
14
- _defineProperty(this, "state", 'idle');
15
- _defineProperty(this, "options", {
16
- minDuration: VoiceMessageConfig.DEFAULT.RECORDER.MIN_DURATION,
17
- maxDuration: VoiceMessageConfig.DEFAULT.RECORDER.MAX_DURATION,
18
- extension: VoiceMessageConfig.DEFAULT.RECORDER.EXTENSION
9
+ class BaseAudioRecorderAdapter {
10
+ constructor() {
11
+ _defineProperty(this, "uri", undefined);
12
+ _defineProperty(this, "state", 'idle');
13
+ _defineProperty(this, "options", {
14
+ minDuration: VoiceMessageConfig.DEFAULT.RECORDER.MIN_DURATION,
15
+ maxDuration: VoiceMessageConfig.DEFAULT.RECORDER.MAX_DURATION,
16
+ extension: VoiceMessageConfig.DEFAULT.RECORDER.EXTENSION
17
+ });
18
+ _defineProperty(this, "_audioSettings", {
19
+ sampleRate: VoiceMessageConfig.DEFAULT.RECORDER.SAMPLE_RATE,
20
+ bitRate: VoiceMessageConfig.DEFAULT.RECORDER.BIT_RATE,
21
+ numberOfChannels: VoiceMessageConfig.DEFAULT.RECORDER.CHANNELS
22
+ // encoding: mpeg4_aac
23
+ });
24
+ _defineProperty(this, "_recordingSubscribers", new Set());
25
+ _defineProperty(this, "_stateSubscribers", new Set());
26
+ // NOTE: In Android, even when startRecorder() is awaited, if stop() is executed immediately afterward, an error occurs
27
+ _defineProperty(this, "_recordStartedAt", 0);
28
+ _defineProperty(this, "_getRecorderStopSafeBuffer", () => {
29
+ const minWaitingTime = 500;
30
+ const elapsedTime = Date.now() - this._recordStartedAt;
31
+ if (elapsedTime > minWaitingTime) return 0;else return minWaitingTime - elapsedTime;
32
+ });
33
+ _defineProperty(this, "setState", state => {
34
+ this.state = state;
35
+ this._stateSubscribers.forEach(callback => {
36
+ callback(state);
19
37
  });
20
- // NOTE: In Android, even when startRecorder() is awaited, if stop() is executed immediately afterward, an error occurs
21
- _defineProperty(this, "_recordStartedAt", 0);
22
- _defineProperty(this, "_getRecorderStopSafeBuffer", () => {
23
- const minWaitingTime = 500;
24
- const elapsedTime = Date.now() - this._recordStartedAt;
25
- if (elapsedTime > minWaitingTime) return 0;else return minWaitingTime - elapsedTime;
26
- });
27
- _defineProperty(this, "_recorder", new avModule.Audio.Recording());
28
- _defineProperty(this, "_recordingSubscribers", new Set());
29
- _defineProperty(this, "_stateSubscribers", new Set());
30
- _defineProperty(this, "_audioSettings", {
31
- sampleRate: VoiceMessageConfig.DEFAULT.RECORDER.SAMPLE_RATE,
32
- bitRate: VoiceMessageConfig.DEFAULT.RECORDER.BIT_RATE,
33
- numberOfChannels: VoiceMessageConfig.DEFAULT.RECORDER.CHANNELS
34
- // encoding: mpeg4_aac
35
- });
36
- _defineProperty(this, "_audioOptions", {
37
- android: {
38
- ...this._audioSettings,
39
- extension: `.${this.options.extension}`,
40
- audioEncoder: avModule.Audio.AndroidAudioEncoder.AAC,
41
- outputFormat: avModule.Audio.AndroidOutputFormat.MPEG_4
42
- },
43
- ios: {
44
- ...this._audioSettings,
45
- extension: `.${this.options.extension}`,
46
- outputFormat: avModule.Audio.IOSOutputFormat.MPEG4AAC,
47
- audioQuality: avModule.Audio.IOSAudioQuality.HIGH
48
- },
49
- web: {}
38
+ });
39
+ _defineProperty(this, "addRecordingListener", callback => {
40
+ this._recordingSubscribers.add(callback);
41
+ return () => {
42
+ this._recordingSubscribers.delete(callback);
43
+ };
44
+ });
45
+ _defineProperty(this, "addStateListener", callback => {
46
+ this._stateSubscribers.add(callback);
47
+ return () => {
48
+ this._stateSubscribers.delete(callback);
49
+ };
50
+ });
51
+ _defineProperty(this, "convertRecordPath", uri => {
52
+ return uri;
53
+ });
54
+ }
55
+ }
56
+ class LegacyExpoAVRecorderAdapter extends BaseAudioRecorderAdapter {
57
+ constructor(avModule) {
58
+ super();
59
+ _defineProperty(this, "avModule", void 0);
60
+ _defineProperty(this, "_recorder", void 0);
61
+ _defineProperty(this, "_audioOptions", void 0);
62
+ _defineProperty(this, "prepare", async () => {
63
+ this.setState('preparing');
64
+ if (Platform.OS === 'ios') {
65
+ await this.avModule.Audio.setAudioModeAsync({
66
+ allowsRecordingIOS: true,
67
+ playsInSilentModeIOS: true
68
+ });
69
+ }
70
+ if (this._recorder._isDoneRecording) {
71
+ this._recorder = new this.avModule.Audio.Recording();
72
+ }
73
+ this._recorder.setProgressUpdateInterval(100);
74
+ this._recorder.setOnRecordingStatusUpdate(status => {
75
+ const completed = status.durationMillis >= this.options.maxDuration;
76
+ if (completed) this.stop();
77
+ if (status.isRecording) {
78
+ this._recordingSubscribers.forEach(callback => {
79
+ callback({
80
+ currentTime: status.durationMillis,
81
+ completed: completed
82
+ });
83
+ });
84
+ }
50
85
  });
51
- _defineProperty(this, "prepare", async () => {
52
- this.setState('preparing');
86
+ await this._recorder.prepareToRecordAsync(this._audioOptions);
87
+ });
88
+ _defineProperty(this, "requestPermission", async () => {
89
+ const status = await this.avModule.Audio.getPermissionsAsync();
90
+ if (expoPermissionGranted([status])) {
91
+ return true;
92
+ } else {
93
+ const status = await this.avModule.Audio.requestPermissionsAsync();
94
+ return expoPermissionGranted([status]);
95
+ }
96
+ });
97
+ _defineProperty(this, "record", async () => {
98
+ if (matchesOneOf(this.state, ['idle', 'completed'])) {
99
+ try {
100
+ await this.prepare();
101
+ await this._recorder.startAsync();
102
+ if (Platform.OS === 'android') {
103
+ this._recordStartedAt = Date.now();
104
+ }
105
+ const uri = this._recorder.getURI();
106
+ if (uri) this.uri = uri;
107
+ this.setState('recording');
108
+ } catch (e) {
109
+ this.setState('idle');
110
+ throw e;
111
+ }
112
+ }
113
+ });
114
+ _defineProperty(this, "stop", async () => {
115
+ if (matchesOneOf(this.state, ['recording'])) {
116
+ if (Platform.OS === 'android') {
117
+ const buffer = this._getRecorderStopSafeBuffer();
118
+ if (buffer > 0) await sleep(buffer);
119
+ }
120
+ await this._recorder.stopAndUnloadAsync();
53
121
  if (Platform.OS === 'ios') {
54
- await avModule.Audio.setAudioModeAsync({
55
- allowsRecordingIOS: true,
56
- playsInSilentModeIOS: true
122
+ await this.avModule.Audio.setAudioModeAsync({
123
+ allowsRecordingIOS: false,
124
+ playsInSilentModeIOS: false
57
125
  });
58
126
  }
59
- if (this._recorder._isDoneRecording) {
60
- this._recorder = new avModule.Audio.Recording();
61
- }
62
- this._recorder.setProgressUpdateInterval(100);
63
- this._recorder.setOnRecordingStatusUpdate(status => {
64
- const completed = status.durationMillis >= this.options.maxDuration;
65
- if (completed) this.stop();
66
- if (status.isRecording) {
67
- this._recordingSubscribers.forEach(callback => {
68
- callback({
69
- currentTime: status.durationMillis,
70
- completed: completed
71
- });
127
+ this.setState('completed');
128
+ }
129
+ });
130
+ _defineProperty(this, "reset", async () => {
131
+ await this.stop();
132
+ this.uri = undefined;
133
+ this._recordingSubscribers.clear();
134
+ this._recorder = new this.avModule.Audio.Recording();
135
+ this.setState('idle');
136
+ });
137
+ this.avModule = avModule;
138
+ this._recorder = new avModule.Audio.Recording();
139
+ this._audioOptions = {
140
+ android: {
141
+ ...this._audioSettings,
142
+ extension: `.${this.options.extension}`,
143
+ audioEncoder: avModule.Audio.AndroidAudioEncoder.AAC,
144
+ outputFormat: avModule.Audio.AndroidOutputFormat.MPEG_4
145
+ },
146
+ ios: {
147
+ ...this._audioSettings,
148
+ extension: `.${this.options.extension}`,
149
+ outputFormat: avModule.Audio.IOSOutputFormat.MPEG4AAC,
150
+ audioQuality: avModule.Audio.IOSAudioQuality.HIGH
151
+ },
152
+ web: {}
153
+ };
154
+ }
155
+ }
156
+ class ExpoAudioRecorderAdapter extends BaseAudioRecorderAdapter {
157
+ constructor(audioModule) {
158
+ super();
159
+ _defineProperty(this, "audioModule", void 0);
160
+ _defineProperty(this, "recorder", null);
161
+ _defineProperty(this, "recordingUpdateInterval", null);
162
+ _defineProperty(this, "setListener", () => {
163
+ if (!this.recorder) return;
164
+ this.recordingUpdateInterval = setInterval(() => {
165
+ if (this.recorder && this.recorder.isRecording) {
166
+ const currentTime = this.recorder.currentTime * 1000;
167
+ const completed = currentTime >= this.options.maxDuration;
168
+ if (completed) {
169
+ this.stop().catch(error => {
170
+ Logger.warn('[RecorderService.Expo] Failed to stop in update interval', error);
72
171
  });
73
172
  }
74
- });
75
- await this._recorder.prepareToRecordAsync(this._audioOptions);
76
- });
77
- _defineProperty(this, "setState", state => {
78
- this.state = state;
79
- this._stateSubscribers.forEach(callback => {
80
- callback(state);
81
- });
82
- });
83
- _defineProperty(this, "requestPermission", async () => {
84
- const status = await avModule.Audio.getPermissionsAsync();
85
- if (expoPermissionGranted([status])) {
86
- return true;
87
- } else {
88
- const status = await avModule.Audio.requestPermissionsAsync();
89
- return expoPermissionGranted([status]);
90
- }
91
- });
92
- _defineProperty(this, "addRecordingListener", callback => {
93
- this._recordingSubscribers.add(callback);
94
- return () => {
95
- this._recordingSubscribers.delete(callback);
96
- };
97
- });
98
- _defineProperty(this, "addStateListener", callback => {
99
- this._stateSubscribers.add(callback);
100
- return () => {
101
- this._stateSubscribers.delete(callback);
102
- };
103
- });
104
- _defineProperty(this, "record", async () => {
105
- if (matchesOneOf(this.state, ['idle', 'completed'])) {
106
- try {
107
- await this.prepare();
108
- await this._recorder.startAsync();
109
- if (Platform.OS === 'android') {
110
- this._recordStartedAt = Date.now();
111
- }
112
- const uri = this._recorder.getURI();
113
- if (uri) this.uri = uri;
114
- this.setState('recording');
115
- } catch (e) {
116
- this.setState('idle');
117
- throw e;
118
- }
173
+ this._recordingSubscribers.forEach(callback => {
174
+ callback({
175
+ currentTime,
176
+ completed
177
+ });
178
+ });
119
179
  }
120
- });
121
- _defineProperty(this, "stop", async () => {
122
- if (matchesOneOf(this.state, ['recording'])) {
180
+ }, 100);
181
+ });
182
+ _defineProperty(this, "removeListener", () => {
183
+ if (this.recordingUpdateInterval) {
184
+ clearInterval(this.recordingUpdateInterval);
185
+ this.recordingUpdateInterval = null;
186
+ }
187
+ });
188
+ _defineProperty(this, "prepare", async () => {
189
+ this.setState('preparing');
190
+ if (Platform.OS === 'ios') {
191
+ await this.audioModule.setAudioModeAsync({
192
+ allowsRecording: true,
193
+ playsInSilentMode: true
194
+ });
195
+ }
196
+ const recordingOptions = {
197
+ ...this._audioSettings,
198
+ extension: `.${this.options.extension}`
199
+ };
200
+ this.recorder = new this.audioModule.AudioModule.AudioRecorder(recordingOptions);
201
+ await this.recorder.prepareToRecordAsync();
202
+ });
203
+ _defineProperty(this, "requestPermission", async () => {
204
+ const status = await this.audioModule.getRecordingPermissionsAsync();
205
+ if (expoPermissionGranted([status])) {
206
+ return true;
207
+ } else {
208
+ const status = await this.audioModule.requestRecordingPermissionsAsync();
209
+ return expoPermissionGranted([status]);
210
+ }
211
+ });
212
+ _defineProperty(this, "record", async () => {
213
+ if (matchesOneOf(this.state, ['idle', 'completed'])) {
214
+ try {
215
+ var _this$recorder, _this$recorder2;
216
+ await this.prepare();
217
+ this.setListener();
218
+ (_this$recorder = this.recorder) === null || _this$recorder === void 0 || _this$recorder.record();
123
219
  if (Platform.OS === 'android') {
124
- const buffer = this._getRecorderStopSafeBuffer();
125
- if (buffer > 0) await sleep(buffer);
126
- }
127
- await this._recorder.stopAndUnloadAsync();
128
- if (Platform.OS === 'ios') {
129
- await avModule.Audio.setAudioModeAsync({
130
- allowsRecordingIOS: false,
131
- playsInSilentModeIOS: false
132
- });
220
+ this._recordStartedAt = Date.now();
133
221
  }
134
- this.setState('completed');
222
+ const uri = (_this$recorder2 = this.recorder) === null || _this$recorder2 === void 0 ? void 0 : _this$recorder2.uri;
223
+ if (uri) this.uri = uri;
224
+ this.setState('recording');
225
+ } catch (e) {
226
+ this.setState('idle');
227
+ this.removeListener();
228
+ throw e;
135
229
  }
136
- });
137
- _defineProperty(this, "reset", async () => {
138
- await this.stop();
139
- this.uri = undefined;
140
- this._recordingSubscribers.clear();
141
- this._recorder = new avModule.Audio.Recording();
142
- this.setState('idle');
143
- });
144
- }
230
+ }
231
+ });
232
+ _defineProperty(this, "stop", async () => {
233
+ if (matchesOneOf(this.state, ['recording'])) {
234
+ var _this$recorder3;
235
+ if (Platform.OS === 'android') {
236
+ const buffer = this._getRecorderStopSafeBuffer();
237
+ if (buffer > 0) await sleep(buffer);
238
+ }
239
+ await ((_this$recorder3 = this.recorder) === null || _this$recorder3 === void 0 ? void 0 : _this$recorder3.stop());
240
+ this.removeListener();
241
+ if (Platform.OS === 'ios') {
242
+ await this.audioModule.setAudioModeAsync({
243
+ allowsRecording: false,
244
+ playsInSilentMode: false
245
+ });
246
+ }
247
+ this.setState('completed');
248
+ }
249
+ });
250
+ _defineProperty(this, "reset", async () => {
251
+ await this.stop();
252
+ this.recorder = null;
253
+ this.uri = undefined;
254
+ this._recordingSubscribers.clear();
255
+ this._stateSubscribers.clear();
256
+ this.setState('idle');
257
+ });
258
+ this.audioModule = audioModule;
259
+ }
260
+ }
261
+ const createExpoRecorderService = ({
262
+ avModule
263
+ }) => {
264
+ if (expoBackwardUtils.expoAV.isLegacyAVModule(avModule)) {
265
+ Logger.warn('[RecorderService.Expo] expo-av is deprecated and will be removed in Expo 54. Please migrate to expo-audio.');
145
266
  }
146
- return new VoiceRecorder();
267
+ return expoBackwardUtils.expoAV.isAudioModule(avModule) ? new ExpoAudioRecorderAdapter(avModule) : new LegacyExpoAVRecorderAdapter(avModule);
147
268
  };
148
269
  export default createExpoRecorderService;
149
270
  //# sourceMappingURL=createRecorderService.expo.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","matchesOneOf","sleep","VoiceMessageConfig","expoPermissionGranted","createExpoRecorderService","avModule","VoiceRecorder","constructor","_defineProperty","undefined","minDuration","DEFAULT","RECORDER","MIN_DURATION","maxDuration","MAX_DURATION","extension","EXTENSION","minWaitingTime","elapsedTime","Date","now","_recordStartedAt","Audio","Recording","Set","sampleRate","SAMPLE_RATE","bitRate","BIT_RATE","numberOfChannels","CHANNELS","android","_audioSettings","options","audioEncoder","AndroidAudioEncoder","AAC","outputFormat","AndroidOutputFormat","MPEG_4","ios","IOSOutputFormat","MPEG4AAC","audioQuality","IOSAudioQuality","HIGH","web","setState","OS","setAudioModeAsync","allowsRecordingIOS","playsInSilentModeIOS","_recorder","_isDoneRecording","setProgressUpdateInterval","setOnRecordingStatusUpdate","status","completed","durationMillis","stop","isRecording","_recordingSubscribers","forEach","callback","currentTime","prepareToRecordAsync","_audioOptions","state","_stateSubscribers","getPermissionsAsync","requestPermissionsAsync","add","delete","prepare","startAsync","uri","getURI","e","buffer","_getRecorderStopSafeBuffer","stopAndUnloadAsync","clear"],"sources":["createRecorderService.expo.tsx"],"sourcesContent":["import * as ExpoAV from 'expo-av';\nimport type { RecordingOptions } from 'expo-av/build/Audio/Recording.types';\nimport { Platform } from 'react-native';\n\nimport { matchesOneOf, sleep } from '@sendbird/uikit-utils';\n\nimport VoiceMessageConfig from '../libs/VoiceMessageConfig';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport type { RecorderServiceInterface, Unsubscribe } from './types';\n\ntype RecordingListener = Parameters<RecorderServiceInterface['addRecordingListener']>[number];\ntype StateListener = Parameters<RecorderServiceInterface['addStateListener']>[number];\ntype Modules = {\n avModule: typeof ExpoAV;\n};\nconst createExpoRecorderService = ({ avModule }: Modules): RecorderServiceInterface => {\n class VoiceRecorder implements RecorderServiceInterface {\n public uri: RecorderServiceInterface['uri'] = undefined;\n public state: RecorderServiceInterface['state'] = 'idle';\n public options: RecorderServiceInterface['options'] = {\n minDuration: VoiceMessageConfig.DEFAULT.RECORDER.MIN_DURATION,\n maxDuration: VoiceMessageConfig.DEFAULT.RECORDER.MAX_DURATION,\n extension: VoiceMessageConfig.DEFAULT.RECORDER.EXTENSION,\n };\n\n // NOTE: In Android, even when startRecorder() is awaited, if stop() is executed immediately afterward, an error occurs\n private _recordStartedAt = 0;\n private _getRecorderStopSafeBuffer = () => {\n const minWaitingTime = 500;\n const elapsedTime = Date.now() - this._recordStartedAt;\n if (elapsedTime > minWaitingTime) return 0;\n else return minWaitingTime - elapsedTime;\n };\n\n private _recorder = new avModule.Audio.Recording();\n private readonly _recordingSubscribers = new Set<RecordingListener>();\n private readonly _stateSubscribers = new Set<StateListener>();\n private readonly _audioSettings = {\n sampleRate: VoiceMessageConfig.DEFAULT.RECORDER.SAMPLE_RATE,\n bitRate: VoiceMessageConfig.DEFAULT.RECORDER.BIT_RATE,\n numberOfChannels: VoiceMessageConfig.DEFAULT.RECORDER.CHANNELS,\n // encoding: mpeg4_aac\n };\n private readonly _audioOptions: RecordingOptions = {\n android: {\n ...this._audioSettings,\n extension: `.${this.options.extension}`,\n audioEncoder: avModule.Audio.AndroidAudioEncoder.AAC,\n outputFormat: avModule.Audio.AndroidOutputFormat.MPEG_4,\n },\n ios: {\n ...this._audioSettings,\n extension: `.${this.options.extension}`,\n outputFormat: avModule.Audio.IOSOutputFormat.MPEG4AAC,\n audioQuality: avModule.Audio.IOSAudioQuality.HIGH,\n },\n web: {},\n };\n\n private prepare = async () => {\n this.setState('preparing');\n if (Platform.OS === 'ios') {\n await avModule.Audio.setAudioModeAsync({ allowsRecordingIOS: true, playsInSilentModeIOS: true });\n }\n\n if (this._recorder._isDoneRecording) {\n this._recorder = new avModule.Audio.Recording();\n }\n this._recorder.setProgressUpdateInterval(100);\n this._recorder.setOnRecordingStatusUpdate((status) => {\n const completed = status.durationMillis >= this.options.maxDuration;\n if (completed) this.stop();\n if (status.isRecording) {\n this._recordingSubscribers.forEach((callback) => {\n callback({ currentTime: status.durationMillis, completed: completed });\n });\n }\n });\n await this._recorder.prepareToRecordAsync(this._audioOptions);\n };\n\n private setState = (state: RecorderServiceInterface['state']) => {\n this.state = state;\n this._stateSubscribers.forEach((callback) => {\n callback(state);\n });\n };\n\n public requestPermission = async (): Promise<boolean> => {\n const status = await avModule.Audio.getPermissionsAsync();\n if (expoPermissionGranted([status])) {\n return true;\n } else {\n const status = await avModule.Audio.requestPermissionsAsync();\n return expoPermissionGranted([status]);\n }\n };\n\n public addRecordingListener = (callback: RecordingListener): Unsubscribe => {\n this._recordingSubscribers.add(callback);\n return () => {\n this._recordingSubscribers.delete(callback);\n };\n };\n\n public addStateListener = (callback: StateListener): Unsubscribe => {\n this._stateSubscribers.add(callback);\n return () => {\n this._stateSubscribers.delete(callback);\n };\n };\n\n public record = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['idle', 'completed'])) {\n try {\n await this.prepare();\n await this._recorder.startAsync();\n\n if (Platform.OS === 'android') {\n this._recordStartedAt = Date.now();\n }\n\n const uri = this._recorder.getURI();\n if (uri) this.uri = uri;\n this.setState('recording');\n } catch (e) {\n this.setState('idle');\n throw e;\n }\n }\n };\n\n public stop = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['recording'])) {\n if (Platform.OS === 'android') {\n const buffer = this._getRecorderStopSafeBuffer();\n if (buffer > 0) await sleep(buffer);\n }\n\n await this._recorder.stopAndUnloadAsync();\n if (Platform.OS === 'ios') {\n await avModule.Audio.setAudioModeAsync({ allowsRecordingIOS: false, playsInSilentModeIOS: false });\n }\n this.setState('completed');\n }\n };\n\n public reset = async (): Promise<void> => {\n await this.stop();\n this.uri = undefined;\n this._recordingSubscribers.clear();\n this._recorder = new avModule.Audio.Recording();\n this.setState('idle');\n };\n }\n\n return new VoiceRecorder();\n};\n\nexport default createExpoRecorderService;\n"],"mappings":";;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,YAAY,EAAEC,KAAK,QAAQ,uBAAuB;AAE3D,OAAOC,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,qBAAqB,MAAM,gCAAgC;AAQlE,MAAMC,yBAAyB,GAAGA,CAAC;EAAEC;AAAkB,CAAC,KAA+B;EACrF,MAAMC,aAAa,CAAqC;IAAAC,YAAA;MAAAC,eAAA,cACRC,SAAS;MAAAD,eAAA,gBACL,MAAM;MAAAA,eAAA,kBACF;QACpDE,WAAW,EAAER,kBAAkB,CAACS,OAAO,CAACC,QAAQ,CAACC,YAAY;QAC7DC,WAAW,EAAEZ,kBAAkB,CAACS,OAAO,CAACC,QAAQ,CAACG,YAAY;QAC7DC,SAAS,EAAEd,kBAAkB,CAACS,OAAO,CAACC,QAAQ,CAACK;MACjD,CAAC;MAED;MAAAT,eAAA,2BAC2B,CAAC;MAAAA,eAAA,qCACS,MAAM;QACzC,MAAMU,cAAc,GAAG,GAAG;QAC1B,MAAMC,WAAW,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,CAACC,gBAAgB;QACtD,IAAIH,WAAW,GAAGD,cAAc,EAAE,OAAO,CAAC,CAAC,KACtC,OAAOA,cAAc,GAAGC,WAAW;MAC1C,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IAAIrE,QAAQ,CAACkD,EAAE,KAAK,SAAS,EAAE;YAC7B,MAAM8B,MAAM,GAAG,IAAI,CAACC,0BAA0B,CAAC,CAAC;YAChD,IAAID,MAAM,GAAG,CAAC,EAAE,MAAM9E,KAAK,CAAC8E,MAAM,CAAC;UACrC;UAEA,MAAM,IAAI,CAAC1B,SAAS,CAAC4B,kBAAkB,CAAC,CAAC;UACzC,IAAIlF,QAAQ,CAACkD,EAAE,KAAK,KAAK,EAAE;YACzB,MAAM5C,QAAQ,CAACkB,KAAK,CAAC2B,iBAAiB,CAAC;cAAEC,kBAAkB,EAAE,KAAK;cAAEC,oBAAoB,EAAE;YAAM,CAAC,CAAC;UACpG;UACA,IAAI,CAACJ,QAAQ,CAAC,WAAW,CAAC;QAC5B;MACF,CAAC;MAAAxC,eAAA,gBAEc,YAA2B;QACxC,MAAM,IAAI,CAACoD,IAAI,CAAC,CAAC;QACjB,IAAI,CAACgB,GAAG,GAAGnE,SAAS;QACpB,IAAI,CAACqD,qBAAqB,CAACoB,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC7B,SAAS,GAAG,IAAIhD,QAAQ,CAACkB,KAAK,CAACC,SAAS,CAAC,CAAC;QAC/C,IAAI,CAACwB,QAAQ,CAAC,MAAM,CAAC;MACvB,CAAC;IAAA;EACH;EAEA,OAAO,IAAI1C,aAAa,CAAC,CAAC;AAC5B,CAAC;AAED,eAAeF,yBAAyB","ignoreList":[]}
1
+ {"version":3,"names":["Platform","Logger","matchesOneOf","sleep","VoiceMessageConfig","expoBackwardUtils","expoPermissionGranted","BaseAudioRecorderAdapter","constructor","_defineProperty","undefined","minDuration","DEFAULT","RECORDER","MIN_DURATION","maxDuration","MAX_DURATION","extension","EXTENSION","sampleRate","SAMPLE_RATE","bitRate","BIT_RATE","numberOfChannels","CHANNELS","Set","minWaitingTime","elapsedTime","Date","now","_recordStartedAt","state","_stateSubscribers","forEach","callback","_recordingSubscribers","add","delete","uri","LegacyExpoAVRecorderAdapter","avModule","setState","OS","Audio","setAudioModeAsync","allowsRecordingIOS","playsInSilentModeIOS","_recorder","_isDoneRecording","Recording","setProgressUpdateInterval","setOnRecordingStatusUpdate","status","completed","durationMillis","options","stop","isRecording","currentTime","prepareToRecordAsync","_audioOptions","getPermissionsAsync","requestPermissionsAsync","prepare","startAsync","getURI","e","buffer","_getRecorderStopSafeBuffer","stopAndUnloadAsync","clear","android","_audioSettings","audioEncoder","AndroidAudioEncoder","AAC","outputFormat","AndroidOutputFormat","MPEG_4","ios","IOSOutputFormat","MPEG4AAC","audioQuality","IOSAudioQuality","HIGH","web","ExpoAudioRecorderAdapter","audioModule","recorder","recordingUpdateInterval","setInterval","catch","error","warn","clearInterval","allowsRecording","playsInSilentMode","recordingOptions","AudioModule","AudioRecorder","getRecordingPermissionsAsync","requestRecordingPermissionsAsync","_this$recorder","_this$recorder2","setListener","record","removeListener","_this$recorder3","createExpoRecorderService","expoAV","isLegacyAVModule","isAudioModule"],"sources":["createRecorderService.expo.tsx"],"sourcesContent":["import type * as ExpoAudio from 'expo-audio';\nimport type * as ExpoAV from 'expo-av';\nimport { Platform } from 'react-native';\n\nimport { Logger, matchesOneOf, sleep } from '@sendbird/uikit-utils';\n\nimport VoiceMessageConfig from '../libs/VoiceMessageConfig';\nimport expoBackwardUtils from '../utils/expoBackwardUtils';\nimport type { ExpoAudioModule } from '../utils/expoBackwardUtils';\nimport expoPermissionGranted from '../utils/expoPermissionGranted';\nimport type { RecorderServiceInterface, Unsubscribe } from './types';\n\ntype RecordingListener = Parameters<RecorderServiceInterface['addRecordingListener']>[number];\ntype StateListener = Parameters<RecorderServiceInterface['addStateListener']>[number];\ntype Modules = {\n avModule: ExpoAudioModule;\n};\n\ninterface AudioRecorderAdapter {\n requestPermission(): Promise<boolean>;\n record(): Promise<void>;\n stop(): Promise<void>;\n reset(): Promise<void>;\n addRecordingListener(callback: RecordingListener): Unsubscribe;\n addStateListener(callback: StateListener): Unsubscribe;\n convertRecordPath(uri: string): string;\n readonly state: RecorderServiceInterface['state'];\n readonly options: RecorderServiceInterface['options'];\n uri?: string;\n}\n\nabstract class BaseAudioRecorderAdapter implements AudioRecorderAdapter {\n public uri: RecorderServiceInterface['uri'] = undefined;\n public state: RecorderServiceInterface['state'] = 'idle';\n public options: RecorderServiceInterface['options'] = {\n minDuration: VoiceMessageConfig.DEFAULT.RECORDER.MIN_DURATION,\n maxDuration: VoiceMessageConfig.DEFAULT.RECORDER.MAX_DURATION,\n extension: VoiceMessageConfig.DEFAULT.RECORDER.EXTENSION,\n };\n\n protected readonly _audioSettings = {\n sampleRate: VoiceMessageConfig.DEFAULT.RECORDER.SAMPLE_RATE,\n bitRate: VoiceMessageConfig.DEFAULT.RECORDER.BIT_RATE,\n numberOfChannels: VoiceMessageConfig.DEFAULT.RECORDER.CHANNELS,\n // encoding: mpeg4_aac\n };\n protected readonly _recordingSubscribers = new Set<RecordingListener>();\n protected readonly _stateSubscribers = new Set<StateListener>();\n\n // NOTE: In Android, even when startRecorder() is awaited, if stop() is executed immediately afterward, an error occurs\n protected _recordStartedAt = 0;\n protected _getRecorderStopSafeBuffer = () => {\n const minWaitingTime = 500;\n const elapsedTime = Date.now() - this._recordStartedAt;\n if (elapsedTime > minWaitingTime) return 0;\n else return minWaitingTime - elapsedTime;\n };\n protected setState = (state: RecorderServiceInterface['state']) => {\n this.state = state;\n this._stateSubscribers.forEach((callback) => {\n callback(state);\n });\n };\n\n public addRecordingListener = (callback: RecordingListener): Unsubscribe => {\n this._recordingSubscribers.add(callback);\n return () => {\n this._recordingSubscribers.delete(callback);\n };\n };\n\n public addStateListener = (callback: StateListener): Unsubscribe => {\n this._stateSubscribers.add(callback);\n return () => {\n this._stateSubscribers.delete(callback);\n };\n };\n\n public convertRecordPath = (uri: string): string => {\n return uri;\n };\n\n abstract requestPermission(): Promise<boolean>;\n abstract record(): Promise<void>;\n abstract stop(): Promise<void>;\n abstract reset(): Promise<void>;\n}\n\nclass LegacyExpoAVRecorderAdapter extends BaseAudioRecorderAdapter {\n private readonly avModule: typeof ExpoAV;\n\n private _recorder: ExpoAV.Audio.Recording;\n private readonly _audioOptions: ExpoAV.Audio.RecordingOptions;\n\n constructor(avModule: typeof ExpoAV) {\n super();\n this.avModule = avModule;\n this._recorder = new avModule.Audio.Recording();\n this._audioOptions = {\n android: {\n ...this._audioSettings,\n extension: `.${this.options.extension}`,\n audioEncoder: avModule.Audio.AndroidAudioEncoder.AAC,\n outputFormat: avModule.Audio.AndroidOutputFormat.MPEG_4,\n },\n ios: {\n ...this._audioSettings,\n extension: `.${this.options.extension}`,\n outputFormat: avModule.Audio.IOSOutputFormat.MPEG4AAC,\n audioQuality: avModule.Audio.IOSAudioQuality.HIGH,\n },\n web: {},\n };\n }\n\n private prepare = async () => {\n this.setState('preparing');\n if (Platform.OS === 'ios') {\n await this.avModule.Audio.setAudioModeAsync({ allowsRecordingIOS: true, playsInSilentModeIOS: true });\n }\n\n if (this._recorder._isDoneRecording) {\n this._recorder = new this.avModule.Audio.Recording();\n }\n this._recorder.setProgressUpdateInterval(100);\n this._recorder.setOnRecordingStatusUpdate((status) => {\n const completed = status.durationMillis >= this.options.maxDuration;\n if (completed) this.stop();\n if (status.isRecording) {\n this._recordingSubscribers.forEach((callback) => {\n callback({ currentTime: status.durationMillis, completed: completed });\n });\n }\n });\n await this._recorder.prepareToRecordAsync(this._audioOptions);\n };\n\n public requestPermission = async (): Promise<boolean> => {\n const status = await this.avModule.Audio.getPermissionsAsync();\n if (expoPermissionGranted([status])) {\n return true;\n } else {\n const status = await this.avModule.Audio.requestPermissionsAsync();\n return expoPermissionGranted([status]);\n }\n };\n\n public record = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['idle', 'completed'])) {\n try {\n await this.prepare();\n await this._recorder.startAsync();\n\n if (Platform.OS === 'android') {\n this._recordStartedAt = Date.now();\n }\n\n const uri = this._recorder.getURI();\n if (uri) this.uri = uri;\n this.setState('recording');\n } catch (e) {\n this.setState('idle');\n throw e;\n }\n }\n };\n\n public stop = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['recording'])) {\n if (Platform.OS === 'android') {\n const buffer = this._getRecorderStopSafeBuffer();\n if (buffer > 0) await sleep(buffer);\n }\n\n await this._recorder.stopAndUnloadAsync();\n if (Platform.OS === 'ios') {\n await this.avModule.Audio.setAudioModeAsync({ allowsRecordingIOS: false, playsInSilentModeIOS: false });\n }\n this.setState('completed');\n }\n };\n\n public reset = async (): Promise<void> => {\n await this.stop();\n this.uri = undefined;\n this._recordingSubscribers.clear();\n this._recorder = new this.avModule.Audio.Recording();\n this.setState('idle');\n };\n}\n\nclass ExpoAudioRecorderAdapter extends BaseAudioRecorderAdapter {\n private readonly audioModule: typeof ExpoAudio;\n private recorder: ExpoAudio.AudioRecorder | null = null;\n private recordingUpdateInterval: NodeJS.Timeout | null = null;\n\n constructor(audioModule: typeof ExpoAudio) {\n super();\n this.audioModule = audioModule;\n }\n\n private setListener = () => {\n if (!this.recorder) return;\n\n this.recordingUpdateInterval = setInterval(() => {\n if (this.recorder && this.recorder.isRecording) {\n const currentTime = this.recorder.currentTime * 1000;\n const completed = currentTime >= this.options.maxDuration;\n\n if (completed) {\n this.stop().catch((error) => {\n Logger.warn('[RecorderService.Expo] Failed to stop in update interval', error);\n });\n }\n\n this._recordingSubscribers.forEach((callback) => {\n callback({ currentTime, completed });\n });\n }\n }, 100);\n };\n\n private removeListener = () => {\n if (this.recordingUpdateInterval) {\n clearInterval(this.recordingUpdateInterval);\n this.recordingUpdateInterval = null;\n }\n };\n\n private prepare = async () => {\n this.setState('preparing');\n if (Platform.OS === 'ios') {\n await this.audioModule.setAudioModeAsync({\n allowsRecording: true,\n playsInSilentMode: true,\n });\n }\n\n const recordingOptions = {\n ...this._audioSettings,\n extension: `.${this.options.extension}`,\n };\n\n this.recorder = new this.audioModule.AudioModule.AudioRecorder(recordingOptions);\n await this.recorder.prepareToRecordAsync();\n };\n\n public requestPermission = async (): Promise<boolean> => {\n const status = await this.audioModule.getRecordingPermissionsAsync();\n if (expoPermissionGranted([status])) {\n return true;\n } else {\n const status = await this.audioModule.requestRecordingPermissionsAsync();\n return expoPermissionGranted([status]);\n }\n };\n\n public record = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['idle', 'completed'])) {\n try {\n await this.prepare();\n this.setListener();\n this.recorder?.record();\n\n if (Platform.OS === 'android') {\n this._recordStartedAt = Date.now();\n }\n\n const uri = this.recorder?.uri;\n if (uri) this.uri = uri;\n this.setState('recording');\n } catch (e) {\n this.setState('idle');\n this.removeListener();\n throw e;\n }\n }\n };\n\n public stop = async (): Promise<void> => {\n if (matchesOneOf(this.state, ['recording'])) {\n if (Platform.OS === 'android') {\n const buffer = this._getRecorderStopSafeBuffer();\n if (buffer > 0) await sleep(buffer);\n }\n\n await this.recorder?.stop();\n this.removeListener();\n if (Platform.OS === 'ios') {\n await this.audioModule.setAudioModeAsync({\n allowsRecording: false,\n playsInSilentMode: false,\n });\n }\n this.setState('completed');\n }\n };\n\n public reset = async (): Promise<void> => {\n await this.stop();\n this.recorder = null;\n this.uri = undefined;\n this._recordingSubscribers.clear();\n this._stateSubscribers.clear();\n this.setState('idle');\n };\n}\n\nconst createExpoRecorderService = ({ avModule }: Modules): RecorderServiceInterface => {\n if (expoBackwardUtils.expoAV.isLegacyAVModule(avModule)) {\n Logger.warn(\n '[RecorderService.Expo] expo-av is deprecated and will be removed in Expo 54. Please migrate to expo-audio.',\n );\n }\n\n return expoBackwardUtils.expoAV.isAudioModule(avModule)\n ? new ExpoAudioRecorderAdapter(avModule)\n : new LegacyExpoAVRecorderAdapter(avModule);\n};\n\nexport default createExpoRecorderService;\n"],"mappings":";;;AAEA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,SAASC,MAAM,EAAEC,YAAY,EAAEC,KAAK,QAAQ,uBAAuB;AAEnE,OAAOC,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,iBAAiB,MAAM,4BAA4B;AAE1D,OAAOC,qBAAqB,MAAM,gCAAgC;AAsBlE,MAAeC,wBAA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