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')); info("Generated shared secret for call session: " + Buffer.from(computedSharedSecret).toString('hex'));
setSharedSecret(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) { if(signalType == SignalType.ACTIVE_CALL) {
setCallState(CallState.ACTIVE); setCallState(CallState.ACTIVE);
} }
}, []); }, [activeCall, sessionKeys]);
const generateSessionKeys = () => { const generateSessionKeys = () => {
const sessionKeys = nacl.box.keyPair(); const sessionKeys = nacl.box.keyPair();
@@ -186,10 +205,10 @@ export function CallProvider(props : CallProviderProps) {
* @returns * @returns
*/ */
const getKeyCast = () => { const getKeyCast = () => {
if(!sessionKeys){ if(!sharedSecret){
return ""; return "";
} }
return Buffer.from(sessionKeys.secretKey).toString('hex'); return sharedSecret;
} }
const context = { const context = {

View File

@@ -5,7 +5,10 @@ export enum SignalType {
CALL = 0, CALL = 0,
KEY_EXCHANGE = 1, KEY_EXCHANGE = 1,
ACTIVE_CALL = 2, ACTIVE_CALL = 2,
END_CALL = 3 END_CALL = 3,
OFFER = 4,
ANSWER = 5,
ICE_CONFIG = 6
} }
export class PacketSignal extends Packet { export class PacketSignal extends Packet {