Skip to content

Commit 2c46788

Browse files
committed
updated jsdoc for handleReceiveCall
1 parent 52cb87a commit 2c46788

File tree

7 files changed

+113
-30
lines changed

7 files changed

+113
-30
lines changed

dist/src/components/VideoCall.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// <reference types="react" />
22
/**
3+
* @func VideoCall
4+
* @param {String} props.URL - ws or wss link
5+
* @param {object} props.mediaOptions video embed attributes
6+
37
* @desc Wrapper component containing the logic necessary for peer connections using WebRTC APIs (RTCPeerConnect API + MediaSession API) and WebSockets.
48
*
59
* 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.
@@ -11,9 +15,6 @@
1115
* @type {state} username - username state stores the name the client enters. All users (see getUsers) will be able to see an updated list of all other users whenever a new user logs in or leaves.
1216
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
1317
*
14-
* @param {Object} props
15-
* @param {String} props.URL - ws or wss link
16-
* @param {object} props.mediaOptions video embed attributes
1718
* @returns A component that renders two VideoComponents,
1819
*/
1920
declare const VideoCall: ({ URL, mediaOptions }: {

dist/src/components/VideoCall.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const mediaStreamConstraints_1 = __importDefault(require("../constants/mediaStre
4444
const rtcConfiguration_1 = __importDefault(require("../constants/rtcConfiguration"));
4545
const { LOGIN, ICECANDIDATE, OFFER, ANSWER, LEAVE } = actions_1.default;
4646
/**
47+
* @func VideoCall
48+
* @param {String} props.URL - ws or wss link
49+
* @param {object} props.mediaOptions video embed attributes
50+
4751
* @desc Wrapper component containing the logic necessary for peer connections using WebRTC APIs (RTCPeerConnect API + MediaSession API) and WebSockets.
4852
*
4953
* 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.
@@ -55,24 +59,21 @@ const { LOGIN, ICECANDIDATE, OFFER, ANSWER, LEAVE } = actions_1.default;
5559
* @type {state} username - username state stores the name the client enters. All users (see getUsers) will be able to see an updated list of all other users whenever a new user logs in or leaves.
5660
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
5761
*
58-
* @param {Object} props
59-
* @param {String} props.URL - ws or wss link
60-
* @param {object} props.mediaOptions video embed attributes
6162
* @returns A component that renders two VideoComponents,
6263
*/
6364
const VideoCall = ({ URL, mediaOptions }) => {
6465
const [username, setUsername] = (0, react_1.useState)('');
6566
const [users, setUsers] = (0, react_1.useState)();
6667
/**
67-
* @type {mutable ref WebSocket object} ws is the mutable ref object that contains the WebSocket object (ws.current). It cannot be null or undefined.
68+
* @type {mutable ref WebSocket object} ws is the mutable ref object that contains the WebSocket object in its .current property (ws.current). It cannot be null or undefined.
6869
*
69-
* @desc The ws.current WebSocket object is created using the useEffect hook and it will establish the WebSocket connection to the server. This WebSocket connection is made on component mount and the function openUserMedia is invoked, which makes a permissions request for the client's video and audio.
70+
* @desc ws.current property contains the WebSocket object, which is created using the useEffect hook and it establishes the WebSocket connection to the server. The useEffect Hook creates the WebSocket object using the URL parameter when the component mounts and the function openUserMedia() is invoked, which makes a permissions request for the client's video and audio.
7071
*
7172
* ws.current.send enqueues the specified messages that need to be transmitted to the server over the WebSocket connection and this WebSocket connection is connected to the server by using RTConnect's importable SignalingChannel module.
7273
*/
7374
const ws = (0, react_1.useRef)(null);
7475
/**
75-
* @type {mutable ref object} localVideo - video stream of the local user. It will not be null or undefined.
76+
* @type {mutable ref object} localVideo - video element of the local user. It will not be null or undefined.
7677
*/
7778
const localVideo = (0, react_1.useRef)(null);
7879
/**
@@ -125,13 +126,18 @@ const VideoCall = ({ URL, mediaOptions }) => {
125126
* 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
126127
* If Peer B receives a call then we invoke... ^Receive Offer SDP^ --> handleReceiveCall --> createPeer --> ^send Answer SDP^ --> handleIceCandidateMsg --> handleIceCandidateEvent --> once connected, handleTrackEvent
127128
*
128-
* Note: Media is attached to the Peer Connection and sent along with the offers/answers to describe what media each client has. (see RTCPeerConnection.addTrack() MDN)
129+
* Note: Media is attached to the Peer Connection and sent along with the offers/answers to describe what media each client has.
130+
*
131+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack
129132
*/
130133
/**
131134
* @func handleUsername
132-
* @desc When the client enters a username and clicks the Submit Username button, a LOGIN event is triggered and the loginPayload is sent via the WebSocketServer (ws.current.send(loginPayload)) to the backend/server.
133135
*
134-
* Then, username state is updated with the string stored in the userField variable (the username entered by the client when they clicked the Submit Username).
136+
* @desc Invoked when clients click the Submit Username button. A loginPayload object is initiated - it contains the LOGIN event and its payload contains the client's username.
137+
*
138+
* The loginPayload object is sent via the WebSocketServer (ws.current.send(loginPayload)) to the backend/SignalingChannel.
139+
*
140+
* Then, the username state is updated with the userField string (the username entered by the client when they clicked the Submit Username). setUsername(userField)
135141
*/
136142
const handleUsername = () => {
137143
const loginPayload = {
@@ -166,9 +172,9 @@ const VideoCall = ({ URL, mediaOptions }) => {
166172
};
167173
/**
168174
* @async
169-
* @function openUserMedia
170-
* @param
171-
* @desc Asks for the client's permissions to open their webcam and microphone.
175+
* @function openUserMedia: Invoked in useEffect Hook. openUserMedia uses the constraints provided Requests the clients' browser permissions to open their webcam and microphone.
176+
* @param {void}
177+
* @desc If the localVideo.current property exists, the MediaStream from the local camera is assigned to the local video element.
172178
*/
173179
const openUserMedia = () => __awaiter(void 0, void 0, void 0, function* () {
174180
try {

dist/src/utils/Livestream.d.ts

Whitespace-only changes.

dist/src/utils/Livestream.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
3+
/*
4+
const openUserMedia = async (): Promise<void> => {
5+
try {
6+
if (localVideo.current){
7+
localStream.current = localVideo.current.srcObject = await navigator.mediaDevices.getUserMedia(constraints);
8+
}
9+
} catch (error) {
10+
console.log('Error in openUserMedia: ', error);
11+
}
12+
};
13+
14+
15+
// In this example, a MediaStream from a camera is assigned to a newly-created <video> element.
16+
const mediaStream = await navigator.mediaDevices.getUserMedia({video: true});
17+
const video = document.createElement('video');
18+
video.srcObject = mediaStream;
19+
20+
21+
// In this example, a new MediaSource is assigned to a newly-created <video> element.
22+
const mediaSource = new MediaSource();
23+
const video = document.createElement('video');
24+
video.srcObject = mediaSource;
25+
26+
// First, a MediaStream from a camera is assigned to a newly-created <video> element, with fallback for older browsers.
27+
const mediaStream = await navigator.mediaDevices.getUserMedia({video: true});
28+
const video = document.createElement('video');
29+
if ('srcObject' in video) {
30+
video.srcObject = mediaStream;
31+
} else {
32+
// Avoid using this in new browsers, as it is going away.
33+
video.src = URL.createObjectURL(mediaStream);
34+
}
35+
*/

lib/src/components/VideoCall.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ interface icePayObj extends payloadObj {
3232
}
3333

3434
/**
35+
* @func VideoCall
36+
* @param {String} props.URL - ws or wss link
37+
* @param {object} props.mediaOptions video embed attributes
38+
3539
* @desc Wrapper component containing the logic necessary for peer connections using WebRTC APIs (RTCPeerConnect API + MediaSession API) and WebSockets.
3640
*
3741
* 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.
@@ -43,9 +47,6 @@ interface icePayObj extends payloadObj {
4347
* @type {state} username - username state stores the name the client enters. All users (see getUsers) will be able to see an updated list of all other users whenever a new user logs in or leaves.
4448
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
4549
*
46-
* @param {Object} props
47-
* @param {String} props.URL - ws or wss link
48-
* @param {object} props.mediaOptions video embed attributes
4950
* @returns A component that renders two VideoComponents,
5051
*/
5152
const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { controls: boolean, style: { width: string, height: string }}}): JSX.Element => {
@@ -55,16 +56,16 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
5556
const [users, setUsers] = useState<JSX.Element[]>();
5657

5758
/**
58-
* @type {mutable ref WebSocket object} ws is the mutable ref object that contains the WebSocket object (ws.current). It cannot be null or undefined.
59+
* @type {mutable ref WebSocket object} ws is the mutable ref object that contains the WebSocket object in its .current property (ws.current). It cannot be null or undefined.
5960
*
60-
* @desc The ws.current WebSocket object is created using the useEffect hook and it will establish the WebSocket connection to the server. This WebSocket connection is made on component mount and the function openUserMedia is invoked, which makes a permissions request for the client's video and audio.
61+
* @desc ws.current property contains the WebSocket object, which is created using the useEffect hook and it establishes the WebSocket connection to the server. The useEffect Hook creates the WebSocket object using the URL parameter when the component mounts and the function openUserMedia() is invoked, which makes a permissions request for the client's video and audio.
6162
*
6263
* ws.current.send enqueues the specified messages that need to be transmitted to the server over the WebSocket connection and this WebSocket connection is connected to the server by using RTConnect's importable SignalingChannel module.
6364
*/
6465
const ws = useRef<WebSocket>(null!);
6566

6667
/**
67-
* @type {mutable ref object} localVideo - video stream of the local user. It will not be null or undefined.
68+
* @type {mutable ref object} localVideo - video element of the local user. It will not be null or undefined.
6869
*/
6970
const localVideo = useRef<HTMLVideoElement>(null!);
7071

@@ -126,14 +127,19 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
126127
* 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
127128
* If Peer B receives a call then we invoke... ^Receive Offer SDP^ --> handleReceiveCall --> createPeer --> ^send Answer SDP^ --> handleIceCandidateMsg --> handleIceCandidateEvent --> once connected, handleTrackEvent
128129
*
129-
* Note: Media is attached to the Peer Connection and sent along with the offers/answers to describe what media each client has. (see RTCPeerConnection.addTrack() MDN)
130+
* Note: Media is attached to the Peer Connection and sent along with the offers/answers to describe what media each client has.
131+
*
132+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack
130133
*/
131134

132135
/**
133-
* @func handleUsername
134-
* @desc When the client enters a username and clicks the Submit Username button, a LOGIN event is triggered and the loginPayload is sent via the WebSocketServer (ws.current.send(loginPayload)) to the backend/server.
136+
* @func handleUsername
137+
*
138+
* @desc Invoked when clients click the Submit Username button. A loginPayload object is initiated - it contains the LOGIN event and its payload contains the client's username.
139+
*
140+
* The loginPayload object is sent via the WebSocketServer (ws.current.send(loginPayload)) to the backend/SignalingChannel.
135141
*
136-
* Then, username state is updated with the string stored in the userField variable (the username entered by the client when they clicked the Submit Username).
142+
* Then, the username state is updated with the userField string (the username entered by the client when they clicked the Submit Username). setUsername(userField)
137143
*/
138144
const handleUsername = (): void => {
139145
const loginPayload: loginPayObj = {
@@ -175,9 +181,9 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
175181

176182
/**
177183
* @async
178-
* @function openUserMedia
179-
* @param
180-
* @desc Asks for the client's permissions to open their webcam and microphone.
184+
* @function openUserMedia: Invoked in useEffect Hook. openUserMedia uses the constraints provided Requests the clients' browser permissions to open their webcam and microphone.
185+
* @param {void}
186+
* @desc If the localVideo.current property exists, the MediaStream from the local camera is assigned to the local video element.
181187
*/
182188
const openUserMedia = async (): Promise<void> => {
183189
try {

lib/src/utils/Livestream.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
2+
3+
/*
4+
const openUserMedia = async (): Promise<void> => {
5+
try {
6+
if (localVideo.current){
7+
localStream.current = localVideo.current.srcObject = await navigator.mediaDevices.getUserMedia(constraints);
8+
}
9+
} catch (error) {
10+
console.log('Error in openUserMedia: ', error);
11+
}
12+
};
13+
14+
15+
// In this example, a MediaStream from a camera is assigned to a newly-created <video> element.
16+
const mediaStream = await navigator.mediaDevices.getUserMedia({video: true});
17+
const video = document.createElement('video');
18+
video.srcObject = mediaStream;
19+
20+
21+
// In this example, a new MediaSource is assigned to a newly-created <video> element.
22+
const mediaSource = new MediaSource();
23+
const video = document.createElement('video');
24+
video.srcObject = mediaSource;
25+
26+
// First, a MediaStream from a camera is assigned to a newly-created <video> element, with fallback for older browsers.
27+
const mediaStream = await navigator.mediaDevices.getUserMedia({video: true});
28+
const video = document.createElement('video');
29+
if ('srcObject' in video) {
30+
video.srcObject = mediaStream;
31+
} else {
32+
// Avoid using this in new browsers, as it is going away.
33+
video.src = URL.createObjectURL(mediaStream);
34+
}
35+
*/

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.60",
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)