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;
}
}
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();
});
}
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);
}
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);
}
}
}
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);
}
}
}
}
}
Aggregations