use of im.actor.runtime.webrtc.WebRTCSessionDescription in project actor-platform by actorapp.
the class PeerConnectionActor method onOffer.
public void onOffer(final long sessionId, @NotNull String sdp) {
// Ignore if we are not waiting for handshake
if (state != PeerConnectionState.WAITING_HANDSHAKE) {
return;
}
// Ignore if we already have session id
if (this.sessionId != -1) {
return;
}
//
// Stages
// 1. Set Remote Description
// 2. Create Answer
// 3. Set Local Description
// 4. Send Answer
// 5. Enter READY mode
//
isReady = false;
peerConnection.setRemoteDescription(new WebRTCSessionDescription("offer", sdp)).flatMap(description -> {
return peerConnection.createAnswer();
}).flatMap(webRTCSessionDescription -> {
return peerConnection.setLocalDescription(SDPOptimizer.optimize(webRTCSessionDescription));
}).then(webRTCSessionDescription -> {
callback.onAnswer(sessionId, webRTCSessionDescription.getSdp());
PeerConnectionActor.this.sessionId = sessionId;
onHandShakeCompleted(sessionId);
onReady();
}).failure(e -> {
e.printStackTrace();
onHandshakeFailure();
});
}
use of im.actor.runtime.webrtc.WebRTCSessionDescription in project actor-platform by actorapp.
the class SDPOptimizer method optimize.
public static WebRTCSessionDescription optimize(WebRTCSessionDescription src) {
SDPScheme sdpScheme = SDP.parse(src.getSdp());
// Prefer ISAC over other audio codecs
for (SDPMedia media : sdpScheme.getMediaLevel()) {
SDPCodec isacCodec = null;
for (SDPCodec codec : media.getCodecs()) {
if (codec.getName().toLowerCase().equals("isac")) {
isacCodec = codec;
break;
}
}
if (isacCodec != null) {
media.getCodecs().remove(isacCodec);
media.getCodecs().add(0, isacCodec);
}
}
return new WebRTCSessionDescription(src.getType(), sdpScheme.toSDP());
}
use of im.actor.runtime.webrtc.WebRTCSessionDescription in project actor-platform by actorapp.
the class PeerConnectionActor method onAnswer.
public void onAnswer(final long sessionId, @NotNull String sdp) {
// Ignore if we are not waiting for answer
if (state != PeerConnectionState.WAITING_ANSWER) {
return;
}
//
// Stages
// 1. Set Remote Description
// 2. Enter READY mode
//
peerConnection.setRemoteDescription(new WebRTCSessionDescription("answer", sdp)).then(description -> {
onHandShakeCompleted(sessionId);
onReady();
}).failure(e -> {
e.printStackTrace();
onHandshakeFailure();
});
}
Aggregations