Class SignalingManager

java.lang.Object
dev.onvoid.webrtc.examples.web.client.SignalingManager

public class SignalingManager extends Object
Manages WebSocket signaling for WebRTC connections.

This class handles the communication between peers during WebRTC connection establishment. It manages sending and receiving:

  • Session descriptions (offers and answers)
  • ICE candidates
  • Join messages for room-based signaling

The manager connects to a signaling server via WebSocket and translates WebRTC-related objects to JSON messages that can be transmitted over the signaling channel.

Author:
Alex Andres
  • Constructor Details

    • SignalingManager

      public SignalingManager(URI signalingUri, String subprotocol)
      Creates a new SignalingManager with the specified URI and subprotocol.
      Parameters:
      signalingUri - The URI of the signaling server.
      subprotocol - The WebSocket subprotocol to use.
  • Method Details

    • connect

      public boolean connect()
      Connects to the signaling server.
      Returns:
      true if the connection was successful, false otherwise.
    • disconnect

      public void disconnect()
      Disconnects from the signaling server.
    • sendJoin

      public void sendJoin(String roomId)
      Sends a join message to the signaling server.
      Parameters:
      roomId - The ID of the room to join.
    • sendSessionDescription

      public void sendSessionDescription(RTCSessionDescription sdp)
      Sends a session description (offer or answer) to the remote peer.
      Parameters:
      sdp - The session description to send.
    • sendIceCandidate

      public void sendIceCandidate(RTCIceCandidate candidate)
      Sends an ICE candidate to the remote peer.
      Parameters:
      candidate - The ICE candidate to send.
    • setOnOfferReceived

      public void setOnOfferReceived(Consumer<SessionDescriptionMessage> callback)
      Sets a callback to be invoked when an offer is received.
      Parameters:
      callback - The callback to invoke.
    • setOnAnswerReceived

      public void setOnAnswerReceived(Consumer<SessionDescriptionMessage> callback)
      Sets a callback to be invoked when an answer is received.
      Parameters:
      callback - The callback to invoke.
    • setOnCandidateReceived

      public void setOnCandidateReceived(Consumer<IceCandidateMessage> callback)
      Sets a callback to be invoked when an ICE candidate is received.
      Parameters:
      callback - The callback to invoke.
    • setOnJoinReceived

      public void setOnJoinReceived(Consumer<JoinMessage> callback)
      Sets a callback to be invoked when a join message is received.
      Parameters:
      callback - The callback to invoke.
    • setOnLeaveReceived

      public void setOnLeaveReceived(Consumer<LeaveMessage> callback)
      Sets a callback to be invoked when a leave message is received.
      Parameters:
      callback - The callback to invoke.
    • setUserId

      public void setUserId(String userId)
      Sets the user ID for this client.
      Parameters:
      userId - The user ID to set.
    • setRemotePeerId

      public void setRemotePeerId(String remotePeerId)
      Sets the remote peer ID.
      Parameters:
      remotePeerId - The remote peer ID to set.
    • getUserId

      public String getUserId()
      Gets the user ID for this client.
      Returns:
      The user ID.
    • getRemotePeerId

      public String getRemotePeerId()
      Gets the remote peer ID.
      Returns:
      The remote peer ID.
    • isConnected

      public boolean isConnected()
      Checks if the signaling connection is established.
      Returns:
      true if connected, false otherwise.