This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const stopAudio = () => { | |
| rtc.localAudioTrack.close(); | |
| rtc.client.unpublish(rtc.localAudioTrack); | |
| btnMic.classList.remove("active"); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const leave = () => { | |
| stopVideo(); | |
| stopAudio(); | |
| rtc.client.leave(); | |
| btnStop.classList.add("hidden"); | |
| btnStart.classList.remove("hidden"); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| btnStop.addEventListener("click", () => { | |
| leave(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const startAudio = async () => { | |
| rtc.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack(); | |
| rtc.client.publish(rtc.localAudioTrack); | |
| btnMic.classList.add("active"); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const startVideo = async () => { | |
| me.classList.add("connecting"); | |
| rtc.localVideoTrack = await AgoraRTC.createCameraVideoTrack(); | |
| rtc.client.publish(rtc.localVideoTrack); | |
| me.classList.remove("connecting"); | |
| rtc.localVideoTrack.play("me"); | |
| btnCam.classList.add("active"); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function startBasicCall() { | |
| join().then(() => { | |
| startVideo(); | |
| startAudio(); | |
| rtc.client.on("user-published", async (user, mediaType) => { | |
| await rtc.client.subscribe(user, mediaType); | |
| remote.classList.remove("waiting"); | |
| if (mediaType === "video") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| btnStart.addEventListener("click", () => { | |
| startBasicCall(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const join = async () => { | |
| rtc.client = AgoraRTC.createClient({ mode: "rtc", codec: "vp8" }); | |
| return await rtc.client.join( | |
| options.appId, | |
| options.channel, | |
| options.token, | |
| null | |
| ); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const btnCam = document.getElementById("btnCam"); | |
| const btnMic = document.getElementById("btnMic"); | |
| const btnStart = document.getElementById("btnStart"); | |
| const btnStop = document.getElementById("btnStop"); | |
| const me = document.getElementById("me"); | |
| const remote = document.getElementById("remote"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rtc = { | |
| client: null, | |
| localAudioTrack: null, | |
| localVideoTrack: null, | |
| }; |