Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setIceCandidate = async (candidate) => {
try {
// set ice candidate
if (this.connection && candidate) {
await this.connection.addIceCandidate(new RTCIceCandidate(candidate));
}
} catch (err) {
// error setting ice candidate?
console.log(err);
}
};
peer = pcPeers[fromId];
} else {
peer = createPC(fromId, false);
}
if (data.sdp) {
//console.log('exchange sdp', data);
let sdp = new RTCSessionDescription(data.sdp);
let callback = () => peer.remoteDescription.type === 'offer' ? peer.createAnswer(callback2, logError) : null;
let callback2 = desc => peer.setLocalDescription(desc, callback3, logError);
let callback3 = () => socket.emit('exchange', { to: fromId, sdp: peer.localDescription });
peer.setRemoteDescription(sdp, callback, logError);
} else {
peer.addIceCandidate(new RTCIceCandidate(data.candidate));
}
};
peerconn.setRemoteDescription(new RTCSessionDescription(data.sdp))
.then(() => {
if (peerconn.remoteDescription.type === "offer") {
peerconn.createAnswer(offerOpts)
.then(desc => {
peerconn.setLocalDescription(desc)
.then(() => {
store.dispatch({ type: EXCHANGE, payload: {'to': data.from, 'sdp': peerconn.localDescription } });
})
.catch(err => console.error("exchange sdp error : ", err))
})
}
})
} else {
console.log('exchange candidate');
peerconn.addIceCandidate(new RTCIceCandidate(data.candidate));
}
}
return store => next => action => {
SocketUtils.emitExchangeServerSdp(
fromId,
pc.localDescription
);
},
error => console.log('error : ' + error)
);
},
error => console.log('error : ' + error)
);
},
error => console.log('error : ' + error)
);
} else {
console.log('exchange candidate', data);
pc.addIceCandidate(new RTCIceCandidate(data.candidate));
}
}
};