Skip to content

Commit 295dffd

Browse files
Vineeth Sicywind
Vineeth S
authored andcommitted
added comments for open live
1 parent 61f2807 commit 295dffd

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

Group-Video/OpenVideoCall-Web/src/pages/index/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { RESOLUTION_ARR } from "@/utils/Settings";
1111
import Polyfill from "@/utils/Polyfill";
1212
import Validator from "@/utils/Validate";
1313

14+
// Parses the query params from the url
15+
1416
const getParameterByName = (name, url) => {
1517
if (!url) {
1618
url = window.location.href;
@@ -23,6 +25,8 @@ const getParameterByName = (name, url) => {
2325
return decodeURIComponent(results[2].replace(/\+/g, " "));
2426
};
2527

28+
29+
// Intializes the ui with necessary video profile options. (resolution, framerate, bitrate etc.)
2630
const uiInit = () => {
2731
document.querySelector(
2832
".login-title"
@@ -73,6 +77,8 @@ const uiInit = () => {
7377
}
7478
};
7579

80+
// Channel name validator
81+
7682
const validate = channelName => {
7783
if (Validator.isNonEmpty(channelName)) {
7884
return "Cannot be empty!";
@@ -90,6 +96,8 @@ const validate = channelName => {
9096
return "";
9197
};
9298

99+
100+
93101
const subscribeMouseEvent = () => {
94102
// Click Join and go to the meeting room
95103
$("#joinBtn").on("click", () => {
@@ -112,6 +120,7 @@ const subscribeMouseEvent = () => {
112120
$("#channel").addClass("is-success");
113121
validateIcon.append(`<i class="ag-icon icon-correct"></i>`);
114122

123+
// This config data is added to the cookies to be used in other pages.
115124
let postData = {
116125
baseMode: document.querySelector("#baseMode").dataset.value,
117126
transcode: $('input[name="transcode"]:checked').val(),

Group-Video/OpenVideoCall-Web/src/pages/meeting/meeting.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const globalLog = logger.init("global", "blue");
3636
const shareLog = logger.init("share", "yellow");
3737
const localLog = logger.init("local", "green");
3838

39+
// Initialize the options from cookies (set from index.js and precall.js)
40+
3941
const optionsInit = () => {
4042
let options = {
4143
videoProfile: Cookies.get("videoProfile").split(",")[0] || "480p_4",
@@ -60,6 +62,8 @@ const optionsInit = () => {
6062
return options;
6163
};
6264

65+
// Initalizes the User Interface
66+
6367
const uiInit = options => {
6468
document.querySelector(
6569
".ag-header-lead span"
@@ -92,11 +96,17 @@ const uiInit = options => {
9296
}
9397
};
9498

99+
// Intializes the Agora client object
100+
95101
const clientInit = (client, options) => {
96102
return new Promise((resolve, reject) => {
103+
// Initialize the agora client object with appid
97104
client.init(options.key, () => {
98105
globalLog("AgoraRTC client initialized");
106+
// Set low stream parameter
107+
// Read more here https://docs.agora.io/en/Video/API%20Reference/web/interfaces/agorartc.client.html#setlowstreamparameter
99108
let lowStreamParam = RESOLUTION_ARR[options.videoProfileLow];
109+
// Join the channel
100110
client.join(
101111
options.token,
102112
options.channel,
@@ -122,8 +132,8 @@ const clientInit = (client, options) => {
122132
};
123133

124134
/**
125-
*
126-
* @param {*} uid
135+
* @description Initializes the local stream
136+
* @param {*} uid User Id
127137
* @param {*} options global option
128138
* @param {*} config stream config
129139
*/
@@ -135,6 +145,7 @@ const streamInit = (uid, options, config) => {
135145
screen: false
136146
};
137147

148+
// Modify default config based on attendee mode
138149
switch (options.attendeeMode) {
139150
case "audio-only":
140151
defaultConfig.video = false;
@@ -147,12 +158,15 @@ const streamInit = (uid, options, config) => {
147158
case "video":
148159
break;
149160
}
161+
// Create an Agora stream using the above parameters
150162
// eslint-disable-next-line
151163
let stream = AgoraRTC.createStream(merge(defaultConfig, config));
164+
// Set the selected video profile
152165
stream.setVideoProfile(options.videoProfile);
153166
return stream;
154167
};
155168

169+
// A function to stop and reset screen sharing related features.
156170
const shareEnd = () => {
157171
try {
158172
shareClient && shareClient.unpublish(shareStream);
@@ -172,26 +186,38 @@ const shareEnd = () => {
172186
}
173187
};
174188

189+
190+
// Start screen sharing
175191
const shareStart = () => {
176192
ButtonControl.disable(".shareScreenBtn");
193+
194+
// Create a new client for the screen sharing stream.
195+
177196
// eslint-disable-next-line
178197
shareClient = AgoraRTC.createClient({
179198
mode: options.transcode
180199
});
200+
201+
// Create a new options object for screen sharing.
181202
let shareOptions = merge(options, {
182203
uid: SHARE_ID
183204
});
205+
206+
// Initalializes the client with the screen sharing options.
184207
clientInit(shareClient, shareOptions).then(uid => {
208+
// New config for screen sharing stream
185209
let config = {
186210
screen: true,
187211
video: false,
188212
audio: false,
189213
extensionId: "minllpmhdgpndnkomcoccfekfegnlikg",
190214
mediaSource: "application"
191215
};
216+
// Intialize the screen sharing stream with the necessary parameters.
192217
shareStream = streamInit(uid, shareOptions, config);
193218
shareStream.init(
194219
() => {
220+
// Once the stream is intialized, update the relevant ui and publish the stream.
195221
ButtonControl.enable(".shareScreenBtn");
196222
shareStream.on("stopScreenSharing", () => {
197223
shareEnd();
@@ -203,6 +229,7 @@ const shareStart = () => {
203229
});
204230
},
205231
err => {
232+
// Appropriate error handling if screen sharing doesn't work.
206233
ButtonControl.enable(".shareScreenBtn");
207234
shareLog("getUserMedia failed", err);
208235
shareEnd();
@@ -221,6 +248,7 @@ const shareStart = () => {
221248
});
222249
};
223250

251+
// Relevant code if you are using the screen sharing extension for previous versions of chrome.
224252
window.installSuccess = (...args) => {
225253
globalLog(...args);
226254
};
@@ -233,6 +261,7 @@ window.installError = (...args) => {
233261
);
234262
};
235263

264+
// Helper function to remove stream from UI
236265
const removeStream = id => {
237266
streamList.map((item, index) => {
238267
if (item.getId() === id) {
@@ -249,6 +278,7 @@ const removeStream = id => {
249278
Renderer.customRender(streamList, options.displayMode, mainId);
250279
};
251280

281+
// Helper function to add stream to UI
252282
const addStream = (stream, push = false) => {
253283
let id = stream.getId();
254284
// Check for redundant
@@ -267,12 +297,14 @@ const addStream = (stream, push = false) => {
267297
Renderer.customRender(streamList, options.displayMode, mainId);
268298
};
269299

300+
// Helper function to fetch video streams from the data structure
270301
const getStreamById = id => {
271302
return streamList.filter(item => {
272303
return item.getId() === id;
273304
})[0];
274305
};
275306

307+
// enable dual stream
276308
const enableDualStream = () => {
277309
client.enableDualStream(
278310
function() {
@@ -284,6 +316,7 @@ const enableDualStream = () => {
284316
);
285317
};
286318

319+
// for setting the high stream in dual stream configuration.
287320
const setHighStream = (prev, next) => {
288321
if (prev === next) {
289322
return;
@@ -306,6 +339,7 @@ const setHighStream = (prev, next) => {
306339
// Set next stream to high
307340
nextStream && client.setRemoteVideoStreamType(nextStream, 0);
308341
};
342+
309343
/**
310344
* Add callback for client event to control streams
311345
* @param {*} client
@@ -341,6 +375,7 @@ const subscribeStreamEvents = () => {
341375
});
342376
});
343377

378+
// When a peer leaves
344379
client.on("peer-leave", function(evt) {
345380
let id = evt.uid;
346381
localLog("Peer has left: " + id);
@@ -362,6 +397,7 @@ const subscribeStreamEvents = () => {
362397
removeStream(evt.uid);
363398
});
364399

400+
// when a stream is subscribed
365401
client.on("stream-subscribed", function(evt) {
366402
let stream = evt.stream;
367403
localLog("Got stream-subscribed event");
@@ -370,6 +406,7 @@ const subscribeStreamEvents = () => {
370406
addStream(stream);
371407
});
372408

409+
// when a stream is removed
373410
client.on("stream-removed", function(evt) {
374411
let stream = evt.stream;
375412
let id = stream.getId();
@@ -393,6 +430,7 @@ const subscribeStreamEvents = () => {
393430
});
394431
};
395432

433+
// Subscribe the various mouse events in the UI like clicks
396434
const subscribeMouseEvents = () => {
397435
$(".displayModeBtn").on("click", function(e) {
398436
if (
@@ -522,6 +560,7 @@ const subscribeMouseEvents = () => {
522560
});
523561
};
524562

563+
// Get various scheduled network stats
525564
const infoDetectSchedule = () => {
526565
let no = streamList.length;
527566
for (let i = 0; i < no; i++) {

0 commit comments

Comments
 (0)