Skip to content

Instantly share code, notes, and snippets.

@dueka
Created April 29, 2023 15:14
Show Gist options
  • Save dueka/01d35d803b4459c4e4e17b7d10be4942 to your computer and use it in GitHub Desktop.
Save dueka/01d35d803b4459c4e4e17b7d10be4942 to your computer and use it in GitHub Desktop.
App.tsx
const join = async () => {
setJoinLoading(true);
resetTranscribedData();
const recordingPath = `${RNFS.DocumentDirectoryPath}/audioRecordings`;
RNFS.mkdir(recordingPath);
const fileName = 'recording.wav';
const filePath = `${recordingPath}/${fileName}`;
await RNFS.unlink(filePath).catch(error => {
console.log('Error deleting file:', error);
});
console.log('joining channel');
if (isJoined) {
setJoinLoading(false);
return;
}
try {
agoraEngineRef.current?.setChannelProfile(
ChannelProfileType.ChannelProfileLiveBroadcasting,
);
if (isHost) {
agoraEngineRef.current?.startPreview();
agoraEngineRef.current?.joinChannel(token, channelName, uid, {
clientRoleType: ClientRoleType.ClientRoleBroadcaster,
});
console.log('recording started as a broadcaster');
agoraEngineRef.current?.startAudioRecording({
filePath: filePath,
encode: false,
sampleRate: SAMPLE_RATE,
fileRecordingType: AudioFileRecordingType.AudioFileRecordingMixed,
});
} else {
agoraEngineRef.current?.joinChannel(token, channelName, uid, {
clientRoleType: ClientRoleType.ClientRoleAudience,
});
console.log('recording started as audience');
agoraEngineRef.current?.startAudioRecording({
filePath: filePath,
encode: false,
sampleRate: SAMPLE_RATE,
fileRecordingType: AudioFileRecordingType.AudioFileRecordingMixed,
});
}
setJoinLoading(false);
} catch (e) {
console.log(e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment