Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public interface WebRtcBridge

Internal service-provider interface a port implements to carry the com.codename1.webrtc API onto its native WebRTC stack: Google’s org.webrtc on Android, the WebRTC framework on iOS, the browser’s RTCPeerConnection in the JavaScript port, and a loopback in the simulator.

Application code never touches this interface; the public classes reach it through com.codename1.ui.Display#getWebRtcBridge(), and a port that returns null there is a port without WebRTC – WebRtc.isSupported() says so and nothing else needs a platform if.

Everything is ids, primitives and strings

As with com.codename1.call.spi.CallBridge, no method takes or returns a framework type, so a port reached through ParparVM never constructs a Java object from native code. Peer connections and tracks are integer handles the port allocates; structured values cross as strings.

Every request answers exactly once

An operation that can fail takes a requestId from the caller and answers it by calling exactly one of WebRtc.deliverDescription, WebRtc.deliverTracks or WebRtc.deliverResult. A request that never answers leaves an AsyncResource that never settles, which is worse than one that fails. Unsolicited events – a gathered candidate, a state change, a remote track – carry the peer handle instead. Every entry point may be called from any thread; they marshal to the EDT themselves.

Methods

public abstract int createPeerConnection(String iceServers, boolean relayOnly)Creates a peer connection and answers its handle, or a negative number when it cannot be created.
public abstract void openUserMedia(int requestId, boolean audio, boolean video, boolean frontCamera)Starts the local camera and/or microphone.
public abstract void addTrack(int peer, int track)Sends a local track over a peer connection.
public abstract void createDescription(int peer, int requestId, boolean answer)Creates an offer, or with answer an answer to the remote description already set.
public abstract void setDescription(int peer, int requestId, boolean remote, String type, String sdp)Sets a description as the local one, or with remote as the remote one.
public abstract void addIceCandidate(int peer, String sdpMid, int sdpMLineIndex, String candidate)Adds a candidate the other side gathered.
public abstract void closePeerConnection(int peer)Closes a peer connection and frees its handle.
public abstract void setTrackEnabled(int track, boolean enabled)Mutes or unmutes a track, local or remote.
public abstract void switchCamera(int track)Switches a local video track between the front and back cameras.
public abstract void setSpeakerphone(boolean on)Routes call audio to the loudspeaker or back to the earpiece.
public abstract void releaseTrack(int track)Stops a local track and frees its handle.
public abstract Object createVideoView(int track, boolean mirror)A native view drawing a video track: a com.codename1.ui.PeerComponent, or any com.codename1.ui.Component on a port that draws it itself.
public abstract void releaseVideoView(Object view)Detaches a view from its track, before the view is discarded.

Method details

createPeerConnection

public abstract int createPeerConnection(String iceServers, boolean relayOnly)
Creates a peer connection and answers its handle, or a negative number when it cannot be created.

Parameters

iceServers String
one server per line, each line tab-separated as urls (comma-separated), username, credential
relayOnly boolean
whether only relayed (TURN) candidates may be used, which keeps the device’s own addresses from the other side

openUserMedia

public abstract void openUserMedia(int requestId, boolean audio, boolean video, boolean frontCamera)
Starts the local camera and/or microphone. Answers with WebRtc.deliverTracks: the handles of the audio track and the video track, 0 for one not asked for.

addTrack

public abstract void addTrack(int peer, int track)
Sends a local track over a peer connection.

createDescription

public abstract void createDescription(int peer, int requestId, boolean answer)
Creates an offer, or with answer an answer to the remote description already set. Answers with WebRtc.deliverDescription.

setDescription

public abstract void setDescription(int peer, int requestId, boolean remote, String type, String sdp)
Sets a description as the local one, or with remote as the remote one. Answers with WebRtc.deliverResult.

Parameters

peer int
Not documented.
requestId int
Not documented.
remote boolean
Not documented.
type String
offer or answer
sdp String
Not documented.

addIceCandidate

public abstract void addIceCandidate(int peer, String sdpMid, int sdpMLineIndex, String candidate)
Adds a candidate the other side gathered.

closePeerConnection

public abstract void closePeerConnection(int peer)
Closes a peer connection and frees its handle.

setTrackEnabled

public abstract void setTrackEnabled(int track, boolean enabled)
Mutes or unmutes a track, local or remote.

switchCamera

public abstract void switchCamera(int track)
Switches a local video track between the front and back cameras.

setSpeakerphone

public abstract void setSpeakerphone(boolean on)
Routes call audio to the loudspeaker or back to the earpiece.

releaseTrack

public abstract void releaseTrack(int track)
Stops a local track and frees its handle.

createVideoView

public abstract Object createVideoView(int track, boolean mirror)
A native view drawing a video track: a com.codename1.ui.PeerComponent, or any com.codename1.ui.Component on a port that draws it itself. Null when the track cannot be drawn.

releaseVideoView

public abstract void releaseVideoView(Object view)
Detaches a view from its track, before the view is discarded.