Updated changes

This commit is contained in:
WolverinDEV 2018-09-23 20:49:47 +02:00
parent 27aca1610e
commit 26732e7841

View file

@ -281,15 +281,21 @@ class VoiceConnection {
handleControlPacket(json) { handleControlPacket(json) {
if(json["request"] === "answer") { if(json["request"] === "answer") {
console.log("Set remote sdp! (%o)", json["msg"]); console.log("Set remote sdp! (%o)", json["msg"]);
this.rtcPeerConnection.setRemoteDescription(new RTCSessionDescription(json["msg"])); this.rtcPeerConnection.setRemoteDescription(new RTCSessionDescription(json["msg"])).catch(error => {
console.log("Failed to apply remote description: %o", error); //FIXME error handling!
});
this._ice_use_cache = false; this._ice_use_cache = false;
for(let msg of this._ice_cache) { for(let msg of this._ice_cache) {
this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(msg)); this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(msg)).catch(error => {
console.log("Failed to add remote cached ice candidate %s: %o", msg, error);
});
} }
} else if(json["request"] === "ice") { } else if(json["request"] === "ice") {
if(!this._ice_use_cache) { if(!this._ice_use_cache) {
console.log("Add remote ice! (%s | %o)", json["msg"], json); console.log("Add remote ice! (%s | %o)", json["msg"], json);
this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(json["msg"])); this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(json["msg"])).catch(error => {
console.log("Failed to add remote ice candidate %s: %o", json["msg"], error);
});
} else { } else {
console.log("Cache remote ice! (%s | %o)", json["msg"], json); console.log("Cache remote ice! (%s | %o)", json["msg"], json);
this._ice_cache.push(json["msg"]); this._ice_cache.push(json["msg"]);
@ -310,18 +316,28 @@ class VoiceConnection {
onIceCandidate(event) { onIceCandidate(event) {
console.log("Got ice candidate! Event:"); console.log("Got ice candidate! Event:");
console.log(event); console.log(event);
if (event && event.candidate) { if (event) {
if(event.candidate)
this.client.serverConnection.sendData(JSON.stringify({ this.client.serverConnection.sendData(JSON.stringify({
type: 'WebRTC', type: 'WebRTC',
request: "ice", request: "ice",
msg: event.candidate, msg: event.candidate,
})); }));
else {
this.client.serverConnection.sendData(JSON.stringify({
type: 'WebRTC',
request: "ice_finish"
}));
}
} }
} }
onOfferCreated(localSession) { onOfferCreated(localSession) {
console.log("Offer created and accepted"); console.log("Offer created and accepted");
this.rtcPeerConnection.setLocalDescription(localSession); this.rtcPeerConnection.setLocalDescription(localSession).catch(error => {
console.log("Failed to apply local description: %o", error);
//FIXME error handling
});
console.log("Send offer: %o", localSession); console.log("Send offer: %o", localSession);
this.client.serverConnection.sendData(JSON.stringify({type: 'WebRTC', request: "create", msg: localSession})); this.client.serverConnection.sendData(JSON.stringify({type: 'WebRTC', request: "create", msg: localSession}));