Skip to content

Commit

Permalink
v4.3.21
Browse files Browse the repository at this point in the history
  • Loading branch information
mathews-cometchat committed Nov 27, 2024
1 parent 802f778 commit a948f43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cometchat/chat-uikit-react-native",
"version": "4.3.20",
"version": "4.3.21",
"description": "Ready-to-use Chat UI Components for React Native",
"main": "src/index",
"module": "src/index",
Expand Down
22 changes: 18 additions & 4 deletions src/shared/views/CometChatMediaRecorder/CometChatMediaRecorder.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useContext, useEffect } from 'react';
import { CometChatContext, CometChatContextType, ImageType, localize } from "../..";
import { View, TouchableOpacity, Text, Image, NativeModules, FlatList, PermissionsAndroid, Alert, Platform, Linking, TextStyle, ViewProps } from "react-native";
import { View, TouchableOpacity, Text, Image, NativeModules, FlatList, PermissionsAndroid, Alert, Platform, Linking, TextStyle, ViewProps, AppState } from "react-native";
import { Style } from "./style";
import { ICONS } from '../../framework/resources';
import { MediaRecorderStyle, MediaRecorderStyleInterface } from './MediaRecorderStyle';

let recordedTime = 0, stopRecordingIntervalId: any = null;
let recordingStatedAt = 0;
export interface CometChatMediaRecorderInterface {
onClose?: Function;
onPlay?: Function;
Expand Down Expand Up @@ -70,6 +71,18 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
}
}, [])

useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
if (nextAppState === 'background') {
_onStop();
}
});

return () => {
subscription.remove();
};
}, []);

function permissionAlert() {
Alert.alert('', localize("MICROPHONE_PERMISSION"), [
{
Expand Down Expand Up @@ -114,6 +127,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
}

const startInterval = () => {
recordingStatedAt = Date.now();
timerIntervalId = setInterval(timer, 1000);
}

Expand All @@ -131,7 +145,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
const _onStop = () => {
NativeModules.FileManager.releaseMediaResources((result: string) => {
console.log(time, "Filepath _stopRecorderAudio", result);
recordedTime = time;
recordedTime = Date.now() - recordingStatedAt;
setRecordedFile(JSON.parse(result)?.file);
onStop && onStop(JSON.parse(result)?.file);
})
Expand Down Expand Up @@ -164,7 +178,7 @@ export const CometChatMediaRecorder = (props: CometChatMediaRecorderInterface) =
onPause && onPause();
setRecordedPlaying(false);
clearTimeout(stopRecordingIntervalId);
}, recordedTime * 1000)
}, recordedTime)
})
}

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

0 comments on commit a948f43

Please sign in to comment.