Interface WebRtcBridge


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.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addIceCandidate(int peer, String sdpMid, int sdpMLineIndex, String candidate)
    Adds a candidate the other side gathered.
    void
    addTrack(int peer, int track)
    Sends a local track over a peer connection.
    void
    Closes a peer connection and frees its handle.
    void
    createDescription(int peer, int requestId, boolean answer)
    Creates an offer, or with answer an answer to the remote description already set.
    int
    createPeerConnection(String iceServers, boolean relayOnly)
    Creates a peer connection and answers its handle, or a negative number when it cannot be created.
    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.
    void
    openUserMedia(int requestId, boolean audio, boolean video, boolean frontCamera)
    Starts the local camera and/or microphone.
    void
    releaseTrack(int track)
    Stops a local track and frees its handle.
    void
    Detaches a view from its track, before the view is discarded.
    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.
    void
    setSpeakerphone(boolean on)
    Routes call audio to the loudspeaker or back to the earpiece.
    void
    setTrackEnabled(int track, boolean enabled)
    Mutes or unmutes a track, local or remote.
    void
    switchCamera(int track)
    Switches a local video track between the front and back cameras.
  • Method Details

    • createPeerConnection

      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: one server per line, each line tab-separated as urls (comma-separated), username, credential

      • relayOnly: whether only relayed (TURN) candidates may be used, which keeps the device's own addresses from the other side

    • openUserMedia

      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

      void addTrack(int peer, int track)
      Sends a local track over a peer connection.
    • createDescription

      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

      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
      • type: offer or answer
    • addIceCandidate

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

      void closePeerConnection(int peer)
      Closes a peer connection and frees its handle.
    • setTrackEnabled

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

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

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

      void releaseTrack(int track)
      Stops a local track and frees its handle.
    • createVideoView

      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

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