Skip to content

Commit 6e8cabc

Browse files
authored
Merge pull request #45 from oslabs-beta/doc
updated documentation
2 parents 32facd2 + d309695 commit 6e8cabc

File tree

3 files changed

+33
-55
lines changed

3 files changed

+33
-55
lines changed

dist/src/components/VideoCall.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*
99
* The WebSocket message event will filter through various events to determine the payloads that will be sent to other serverside socket connection via WebSocket.
1010
*
11-
* @type {object} ws is the mutable ref object that contains the WebSocket object (ws.current). The ws.current WebSocket object will be created using the useEffect hook and it will establish the WebSocket connection to the server.
12-
* 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.
1311
* @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.
1412
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
1513
*

dist/src/components/VideoCall.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ const { LOGIN, ICECANDIDATE, OFFER, ANSWER, LEAVE } = actions_1.default;
5252
*
5353
* The WebSocket message event will filter through various events to determine the payloads that will be sent to other serverside socket connection via WebSocket.
5454
*
55-
* @type {object} ws is the mutable ref object that contains the WebSocket object (ws.current). The ws.current WebSocket object will be created using the useEffect hook and it will establish the WebSocket connection to the server.
56-
* 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.
5755
* @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.
5856
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
5957
*
@@ -66,9 +64,11 @@ const VideoCall = ({ URL, mediaOptions }) => {
6664
const [username, setUsername] = (0, react_1.useState)('');
6765
const [users, setUsers] = (0, react_1.useState)();
6866
/**
69-
* @type {mutable ref WebSocket object} ws contains the WebSocket object (ws.current). It cannot be null or undefined.
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.
7068
*
71-
* The ws.current WebSocket object will be created using the useEffect hook and it will establish the WebSocket connection to the server.
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+
*
71+
* 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.
7272
*/
7373
const ws = (0, react_1.useRef)(null);
7474
/**
@@ -96,18 +96,13 @@ const VideoCall = ({ URL, mediaOptions }) => {
9696
*/
9797
const senders = (0, react_1.useRef)([]);
9898
/**
99-
* @type {string} userField - the username that is entered in the input field when the Submit Username
100-
* button is clicked.
99+
* @type {string} userField - the username that is entered in the input field when the Submit Username button is clicked.
101100
*/
102101
let userField = '';
103-
let receiver = '';
104102
/**
105-
* @desc
106-
* A WebSocket connection is made on component mount and the function openUserMedia is invoked, which
107-
* makes a permissions request for the client's video and audio is made
108-
* @prop {object} ws.current
109-
110-
*/
103+
* @type {string} receiver - .
104+
*/
105+
let receiver = '';
111106
(0, react_1.useEffect)(() => {
112107
ws.current = new WebSocket(URL);
113108
openUserMedia();
@@ -133,10 +128,10 @@ const VideoCall = ({ URL, mediaOptions }) => {
133128
* 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)
134129
*/
135130
/**
136-
* @desc An event triggered on a button click.
137-
* Once the client enters and submits a name in the username field, this name is set stored in the
138-
* WebSocketServer along with the socket that sent the name to later send messages to the right client
139-
* using this socket.
131+
* @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.
133+
*
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).
140135
*/
141136
const handleUsername = () => {
142137
const loginPayload = {
@@ -146,11 +141,9 @@ const VideoCall = ({ URL, mediaOptions }) => {
146141
ws.current.send(JSON.stringify(loginPayload));
147142
setUsername(userField);
148143
};
149-
// const handleChange = (e): void => {
150-
// setMessage(e.target.value)
151-
// }
152144
/**
153-
* @desc When a name is entered and submitted into the input field, this starts the Offer-Answer Model exchange
145+
* @func handleOffer
146+
* @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
154147
*/
155148
const handleOffer = () => {
156149
const inputField = document.querySelector('#receiverName');
@@ -163,11 +156,8 @@ const VideoCall = ({ URL, mediaOptions }) => {
163156
};
164157
/**
165158
* @function getUser
166-
* @desc When data (the list of connected users) is received from the WebSocketServer/backend, getUser
167-
* function is invoked and it updates the userList state so that the list of currently connected users
168-
* can be displayed on the frontend.
169-
* @param {Array<string>} parsedData - data (the array of usernames that are connected) that is
170-
* returned from backend/WebSocketServer.
159+
* @desc When data (the list of connected users) is received from the WebSocketServer/backend, getUser function is invoked and it updates the userList state so that the list of currently connected users can be displayed on the frontend.
160+
* @param {Array<string>} parsedData - data (the array of usernames that are connected) that is returned from backend/WebSocketServer.
171161
* @returns Re-renders the page with the new User List
172162
*/
173163
const getUsers = (parsedData) => {

lib/src/components/VideoCall.tsx

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ interface icePayObj extends payloadObj {
4040
*
4141
* The WebSocket message event will filter through various events to determine the payloads that will be sent to other serverside socket connection via WebSocket.
4242
*
43-
* @type {object} ws is the mutable ref object that contains the WebSocket object (ws.current). The ws.current WebSocket object will be created using the useEffect hook and it will establish the WebSocket connection to the server.
44-
* 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.
4543
* @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.
4644
* @type {state} users - users state is the list of connected users that is rendered on the frontend.
4745
*
@@ -57,9 +55,11 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
5755
const [users, setUsers] = useState<JSX.Element[]>();
5856

5957
/**
60-
* @type {mutable ref WebSocket object} ws contains the WebSocket object (ws.current). It cannot be null or undefined.
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.
6159
*
62-
* The ws.current WebSocket object will be created using the useEffect hook and it will establish the WebSocket connection to the server.
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+
*
62+
* 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.
6363
*/
6464
const ws = useRef<WebSocket>(null!);
6565

@@ -94,19 +94,15 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
9494
const senders = useRef<RTCRtpSender[]>([]);
9595

9696
/**
97-
* @type {string} userField - the username that is entered in the input field when the Submit Username
98-
* button is clicked.
97+
* @type {string} userField - the username that is entered in the input field when the Submit Username button is clicked.
9998
*/
10099
let userField = '';
100+
101+
/**
102+
* @type {string} receiver - .
103+
*/
101104
let receiver: string | null = '';
102-
103-
/**
104-
* @desc
105-
* A WebSocket connection is made on component mount and the function openUserMedia is invoked, which
106-
* makes a permissions request for the client's video and audio is made
107-
* @prop {object} ws.current
108105

109-
*/
110106
useEffect(() => {
111107
ws.current = new WebSocket(URL);
112108
openUserMedia();
@@ -134,10 +130,10 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
134130
*/
135131

136132
/**
137-
* @desc An event triggered on a button click.
138-
* Once the client enters and submits a name in the username field, this name is set stored in the
139-
* WebSocketServer along with the socket that sent the name to later send messages to the right client
140-
* using this socket.
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.
135+
*
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).
141137
*/
142138
const handleUsername = (): void => {
143139
const loginPayload: loginPayObj = {
@@ -149,12 +145,9 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
149145
setUsername(userField);
150146
};
151147

152-
// const handleChange = (e): void => {
153-
// setMessage(e.target.value)
154-
// }
155-
156148
/**
157-
* @desc When a name is entered and submitted into the input field, this starts the Offer-Answer Model exchange
149+
* @func handleOffer
150+
* @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
158151
*/
159152
const handleOffer = (): void => {
160153
const inputField:HTMLInputElement | null = document.querySelector('#receiverName');
@@ -169,11 +162,8 @@ const VideoCall = ({ URL, mediaOptions }: { URL: string, mediaOptions: { control
169162

170163
/**
171164
* @function getUser
172-
* @desc When data (the list of connected users) is received from the WebSocketServer/backend, getUser
173-
* function is invoked and it updates the userList state so that the list of currently connected users
174-
* can be displayed on the frontend.
175-
* @param {Array<string>} parsedData - data (the array of usernames that are connected) that is
176-
* returned from backend/WebSocketServer.
165+
* @desc When data (the list of connected users) is received from the WebSocketServer/backend, getUser function is invoked and it updates the userList state so that the list of currently connected users can be displayed on the frontend.
166+
* @param {Array<string>} parsedData - data (the array of usernames that are connected) that is returned from backend/WebSocketServer.
177167
* @returns Re-renders the page with the new User List
178168
*/
179169
const getUsers = (parsedData: { payload: string[] }): void => {

0 commit comments

Comments
 (0)