Skip to content

Commit a948f43

Browse files
v4.3.21
1 parent 802f778 commit a948f43

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cometchat/chat-uikit-react-native",
3-
"version": "4.3.20",
3+
"version": "4.3.21",
44
"description": "Ready-to-use Chat UI Components for React Native",
55
"main": "src/index",
66
"module": "src/index",

src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { useContext, useEffect } from 'react';
22
import { CometChatContext, CometChatContextType, ImageType, localize } from "../..";
3-
import { View, TouchableOpacity, Text, Image, NativeModules, FlatList, PermissionsAndroid, Alert, Platform, Linking, TextStyle, ViewProps } from "react-native";
3+
import { View, TouchableOpacity, Text, Image, NativeModules, FlatList, PermissionsAndroid, Alert, Platform, Linking, TextStyle, ViewProps, AppState } from "react-native";
44
import { Style } from "./style";
55
import { ICONS } from '../../framework/resources';
66
import { MediaRecorderStyle, MediaRecorderStyleInterface } from './MediaRecorderStyle';
77

88
let recordedTime = 0, stopRecordingIntervalId: any = null;
9+
let recordingStatedAt = 0;
910
export interface CometChatMediaRecorderInterface {
1011
onClose?: Function;
1112
onPlay?: Function;
@@ -70,6 +71,18 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
7071
}
7172
}, [])
7273

74+
useEffect(() => {
75+
const subscription = AppState.addEventListener('change', (nextAppState) => {
76+
if (nextAppState === 'background') {
77+
_onStop();
78+
}
79+
});
80+
81+
return () => {
82+
subscription.remove();
83+
};
84+
}, []);
85+
7386
function permissionAlert() {
7487
Alert.alert('', localize("MICROPHONE_PERMISSION"), [
7588
{
@@ -114,6 +127,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
114127
}
115128

116129
const startInterval = () => {
130+
recordingStatedAt = Date.now();
117131
timerIntervalId = setInterval(timer, 1000);
118132
}
119133

@@ -131,7 +145,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
131145
const _onStop = () => {
132146
NativeModules.FileManager.releaseMediaResources((result: string) => {
133147
console.log(time, "Filepath _stopRecorderAudio", result);
134-
recordedTime = time;
148+
recordedTime = Date.now() - recordingStatedAt;
135149
setRecordedFile(JSON.parse(result)?.file);
136150
onStop && onStop(JSON.parse(result)?.file);
137151
})
@@ -164,7 +178,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
164178
onPause && onPause();
165179
setRecordedPlaying(false);
166180
clearTimeout(stopRecordingIntervalId);
167-
}, recordedTime * 1000)
181+
}, recordedTime)
168182
})
169183
}
170184

@@ -246,7 +260,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
246260
<View style={[Style.timerContainer, { flexDirection: Boolean(recordedFile) ? "row-reverse" : "row" }]}>
247261
<Text style={[
248262
timerTextFont && { fontFamily: timerTextFont },
249-
timerTextColor && { color: timerTextColor },
263+
timerTextColor ? { color: timerTextColor } : { color: "#000" },
250264
timerTextstyle && { fontStyle: timerTextstyle },
251265
!Boolean(recordedFile) && { marginRight: 10 }
252266
] as TextStyle}>{formatTime(time)}</Text>

0 commit comments

Comments
 (0)