...
Code Block | ||||
---|---|---|---|---|
| ||||
/** * connect to server */ async function connect() { // hide modal $('#entranceModal').modal('hide'); // disable controls cControls.muteInput(); //create peer connection const pc = new RTCPeerConnection(); //get config object for room creation const roomConfig = cControls.roomConfig(); //kick off connect to server and local room creation try { const session = await sfu.createRoom(roomConfig); // Now we connected to the server (if no exception was thrown) session.on(constants.SFU_EVENT.FAILED, function (e) { if (e.status && e.statusText) { displayError("CONNECTION FAILED: " + e.status + " " + e.statusText); } else if (e.type && e.info) { displayError("CONNECTION FAILED: " + e.info); } else { displayError("CONNECTION FAILED: " + e); } }).on(constants.SFU_EVENT.DISCONNECTED, function (e) { displayError("DISCONNECTED. Refresh the page to enter the room again"); }); const room = session.room(); room.on(constants.SFU_ROOM_EVENT.FAILED, function (e) { displayError(e); }).on(constants.SFU_ROOM_EVENT.OPERATION_FAILED, function (e) { displayError(e.operation + " failed: " + e.error); }) // create local display to show local streams localDisplay = initLocalDisplay(document.getElementById("localDisplay")); // display audio and video control tables await cControls.displayTables(); cControls.onTrack(async function (s) { await publishNewTrack(room, pc, s); }); //create and bind chat to the new room const chatDiv = document.getElementById('messages'); const chatInput = document.getElementById('localMessage'); const chatButton = document.getElementById('sendMessage'); createChat(room, chatDiv, chatInput, chatButton); //setup remote display for showing remote audio/video tracks const remoteDisplay = document.getElementById("display"); initDefaultRemoteDisplay(room, remoteDisplay, {quality: true},{thresholds: [ {parameter: "nackCount", maxLeap: 10}, {parameter: "freezeCount", maxLeap: 10}, {parameter: "packetsLost", maxLeap: 10} ], abrKeepOnGoodQuality: ABR_KEEP_ON_QUALITY, abrTryForUpperQuality: ABR_TRY_UPPER_QUALITY, interval: ABR_QUALITY_CHECK_PERIOD}); //get configured local video streams let streams = cControls.getVideoStreams(); //combine local video streams with audio streams streams.push.apply(streams, cControls.getAudioStreams()); // Publish preconfigured streams publishPreconfiguredStreams(room, pc, streams); } catch (e) { console.error(e); displayError(e); } } |
5. Подробнее о функции connect()
Скрытие модального окна входа и отключение полей ввода до установки соединения с сервером
...