Search in sources :

Example 1 with WebRTCMediaStream

use of im.actor.runtime.webrtc.WebRTCMediaStream 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() {
            }

            @Override
            public void onStreamAdded(WebRTCMediaStream addedStream) {
                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)

Example 2 with WebRTCMediaStream

use of im.actor.runtime.webrtc.WebRTCMediaStream 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 3 with WebRTCMediaStream

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

the class PeerNodeActor method onStreamAdded.

@Override
public void onStreamAdded(WebRTCMediaStream stream) {
    WebRTCMediaStream oldStream = theirStream;
    theirStream = stream;
    //
    if (isStarted) {
        for (WebRTCMediaTrack track : stream.getAudioTracks()) {
            track.setEnabled(isAudioEnabled);
            if (isAudioEnabled) {
                callback.onTrackAdded(deviceId, track);
            }
        }
        for (WebRTCMediaTrack track : stream.getVideoTracks()) {
            track.setEnabled(isVideoEnabled);
            if (isVideoEnabled) {
                callback.onTrackAdded(deviceId, track);
            }
        }
        if (oldStream != null) {
            for (WebRTCMediaTrack track : oldStream.getVideoTracks()) {
                callback.onTrackRemoved(deviceId, track);
            }
            for (WebRTCMediaTrack track : oldStream.getAudioTracks()) {
                callback.onTrackRemoved(deviceId, track);
            }
        }
    }
    if (!isConnected) {
        isConnected = true;
        if (!isEnabled) {
            state = PeerState.CONNECTED;
            callback.onPeerStateChanged(deviceId, state);
        } else {
        // This case is handled in startIfNeeded();
        }
    }
    startIfNeeded();
}
Also used : WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) WebRTCMediaStream(im.actor.runtime.webrtc.WebRTCMediaStream)

Aggregations

WebRTCMediaStream (im.actor.runtime.webrtc.WebRTCMediaStream)3 WebRTCMediaTrack (im.actor.runtime.webrtc.WebRTCMediaTrack)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 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