Skip to content

Commit 1e7e894

Browse files
committed
edited documentation for callUser and createPeer functions
1 parent 357f50e commit 1e7e894

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/src/components/VideoCall.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
121121
* | |-------------------|------------------>| Peer B's NAT
122122
* |<--------------------------|-------------------| Accepting Peer A's call, sending Answer SDP
123123
* |<--------------------------|-------------------| Peer B's ICE Candidates are now being trickled in to peer A for connectivity.
124-
* |-------------------------->|------------------>| ICE Candidates from Peer A, these steps repeat and are only necessary if Peer B can't connect to the earlier candidates sent.
125-
* |<--------------------------|-------------------| ICE Candidate trickling from Peer B, could also take a second if there's a firewall to be circumvented.
124+
* |-------------------------->|------------------>| ICE Candidates from Peer A, these steps repeat and are only necessary if Peer B can't connect to the
125+
* | | | | earlier candidates sent.
126+
* |<--------------------------|-------------------| ICE Candidate trickling from Peer B, could also take a second if there's a firewall to be
127+
* | | | | circumvented.
126128
* | | | | Connected! Peer to Peer connection is made and now both users are streaming data to eachother!
127129
*
128130
* If Peer A starts a call their order of functions being invoked is... handleOffer --> callUser --> createPeer --> peerRef.current.negotiationNeeded event (handleNegotiationNeededEvent) --> ^send Offer SDP^ --> start ICE trickle, handleIceCandidateEvent --> ^receive Answer^ SDP --> handleIceCandidateMsg --> once connected, handleTrackEvent
@@ -154,7 +156,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
154156

155157
/**
156158
* @func handleOffer
157-
* @desc When a username is entered that the client wants to "Call" and the client clicks the Call button, into the input field, this starts the Offer-Answer Model exchange
159+
* @desc When a username is entered into the input field that the client wants to "Call" and the client clicks the Call button, this starts the SDP Offer-Answer exchange
158160
*/
159161
const handleOffer = (): void => {
160162
const inputField:HTMLInputElement | null = document.querySelector('#receiverName');
@@ -201,7 +203,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
201203
};
202204

203205
/**
204-
* @function callUser - Constructs a new RTCPeerConnection object that also adds the local client's media tracks to this object.
206+
* @function callUser - Constructs a new RTCPeerConnection object using the createPeer function and then adds the local client's (Peer A/caller) media tracks to peer connection ref object.
205207
* @param {string} userID
206208
*/
207209
const callUser = (userID: string): void => {
@@ -216,7 +218,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
216218
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event and other events
217219
*/
218220
const createPeer = (userID: string): RTCPeerConnection => {
219-
const peer:RTCPeerConnection = new RTCPeerConnection(configuration);
221+
const peer: RTCPeerConnection = new RTCPeerConnection(configuration);
220222
peer.onicecandidate = handleIceCandidateEvent;
221223
peer.ontrack = handleTrackEvent;
222224
peer.onnegotiationneeded = () => handleNegotiationNeededEvent(userID);
@@ -253,8 +255,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
253255
* @param {string} userID
254256
*/
255257
function handleNegotiationNeededEvent(userID: string): void {
256-
peerRef.current
257-
?.createOffer()
258+
peerRef.current?.createOffer()
258259
.then((offer) => {
259260
return peerRef.current?.setLocalDescription(offer);
260261
})

0 commit comments

Comments
 (0)