npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@banuba/agora-extension

v2.0.0

Published

Banuba WebAR Agora extension

Downloads

17

Readme

Banuba WebAR Agora extension

@banuba/agora-extension - Agora extension and video processor based on @banuba/webar.

Take a look at the @banuba/webar npm package and Banuba WebAR docs for a deep dive.

Quickstart

CDN

Via <script> tag:

<div id="video-container" style="width: 640px; height: 640px"></div>

<!-- Exposes AgoraRTC variable on window -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/AgoraRTC_N-production.min.js"></script>
<!-- Exposes BanubaSDK variable on window -->
<script src="https://cdn.jsdelivr.net/npm/@banuba/webar/dist/BanubaSDK.browser.js"></script>
<!-- Exposes BanubaAgoraExtension variable on window -->
<script src="https://cdn.jsdelivr.net/npm/@banuba/agora-extension/dist/index.browser.js"></script>

<script>
  const banuba = new BanubaAgoraExtension.Extension({
    clientToken: "xxx-xxx-xxx",
    locateFile: BanubaSDK.locateFile
  })
  AgoraRTC.registerExtensions([banuba])

  const processor = banuba.createProcessor()
  await processor.addModule(
    ...["face_tracker", "background"].map((m) => "https://cdn.jsdelivr.net/npm/@banuba/webar/dist/modules/" + m + ".zip"),
  )
  const video = await AgoraRTC.createCameraVideoTrack()

  video.pipe(processor).pipe(video.processorDestination)
  video.play(document.querySelector("#video-container"))
</script>

Via <script type="module"> tag:

<div id="video-container" style="width: 640px; height: 640px"></div>

<!-- Exposes AgoraRTC variable on window -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/AgoraRTC_N-production.min.js"></script>
<!-- Exposes BanubaSDK variable on window -->
<script src="https://cdn.jsdelivr.net/npm/@banuba/webar/dist/BanubaSDK.browser.js"></script>

<script type="module">
  import * as BanubaAgoraExtension from "https://cdn.jsdelivr.net/npm/@banuba/agora-extension/dist/index.js"

  const banuba = new BanubaAgoraExtension.Extension({
    clientToken: "xxx-xxx-xxx",
    locateFile: BanubaSDK.locateFile
  })
  AgoraRTC.registerExtensions([banuba])

  const processor = banuba.createProcessor()
  await processor.addModule(
    ...["face_tracker", "background"].map(
      (m) => "https://cdn.jsdelivr.net/npm/@banuba/agora-extension/dist/modules/" + m + ".zip",
    ),
  )
  const video = await AgoraRTC.createCameraVideoTrack()

  video.pipe(processor).pipe(video.processorDestination)
  video.play(document.querySelector("#video-container"))
</script>

NPM

npm i --save agora-rtc-sdk-ng @banuba/agora-extension
import AgoraRTC from "agora-rtc-sdk-ng"
import { Extension } from "@banuba/agora-extension"
import data from "@banuba/webar/dist/BanubaSDK.data"
import wasm from "@banuba/webar/dist/BanubaSDK.wasm"
import simd from "@banuba/webar/dist/BanubaSDK.simd.wasm"
import FaceTracker from "@banuba/webar/dist/modules/face_tracker.zip"
import Background from "@banuba/webar/dist/modules/background.zip"

const banuba = new Extension({
  clientToken: "xxx-xxx-xxx",
  locateFile: {
    "BanubaSDK.data": data,
    "BanubaSDK.wasm": wasm,
    "BanubaSDK.simd.wasm": simd,
  },
})
AgoraRTC.registerExtensions([banuba])

const processor = banuba.createProcessor()
await processor.addModule(FaceTracker, Background)
const video = await AgoraRTC.createCameraVideoTrack()

video.pipe(processor).pipe(video.processorDestination)
// assume the page has a div element with id="video-container" and `width` and `height` set
video.play(document.querySelector("#video-container"))

Read the Integration tutorials intro for the explanation of the locateFile option.

Read the Bundlers section of the Integrations guides for more receipts for different bundlers.

API Reference

Extension

The Extension constructor accepts all the same options as the Player.create() method from Banuba WebAR SDK, most noticeable options are:

  • clientToken - Banuba Client Token, required. See Obtaining Banuba Client token for details
  • locateFile - specifies where to look for the Banuba WebAR’s .wasm and .data files, optional. Check the Integration tutorials intro for explanation.
  • devicePixelRatio - image scaling factor for HiDPI devices, optional. If not specified it has a value of 1 as a reasonable default for WebRTC AR.

Extension.checkCompatibility()

Checks if the browser is capable to run the Extension and Processor:

const banuba = new Extension({
  clientToken: "xxx-xxx-xxx",
  locateFile: BanubaSDK.locateFile
})

if (!banuba.checkCompatibility()) alert("The browser does not support the extension :(")

Processor

The Processor instance created by the Extension.createProcessor() method has the following methods:

Processor.addModule(url | WebArModule)

Adds AR modules (neural networks) to the processor, so effects can consume them:

// This is a syntax sugar over
// import { Module } from "@banuba/agora-extension"
// const face_tracker = new Module("/path/to/face_tracker.zip")
// await processor.addModule(face_tracker)

await processor.addModule("/path/to/face_tracker.zip")

See the WebAR API Reference for the list of available AR modules and usage code examples.

Also you may want to check the docs of the Player.addModule()from Banuba WebAR SDK as the processor’s method is a simple wrapper around the Player.addModule().

Processor.applyEffect(url | WebArEffect)

Applies an AR effect to the processor:

// This is a syntax sugar over
// import { Effect } from "@banuba/agora-extension"
// const octopus = new Effect("/path/to/Octopus.zip")
// await processor.applyEffect(octopus)

await processor.applyEffect("/path/to/Octopus.zip")

You can download and use test effect from the Demo face filters page.

Also you may want to check the docs of the Player.applyEffect() from Banuba WebAR SDK as the processor’s method is a simple wrapper around the Player.applyEffect().

Processor.clearEffect()

Clears the applied effect if any:

await processor.applyEffect("/path/to/Octopus.zip")

// ... a few moments later ...

processor.clearEffect()

Processor.destroy()

Destroys the processor instance, frees up resources and allocated memory:

processor.destroy()

Try to not to forget to destroy the processor instance once it’s not needed to avoid accidental memory leaks.

The processor instance con not be re-used once it’s destroyed.

Obtaining Banuba Client token

Banuba Client token is required to get Banuba SDK Web AR working.

To receive a new trial client token please fill in the form on banuba.com website, or contact us via [email protected].

Resources and links