Skip to content

Instantly share code, notes, and snippets.

View rebelchris's full-sized avatar
🏠
Working from home

Chris Bongers rebelchris

🏠
Working from home
View GitHub Profile
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:03
Stop audio function
const stopAudio = () => {
rtc.localAudioTrack.close();
rtc.client.unpublish(rtc.localAudioTrack);
btnMic.classList.remove("active");
};
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:03
Leave function
const leave = () => {
stopVideo();
stopAudio();
rtc.client.leave();
btnStop.classList.add("hidden");
btnStart.classList.remove("hidden");
};
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:02
Button stop
btnStop.addEventListener("click", () => {
leave();
});
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:02
Start audio function
const startAudio = async () => {
rtc.localAudioTrack = await AgoraRTC.createMicrophoneAudioTrack();
rtc.client.publish(rtc.localAudioTrack);
btnMic.classList.add("active");
};
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:01
Start video function
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");
};
@rebelchris
rebelchris / script.js
Last active January 23, 2021 15:07
Start basic call function
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") {
@rebelchris
rebelchris / script.js
Created January 23, 2021 15:00
Button start
btnStart.addEventListener("click", () => {
startBasicCall();
});
@rebelchris
rebelchris / script.js
Created January 23, 2021 14:59
Join function
const join = async () => {
rtc.client = AgoraRTC.createClient({ mode: "rtc", codec: "vp8" });
return await rtc.client.join(
options.appId,
options.channel,
options.token,
null
);
};
@rebelchris
rebelchris / script.js
Created January 23, 2021 14:59
All variables
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");
@rebelchris
rebelchris / script.js
Created January 23, 2021 14:58
RTC Variable
let rtc = {
client: null,
localAudioTrack: null,
localVideoTrack: null,
};