java.lang.Object
dev.onvoid.webrtc.examples.web.client.SignalingManager
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 Summary
ConstructorsConstructorDescriptionSignalingManager(URI signalingUri, String subprotocol) Creates a new SignalingManager with the specified URI and subprotocol. -
Method Summary
Modifier and TypeMethodDescriptionbooleanconnect()Connects to the signaling server.voidDisconnects from the signaling server.Gets the remote peer ID.Gets the user ID for this client.booleanChecks if the signaling connection is established.voidsendIceCandidate(RTCIceCandidate candidate) Sends an ICE candidate to the remote peer.voidSends a join message to the signaling server.voidSends a session description (offer or answer) to the remote peer.voidsetOnAnswerReceived(Consumer<SessionDescriptionMessage> callback) Sets a callback to be invoked when an answer is received.voidsetOnCandidateReceived(Consumer<IceCandidateMessage> callback) Sets a callback to be invoked when an ICE candidate is received.voidsetOnJoinReceived(Consumer<JoinMessage> callback) Sets a callback to be invoked when a join message is received.voidsetOnLeaveReceived(Consumer<LeaveMessage> callback) Sets a callback to be invoked when a leave message is received.voidsetOnOfferReceived(Consumer<SessionDescriptionMessage> callback) Sets a callback to be invoked when an offer is received.voidsetRemotePeerId(String remotePeerId) Sets the remote peer ID.voidSets the user ID for this client.
-
Constructor Details
-
SignalingManager
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
Sends a join message to the signaling server.- Parameters:
roomId- The ID of the room to join.
-
sendSessionDescription
Sends a session description (offer or answer) to the remote peer.- Parameters:
sdp- The session description to send.
-
sendIceCandidate
Sends an ICE candidate to the remote peer.- Parameters:
candidate- The ICE candidate to send.
-
setOnOfferReceived
Sets a callback to be invoked when an offer is received.- Parameters:
callback- The callback to invoke.
-
setOnAnswerReceived
Sets a callback to be invoked when an answer is received.- Parameters:
callback- The callback to invoke.
-
setOnCandidateReceived
Sets a callback to be invoked when an ICE candidate is received.- Parameters:
callback- The callback to invoke.
-
setOnJoinReceived
Sets a callback to be invoked when a join message is received.- Parameters:
callback- The callback to invoke.
-
setOnLeaveReceived
Sets a callback to be invoked when a leave message is received.- Parameters:
callback- The callback to invoke.
-
setUserId
Sets the user ID for this client.- Parameters:
userId- The user ID to set.
-
setRemotePeerId
Sets the remote peer ID.- Parameters:
remotePeerId- The remote peer ID to set.
-
getUserId
Gets the user ID for this client.- Returns:
- The user ID.
-
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.
-