Skip to content

Commit f97447a

Browse files
committed
updated jsdoc for handleReceiveCall
1 parent 8d31220 commit f97447a

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

lib/src/components/VideoCall.tsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,21 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
190190
};
191191

192192
/**
193-
* @desc Constructs a new RTCPeerConnection object that also adds the local client's media tracks to this object.
194-
* @param {string} userID
193+
* @function callUser
194+
* @desc Constructs a new RTCPeerConnection object that also adds the local client's media tracks to this object.
195+
* @param {string} userID
195196
*/
196197
const callUser = (userID: string): void => {
197198
peerRef.current = createPeer(userID);
198199
localStream.current.getTracks().forEach((track) => senders.current.push(peerRef.current.addTrack(track, localStream.current)));
199200
};
200201

201202
/**
202-
* @desc Creates a new RTCPeerConnection object, which represents a WebRTC connection between the local device and a remote peer and adds event listeners to it
203-
* @param {string} userID
204-
* @returns {RTCPeerConnection} RTCPeerConnection object
205-
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event and other events
203+
* @function createPeer
204+
* @desc Creates a new RTCPeerConnection object, which represents a WebRTC connection between the local device and a remote peer and adds event listeners to it
205+
* @param {string} userID
206+
* @returns {RTCPeerConnection} RTCPeerConnection object
207+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event and other events
206208
*/
207209
const createPeer = (userID: string): RTCPeerConnection => {
208210
const peer:RTCPeerConnection = new RTCPeerConnection(configuration);
@@ -260,14 +262,47 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
260262
}
261263

262264
/**
263-
* @desc When an offer is received from the SignalingChannel, this function is invoked, creating a new RTCPeerConnection with the local client's media attached and an Answer is created that is then sent back to the original caller through the WebSocket connection.
264-
* @param {RTCSessionDescriptionInit} data
265-
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createAnswer
265+
* @namespace handleReceiveCall
266+
* @function handleReceiveCall - When Peer A (caller) calls Peer B (callee), Peer B receives an Offer from the SignalingChannel and this function is invoked. It creates a new RTCPeerConnection with the Peer A's media attached and an Answer is created. The Answer is then sent back to Peer A through the SignalingChannel.
267+
* @returns answerPayload object with ANSWER action type and the local description as the payload is sent via WebSocket.
268+
* @param {Object} data payload object
269+
* @property {string} data.sender is the person making the call
270+
* @property { RTCSessionDescriptionInit object } data.payload object providing the session description and it consists of a string containing a SDP message indicating an Offer from Peer A. This value is an empty string ("") by default and may not be null.
271+
*
272+
* @function createPeer - Creates a new RTCPeerConnection object, which represents a WebRTC connection between the local device and a remote peer and adds event listeners to it
273+
* @memberof handleReceiveCall
274+
*
275+
* @function RTCSessionDescription - initializes a RTCSessionDescription object, which consists of a description type indicating which part of the offer/answer negotiation process it describes and of the SDP descriptor of the session.
276+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription
277+
* @memberof handleReceiveCall
278+
*
279+
* @function setRemoteDescription - If Peer B wants to accept the offer, setRemoteDescription() is called to set the RTCSessionDescriptionInit object's remote description to the incoming offer from Peer A. The description specifies the properties of the remote end of the connection, including the media format.
280+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription
281+
* @memberof handleReceiveCall
282+
*
283+
* @function createAnswer - Creates an Answer to the Offer received from Peer A during the offer/answer negotiation of a WebRTC connection. The Answer contains information about any media already attached to the session, codecs and options supported by the browser, and any ICE candidates already gathered.
284+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createAnswer
285+
* @memberof handleReceiveCall
286+
*
287+
* @function setLocalDescription - WebRTC selects an appropriate local configuration by invoking setLocalDescription(), which automatically generates an appropriate Answer in response to the received Offer from Peer A. Then we send the Answer through the signaling channel back to Peer A.
288+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setLocalDescription
289+
* @memberof handleReceiveCall
290+
*
291+
* @returns {Promise} A Promise whose fulfillment handler is called with an RTCSessionDescriptionInit object containing the SDP Answer to be delivered to Peer A.
292+
*
266293
*/
267294
function handleReceiveCall(data: { sender: string, payload: RTCSessionDescriptionInit }): void {
268295
otherUser.current = data.sender;
269296
peerRef.current = createPeer(data.sender);
297+
298+
/**
299+
* @type {RTCSessionDescriptionInit object} desc - consists of a description type indicating which part of the answer negotiation process it describes and the SDP descriptor of the session.
300+
* @params {string} desc.type - description type with incoming offer
301+
* @params {string} desc.sdp - string containing a SDP message, the format for describing multimedia communication sessions. SDP contains the codec, source address, and timing information of audio and video
302+
* @see https://developer.mozilla.org/en-US/docs/Glossary/SDP
303+
*/
270304
const desc = new RTCSessionDescription(data.payload);
305+
271306
peerRef.current.setRemoteDescription(desc)
272307
.then(() => {
273308
localStream.current?.getTracks().forEach((track) => peerRef.current?.addTrack(track, localStream.current));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "rtconnect",
3-
"version": "0.0.53",
2+
"name": "rtc-test-run",
3+
"version": "0.0.59",
44
"description": "A lightweight React library to set up live streaming and real-time video calls with peers.",
55
"main": "./dist/src/index.js",
66
"types": "./dist/src/index.d.ts",

0 commit comments

Comments
 (0)