Search in sources :

Example 1 with WebRTCPeerConnectionCallback

use of im.actor.runtime.webrtc.WebRTCPeerConnectionCallback in project actor-platform by actorapp.

the class AndroidPeerConnection method close.

@Override
public void close() {
    AndroidWebRTCRuntimeProvider.postToHandler(() -> {
        while (!ownStreams.isEmpty()) {
            CountedReference<WebRTCMediaStream> stream = ownStreams.remove(0);
            peerConnection.removeStream(((AndroidMediaStream) stream.get()).getStream());
            stream.release();
        }
        for (MediaStream stream : streams.keySet()) {
            AndroidMediaStream stream1 = streams.get(stream);
            if (stream1 != null) {
                for (WebRTCPeerConnectionCallback c : callbacks) {
                    c.onStreamRemoved(stream1);
                }
            }
        }
        peerConnection.dispose();
    });
}
Also used : WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) MediaStream(org.webrtc.MediaStream) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream)

Example 2 with WebRTCPeerConnectionCallback

use of im.actor.runtime.webrtc.WebRTCPeerConnectionCallback in project actor-platform by actorapp.

the class PeerConnectionActor method preStart.

@Override
public void preStart() {
    isReady = false;
    WebRTCIceServer[] rtcIceServers = ManagedList.of(iceServers).map(apiICEServer -> new WebRTCIceServer(apiICEServer.getUrl(), apiICEServer.getUsername(), apiICEServer.getCredential())).toArray(new WebRTCIceServer[0]);
    WebRTCSettings settings = new WebRTCSettings(false, false, config().isVideoCallsEnabled());
    WebRTC.createPeerConnection(rtcIceServers, settings).then(webRTCPeerConnection -> {
        PeerConnectionActor.this.peerConnection = webRTCPeerConnection;
        PeerConnectionActor.this.peerConnection.addOwnStream(userMedia);
        PeerConnectionActor.this.peerConnection.addCallback(new WebRTCPeerConnectionCallback() {

            @Override
            public void onCandidate(int label, String id, String candidate) {
                if (sessionId != -1) {
                    callback.onCandidate(sessionId, label, id, candidate);
                }
            }

            @Override
            public void onRenegotiationNeeded() {
            // if (sessionId != -1) {
            // callback.onNegotiationNeeded(sessionId);
            // }
            }

            @Override
            public void onStreamAdded(WebRTCMediaStream addedStream) {
                // by parent actor
                for (WebRTCMediaTrack track : addedStream.getAudioTracks()) {
                    track.setEnabled(false);
                }
                for (WebRTCMediaTrack track : addedStream.getVideoTracks()) {
                    track.setEnabled(false);
                }
                callback.onStreamAdded(addedStream);
            }

            @Override
            public void onStreamRemoved(WebRTCMediaStream removedStream) {
                callback.onStreamRemoved(removedStream);
            }

            @Override
            public void onDisposed() {
            }
        });
        state = PeerConnectionState.WAITING_HANDSHAKE;
        onReady();
    }).failure(e -> {
        Log.d(TAG, "preStart:error");
        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) WebRTCPeerConnectionCallback(im.actor.runtime.webrtc.WebRTCPeerConnectionCallback) WebRTCSettings(im.actor.runtime.webrtc.WebRTCSettings) WebRTCIceServer(im.actor.runtime.webrtc.WebRTCIceServer) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream)

Aggregations

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