OFFERS & ANSWERS webRTC

This commit is contained in:
RoyceDa
2026-02-28 18:31:21 +02:00
parent 9ad0e5d00a
commit 7a89a3a307
2 changed files with 26 additions and 4 deletions

View File

@@ -128,10 +128,29 @@ export function CallProvider(props : CallProviderProps) {
info("Generated shared secret for call session: " + Buffer.from(computedSharedSecret).toString('hex'));
setSharedSecret(Buffer.from(computedSharedSecret).toString('hex'));
}
if(signalType == SignalType.OFFER){
const offerJson = packet.getOffer();
if(!offerJson || !peerConnectionRef.current){
info("Received offer but peer connection is not ready");
return;
}
handleOffer(offerJson);
}
if(signalType == SignalType.ANSWER){
const answerJson = packet.getAnswer();
if(!answerJson || !peerConnectionRef.current){
info("Received answer but peer connection is not ready");
return;
}
handleAnswer(answerJson);
}
if(signalType == SignalType.ACTIVE_CALL) {
setCallState(CallState.ACTIVE);
}
}, []);
}, [activeCall, sessionKeys]);
const generateSessionKeys = () => {
const sessionKeys = nacl.box.keyPair();
@@ -186,10 +205,10 @@ export function CallProvider(props : CallProviderProps) {
* @returns
*/
const getKeyCast = () => {
if(!sessionKeys){
if(!sharedSecret){
return "";
}
return Buffer.from(sessionKeys.secretKey).toString('hex');
return sharedSecret;
}
const context = {