Created
April 29, 2023 15:14
-
-
Save dueka/01d35d803b4459c4e4e17b7d10be4942 to your computer and use it in GitHub Desktop.
App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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