Skip to content

Commit 5dcec6a

Browse files
committed
updated documentation for configuration object
1 parent 1e7e894 commit 5dcec6a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lib/src/components/VideoCall.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface icePayObj extends payloadObj {
3838
3939
* @desc Wrapper component containing the logic necessary for peer connections using WebRTC APIs (RTCPeerConnect API + MediaSession API) and WebSockets.
4040
*
41-
* ws, localVideo, remoteVideo, peerRef, localStream, otherUser, senders are all mutable ref objects that are created using the useRef hook. The useRef hook allows you to persist values between renders and it is used to store a mutable value that does NOT cause a re-render when updated.
41+
* ws, localVideo, remoteVideo, peerRef, localStreamRef, otherUser, senders are all mutable ref objects that are created using the useRef hook. The useRef hook allows you to persist values between renders and it is used to store a mutable value that does NOT cause a re-render when updated.
4242
*
4343
* The WebSocket connection (ws.current) is established using the useEffect hook and once the component mounts, the Socket component is rendered. The Socket component adds event listeners that handle the offer-answer model and the exchange of SDP objects between peers and the socket.
4444
*
@@ -86,9 +86,9 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
8686
const otherUser = useRef<string>();
8787

8888
/**
89-
* @type {mutable ref object} localStream - It cannot be null or undefined.
89+
* @type {mutable ref object} localStreamRef - It cannot be null or undefined.
9090
*/
91-
const localStream = useRef<MediaStream>(null!);
91+
const localStreamRef = useRef<MediaStream>(null!);
9292

9393
/**
9494
* @type {mutable ref array} senders -
@@ -195,7 +195,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
195195
const openUserMedia = async (): Promise<void> => {
196196
try {
197197
if (localVideo.current){
198-
localStream.current = localVideo.current.srcObject = await navigator.mediaDevices.getUserMedia(constraints);
198+
localStreamRef.current = localVideo.current.srcObject = await navigator.mediaDevices.getUserMedia(constraints);
199199
}
200200
} catch (error) {
201201
console.log('Error in openUserMedia: ', error);
@@ -208,23 +208,22 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
208208
*/
209209
const callUser = (userID: string): void => {
210210
peerRef.current = createPeer(userID);
211-
localStream.current.getTracks().forEach((track) => senders.current.push(peerRef.current.addTrack(track, localStream.current)));
211+
localStreamRef.current.getTracks().forEach((track) => senders.current.push(peerRef.current.addTrack(track, localStreamRef.current)));
212212
};
213213

214214
/**
215215
* @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
216216
* @param {string} userID
217217
* @returns {RTCPeerConnection} RTCPeerConnection object
218218
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionstatechange_event and other events
219+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
219220
*/
220221
const createPeer = (userID: string): RTCPeerConnection => {
221222
const peer: RTCPeerConnection = new RTCPeerConnection(configuration);
222223
peer.onicecandidate = handleIceCandidateEvent;
223224
peer.ontrack = handleTrackEvent;
224225
peer.onnegotiationneeded = () => handleNegotiationNeededEvent(userID);
225226

226-
console.log('registerPeerConnectionListners has activated');
227-
228227
peer.addEventListener('negotiationneeded', () => {
229228
console.log('negotiationneeded event has fired');
230229
});
@@ -321,7 +320,7 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
321320

322321
peerRef.current.setRemoteDescription(desc)
323322
.then(() => {
324-
localStream.current?.getTracks().forEach((track) => peerRef.current?.addTrack(track, localStream.current));
323+
localStreamRef.current?.getTracks().forEach((track) => peerRef.current?.addTrack(track, localStreamRef.current));
325324
})
326325
.then(() => {
327326
return peerRef.current?.createAnswer();
@@ -413,8 +412,8 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
413412
screenTrack.onended = function() { // ended event is fired when playback or streaming has stopped because the end of the media was reached or because no further data is available
414413
senders.current
415414
?.find(sender => sender.track?.kind === 'video')
416-
?.replaceTrack(localStream.current.getTracks()[1]); //
417-
localVideo.current.srcObject = localStream.current; // changing local video displayed back to webcam
415+
?.replaceTrack(localStreamRef.current.getTracks()[1]); //
416+
localVideo.current.srcObject = localStreamRef.current; // changing local video displayed back to webcam
418417
};
419418
});
420419
}

lib/src/constants/rtcConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @type {Object} configuration - The RTCConfiguration object is used to provide configuration options for how an RTCPeerConnection should be created.
2+
* @type {RTCConfiguration} configuration - The RTCConfiguration object is used to provide configuration options for how an RTCPeerConnection should be created.
33
*
44
* @property {array} iceServers - An array of RTCIceServer objects, each describing one server which
55
* may be used by the ICE agent. These servers are typically STUN and/or TURN servers. If this

0 commit comments

Comments
 (0)