Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class WebRtc
- Object
- WebRtc
Real-time audio and video between two devices: the entry point of the package.
import com.codename1.webrtc.*;
Form form = new Form("Call", new BorderLayout());
if (WebRtc.isSupported()) {
WebRtc.openUserMedia(true, true, true).ready(media -> {
PeerConnection pc = WebRtc.createPeerConnection(
new PeerConnectionConfig().addIceServer(IceServer.stun("stun:stun.example.com")),
new PeerConnection.Listener() {
public void iceCandidate(PeerConnection connection, IceCandidate candidate) {
// send it to the other side over your own channel
}
public void stateChanged(PeerConnection connection, String state) {
form.setTitle(state);
}
public void remoteTrack(PeerConnection connection, MediaTrack track) {
if (track.isVideo()) {
form.add(BorderLayout.CENTER, new VideoView(track, false));
form.revalidate();
}
}
});
pc.addTrack(media.getAudio());
pc.addTrack(media.getVideo());
form.add(BorderLayout.SOUTH, new VideoView(media.getVideo(), true));
form.revalidate();
});
} else {
form.add(BorderLayout.CENTER, new Label("No camera calls on this device"));
}
form.show();
The package carries media. It does not ring, place the call in the
system call log, or wake a sleeping phone: that is com.codename1.call,
which an app uses alongside this one. And it does not signal – see
PeerConnection.
On Android this is Google’s WebRTC library and on iOS Apple-platform
builds of the same library; both are added to an app only when it uses
this package. In a browser it is the browser’s own WebRTC. The simulator
connects calls without carrying media: tracks open, descriptions are
exchanged and connections reach PeerConnection.CONNECTED, and the
video views show a test pattern, so an app’s call flow can be developed
and tested end to end on the desktop.
Methods
Inherited methods
Method details
isSupported
public static boolean isSupported()openUserMedia
public static AsyncResource<LocalMedia> openUserMedia(boolean audio, boolean video, boolean frontCamera)Parameters
audioboolean- Not documented.
videoboolean- Not documented.
frontCameraboolean- which camera to open first; see
MediaTrack.switchCamera()
createPeerConnection
public static PeerConnection createPeerConnection(PeerConnectionConfig config, PeerConnection.Listener listener)listener on the EDT.setSpeakerphone
public static void setSpeakerphone(boolean on)deliverDescription
public static void deliverDescription(int requestId, String type, String sdp, String error)createDescription: the description, or a null
sdp and the reason.deliverTracks
public static void deliverTracks(int requestId, int audio, int video, String error)openUserMedia: the track handles, 0 for none,
or both 0 and the reason.deliverResult
public static void deliverResult(int requestId, String error)setDescription: null for success, else the
reason.iceCandidate
public static void iceCandidate(int peer, String sdpMid, int sdpMLineIndex, String candidate)stateChanged
public static void stateChanged(int peer, String state)state, one of the names on
PeerConnection.remoteTrack
public static void remoteTrack(int peer, int track, boolean video)