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