Search in sources :

Example 1 with WebRTCSessionDescription

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();
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTC(im.actor.runtime.WebRTC) CountedReference(im.actor.runtime.function.CountedReference) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) ActorCreator(im.actor.runtime.actors.ActorCreator) Void(im.actor.runtime.actors.messages.Void) ApiICEServer(im.actor.core.api.ApiICEServer) Promise(im.actor.runtime.promise.Promise) AskMessage(im.actor.runtime.actors.ask.AskMessage) ManagedList(im.actor.runtime.collections.ManagedList) WebRTCPeerConnection(im.actor.runtime.webrtc.WebRTCPeerConnection) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription) Property(com.google.j2objc.annotations.Property) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription)

Example 2 with WebRTCSessionDescription

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());
}
Also used : SDPCodec(im.actor.runtime.webrtc.sdp.entities.SDPCodec) SDPScheme(im.actor.runtime.webrtc.sdp.SDPScheme) SDPMedia(im.actor.runtime.webrtc.sdp.entities.SDPMedia) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription)

Example 3 with WebRTCSessionDescription

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();
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTC(im.actor.runtime.WebRTC) CountedReference(im.actor.runtime.function.CountedReference) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) ActorCreator(im.actor.runtime.actors.ActorCreator) Void(im.actor.runtime.actors.messages.Void) ApiICEServer(im.actor.core.api.ApiICEServer) Promise(im.actor.runtime.promise.Promise) AskMessage(im.actor.runtime.actors.ask.AskMessage) ManagedList(im.actor.runtime.collections.ManagedList) WebRTCPeerConnection(im.actor.runtime.webrtc.WebRTCPeerConnection) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription) Property(com.google.j2objc.annotations.Property) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream) WebRTCSessionDescription(im.actor.runtime.webrtc.WebRTCSessionDescription)

Aggregations

WebRTCSessionDescription (im.actor.runtime.webrtc.WebRTCSessionDescription)3 Property (com.google.j2objc.annotations.Property)2 ApiICEServer (im.actor.core.api.ApiICEServer)2 ModuleActor (im.actor.core.modules.ModuleActor)2 ModuleContext (im.actor.core.modules.ModuleContext)2 Log (im.actor.runtime.Log)2 WebRTC (im.actor.runtime.WebRTC)2 ActorCreator (im.actor.runtime.actors.ActorCreator)2 AskMessage (im.actor.runtime.actors.ask.AskMessage)2 Void (im.actor.runtime.actors.messages.Void)2 ManagedList (im.actor.runtime.collections.ManagedList)2 CountedReference (im.actor.runtime.function.CountedReference)2 Promise (im.actor.runtime.promise.Promise)2 WebRTCIceServer (im.actor.runtime.webrtc.WebRTCIceServer)2 WebRTCMediaStream (im.actor.runtime.webrtc.WebRTCMediaStream)2 WebRTCMediaTrack (im.actor.runtime.webrtc.WebRTCMediaTrack)2 WebRTCPeerConnection (im.actor.runtime.webrtc.WebRTCPeerConnection)2 WebRTCPeerConnectionCallback (im.actor.runtime.webrtc.WebRTCPeerConnectionCallback)2 WebRTCSettings (im.actor.runtime.webrtc.WebRTCSettings)2 List (java.util.List)2