Search in sources :

Example 1 with WebRTCMediaTrack

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

the class PeerCallActor method postStop.

@Override
public void postStop() {
    super.postStop();
    for (PeerNodeInt d : refs.values()) {
        d.kill();
    }
    refs.clear();
    if (currentMediaStream != null) {
        if (isAudioEnabled) {
            for (WebRTCMediaTrack track : currentMediaStream.get().getAudioTracks()) {
                callback.onOwnTrackRemoved(track);
            }
        }
        if (isVideoEnabled) {
            for (WebRTCMediaTrack track : currentMediaStream.get().getVideoTracks()) {
                callback.onOwnTrackRemoved(track);
            }
        }
        currentMediaStream.release();
        currentMediaStream = null;
    }
}
Also used : WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack)

Example 2 with WebRTCMediaTrack

use of im.actor.runtime.webrtc.WebRTCMediaTrack 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)

Example 3 with WebRTCMediaTrack

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

the class JsCall method create.

public static JsCall create(JsMessenger messenger, CallVM model) {
    JsArray<JsPeerInfo> members = JsArray.createArray().cast();
    for (CallMember member : model.getMembers().get()) {
        members.push(messenger.buildPeerInfo(Peer.user(member.getUid())));
    }
    String state;
    switch(model.getState().get()) {
        case RINGING:
            state = "calling";
            break;
        case CONNECTING:
            state = "connecting";
            break;
        case IN_PROGRESS:
            state = "in_progress";
            break;
        default:
        case ENDED:
            state = "ended";
            break;
    }
    JsArray<JsMediaStreamTrack> tracks = JsArray.createArray().cast();
    for (WebRTCMediaTrack track : model.getTheirVideoTracks().get()) {
        tracks.push(((MediaTrack) track).getTrack());
    }
    ArrayList<WebRTCMediaTrack> ownTrack = model.getOwnVideoTracks().get();
    return create(JsPeer.create(model.getPeer()), model.isOutgoing(), members, state, !model.getIsAudioEnabled().get(), ownTrack.size() == 0 ? null : ((MediaTrack) ownTrack.get(0)).getTrack(), tracks);
}
Also used : WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack) MediaTrack(im.actor.runtime.js.webrtc.MediaTrack) CallMember(im.actor.core.viewmodel.CallMember) JsMediaStreamTrack(im.actor.runtime.js.webrtc.js.JsMediaStreamTrack) WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack)

Example 4 with WebRTCMediaTrack

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

the class PeerCallActor method onVideoEnabled.

public void onVideoEnabled(boolean isVideoEnabled) {
    if (this.isVideoEnabled != isVideoEnabled) {
        this.isVideoEnabled = isVideoEnabled;
        if (!isVideoRequired) {
            isVideoRequired = true;
        }
        if (currentMediaStream != null) {
            for (WebRTCMediaTrack video : currentMediaStream.get().getVideoTracks()) {
                video.setEnabled(isVideoEnabled);
                if (isVideoEnabled) {
                    callback.onOwnTrackAdded(video);
                } else {
                    callback.onOwnTrackRemoved(video);
                }
            }
        }
        requestStreamIfNeeded();
        for (Long deviceId : refs.keySet()) {
            callback.onMediaStreamsChanged(deviceId, isAudioEnabled, isVideoEnabled);
        }
    }
}
Also used : WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack)

Example 5 with WebRTCMediaTrack

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

the class PeerNodeActor method startIfNeeded.

private void startIfNeeded() {
    if (isEnabled && isConnected && !isStarted) {
        isStarted = true;
        state = PeerState.ACTIVE;
        callback.onPeerStateChanged(deviceId, state);
        if (theirStream != null) {
            for (WebRTCMediaTrack track : theirStream.getAudioTracks()) {
                track.setEnabled(isAudioEnabled);
                if (isAudioEnabled) {
                    callback.onTrackAdded(deviceId, track);
                }
            }
            for (WebRTCMediaTrack track : theirStream.getVideoTracks()) {
                track.setEnabled(isVideoEnabled);
                if (isVideoEnabled) {
                    callback.onTrackAdded(deviceId, track);
                }
            }
        }
    }
}
Also used : WebRTCMediaTrack(im.actor.runtime.webrtc.WebRTCMediaTrack)

Aggregations

WebRTCMediaTrack (im.actor.runtime.webrtc.WebRTCMediaTrack)7 WebRTCMediaStream (im.actor.runtime.webrtc.WebRTCMediaStream)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 CallMember (im.actor.core.viewmodel.CallMember)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 MediaTrack (im.actor.runtime.js.webrtc.MediaTrack)1 JsMediaStreamTrack (im.actor.runtime.js.webrtc.js.JsMediaStreamTrack)1 Promise (im.actor.runtime.promise.Promise)1 WebRTCIceServer (im.actor.runtime.webrtc.WebRTCIceServer)1 WebRTCPeerConnection (im.actor.runtime.webrtc.WebRTCPeerConnection)1 WebRTCPeerConnectionCallback (im.actor.runtime.webrtc.WebRTCPeerConnectionCallback)1