Skip to content

Instantly share code, notes, and snippets.

View digitallysavvy's full-sized avatar
🐼

Hermes digitallysavvy

🐼
View GitHub Profile
@digitallysavvy
digitallysavvy / canvas-to-agora-video-track.js
Created July 9, 2024 17:25
An example of how to use a Canvas element as a custom Agora Video Track
import AgoraRTC from 'agora-rtc-sdk-ng'
// Create the Agora Client
const client = AgoraRTC.createClient({
codec: 'vp9',
mode: 'live',
role: 'host'
})
document.addEventListener('DOMContentLoaded', async () => {
@digitallysavvy
digitallysavvy / Custom-Video-Element-With-Agora.js
Last active April 26, 2024 14:30
An example of how to use the audio and video tracks created by the Agora Web SDK to create a custom `<video />` element and append it to the DOM.
import AgoraRTC from 'agora-rtc-sdk-ng'
// declare audio and video tracks
const [audioTrack, videoTrack] = null
// Initialize the audio and video tracks
if (!audioTrack || !videoTrack) {
[ audioTrack, videoTrack ] = await AgoraRTC.createMicrophoneAndCameraTracks({ audioConfig: 'music_standard', videoConfig: '360p_7' })
}

Architectures

WebRTC (Web Real-Time Communication), an open-source protocol developed by Google, is supported by all major browsers, eliminating the need for third-party audio and video streaming plugins.

However, it's important to understand that while WebRTC facilitates easy setup and direct communication for small-scale applications, it introduces complexities as businesses scale. WebRTC technology was designed for connecting Peer-2-Peer without intermediary servers meaning it can't handle large audiences on its own. There are a few different approaches to implementing scalable backends for WebRTC.

Mesh

Connects participants directly to each other, creating a web-like mesh network. Mesh infrastructures are ideal for: Small group video calls (2–4 participants); P2P file sharing applications; Low-latency gaming applications where direct connection is crucial

graph LR
@digitallysavvy
digitallysavvy / App.tsx
Last active January 9, 2024 02:52
App.tsx for implementing the Agora RTC React SDK using routes.
import { Route, Routes, useNavigate } from 'react-router-dom'
import { ConnectForm } from './components/ConnectForm'
import { LiveVideo } from './components/LiveVideo'
import AgoraRTC, {
AgoraRTCProvider,
useRTCClient,
} from "agora-rtc-react";
import './App.css'
@digitallysavvy
digitallysavvy / LiveVideo.tsx
Last active January 9, 2024 02:42
full implementation of the LiveVideo component using the Agora RTC React SDK.
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import {
LocalUser,
RemoteUser,
useJoin,
useLocalCameraTrack,
useLocalMicrophoneTrack,
usePublish,
@digitallysavvy
digitallysavvy / PubNub-sendMessage+snippet.js
Created October 12, 2020 20:03
a function that uses a PubNub client to send a message into a PubNub channel.
function publishMessage(message, callback) {
var msgConfig = {
channel : channelName,
sendByPost: true,
message: {
uuid: UID,
title: "text",
description: message
}
}
@digitallysavvy
digitallysavvy / initPubNub+snippet.js
Created October 12, 2020 19:37
a function that initializes a new PubNub client with a give Pub and Sub keys.
function initPubNub(pubKey, subKey, uid, channel) {
console.log(pubKey, subKey)
pubNub = new PubNub({
publishKey : pubKey,
subscribeKey : subKey,
uuid: uid,
logVerbosity: true,
ssl: true
});
@digitallysavvy
digitallysavvy / chatUi+snippet.html
Last active October 22, 2020 01:45
a basic chat ui container
<!-- Chat UI -->
<div class="chatContainer">
<div class="chat">
<div class="chat_header"></div>
<div id="chat_fullscreen" class="chat_conversion chat_converse">
<!-- msgs will be dynamically added below -->
</div>
<div class="chatUi_field">
<textarea id="chatTextInput" name="chat_message" placeholder="Send a message" class="chat_field chat_message"></textarea>
<a id="chatUi_send" class="chatUi"><i class="zmdi zmdi-mail-send"></i></a>
@digitallysavvy
digitallysavvy / joinChannel+snippet.js
Created October 8, 2020 19:50
A snippet for extracting the value from modal inputs and passing them to functions to initialize the Agora and PubNub clients.
// init the session when user clicks join
$( "#join-channel" ).click(function( event ) {
var agoraAppId = $('#form-appid').val();
var token = $('#form-token').val();
var channelName = $('#form-channel').val();
var pubKey = $('#form-publishKey').val();
var subKey = $('#form-subscribeKey').val();
var uid = $("#form-uid").val();
$("#modalForm").modal("hide");
initClientAndJoinChannel(agoraAppId, token, channelName, uid);
@digitallysavvy
digitallysavvy / agora-pubnub-login-form.html
Last active October 8, 2020 18:31
A simple Bootstrap modal form that includes inputs for an Agora AppID and token, a PubNub pubkey and subkey, along with channel name, and a user ID.
<!-- Join Form - Modal Overlay -->
<div class="modal fade" id="modalForm">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Join Channel</h4>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>