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

kinesis-webrtc

v1.0.1

Published

Downloads

7

Readme

Kinesis WebRTC

NPM version NPM version

This package is used to interract with Amazon Kinesis Video Streams WebRTC SDK for JavaScript. The package allows you to intergrate Video and Audio capabilities to your application.

Installation

To install this package, simply type add or install kinesis-webrtc using your favorite package manager:

npm i kinesis-webrtc
OR
yarn add kinesis-webrtc

The package is modulized by simple commands. To send a request, you only need to import the KinesisClient and interact with Amazon Kinesis Video Streams WebRTC SDK.

// commonJs
const { KinesisClient } = require("kinesis-webrtc")
// es6+
import { KinesisClient } from "kinesis-webrtc"

We have provided roles for MASTER and VIEWER. These can be accessed by importing the Role from kinesis-webrtc.

// import roles
import { Role } from "kinesis-webrtc"

// usage

Role.MASTER 

OR

Role.VIEWER

Getting started

You can start by trying out the SDK with a webcam on the example Kinesis Video Stream Example.

It is also recommended to develop familiarity with the WebRTC protocols and KVS Signaling Channel APIs. AWS Documentation

Usage

This section demostrates how to use this package to interract with Amazon Kinesis Video Streams WebRTC SDK. Refer to the examples directory for an example of a complete application.

Import and initialize KinesisClient from kinesis-video-webrtc

// import and initialize the KinesisClient

import { KinesisClient } from "kinesis-webrtc"

const kinesisClient = new KinesisClient({
  region: process.env.Region /*requried*/,
  accessKeyId: process.env.AcessKeyId /*requried*/,
  secretAccessKey: process.env.SecretAccessKey /*requried*/,
})

See Managing Credentials for more information about managing credentials in a web environment.

Initialize your WebCam and Audio

We have provided a command that will allow you to prompt users to accept access of camera and audio usage. There are two commands that can be used to during initialization of WebCam and Audio.

The getMedia() function once called you only have to listen to localstream event and you will be able to access your localStream.



const localView = document.getElementById('localView')

// listen to the local stream
kinesisClient.on("localstream", (event) => {
  localView.srcObject = event
})


// listen to the remote stream
const remoteView = document.getElementById('remoteView')


kinesisClient.on("remotestream", (event) => {
  remoteView.srcObject = event.streams[0]
})

await kinesisClient.getMedia({
        audio: {
          sampleSize: 8, // OR 16
          echoCancellation: true,
        },
        video: {
          width: {
            min: 640,
            max: 1024,
          },
          height: {
            min: 480,
            max: 768,
          },
        },
      })

You are not confined in using getMedia() function we have also provided a setMedia() function to allow you to initialize your webcam and audio and only send the stream of each user to KinesisClient. This cammand can be used appropriately if deploying the application in Nodejs backend.

// get your media streams
// local stream
kinesisClient.on("localstream", (event) => {
  ....
})

// remote streams
kinesisClient.on("remotestream", (event) => {
  ....
})


const stream: any = await navigator.mediaDevices
      .getUserMedia(constraints)
      .catch((err) => console.log(error));

// set media streams
await kinesisClient.setMedia(stream)

Once we have initialized the media, in the next steps we will separate the commands for viewer and master user to show how easy it is to interract with kinesis-webrtc.

Master

The master role entails the following actions in a normal Amazon Kinesis Video Streams WebRTC SDK usage:

Create a Signaling Channel Generate Endpoints and IceServers Initialize signalling client Connect to signalling client

To capture the above we have reduced the interraction to few commands. We provide getChannelARN() which will check if a signalling channel being created is available to reduce duplication error on creation attempt and setChannelARN() to create new signlaing channels.

These three commands will complete MASTER connection awaiting viewers to join the channel. Ensure the session name is unique.

/*create a channel incase not available*/
await kinesisClient.setChannelARN(sessionName);

/*provide role*/
await kinesisClient.setKinesisClient({
  role: Role.MASTER,
});

/*connect to channel*/
kinesisClient.masterConnect();

To check if channelARN is available run the following command:

/*get channle arn*/
await kinesisClient.getChannelARN(sessionName);

Viewer

The viewer role entails the following actions in a normal Amazon Kinesis Video Streams WebRTC SDK usage:

Generate Endpoints and IceServers Initialize signalling client Connect to signalling client

/*get channle arn*/
await kinesisClient.getChannelARN(sessionName);

/*provide role and client id*/
await kinesisClient.setKinesisClient({
  role: Role.VIEWER,
  clientId: 12345 /*required*/
});

/*connect to signaling channel*/
kinesisClient.viewerConnect();

That is all you have to do to generate a connection between the Master and Viewers. Use the example provided to guide you through the usage of kinesis-webrtc.

Cleanup

For cleanup after each session we have provided a single command to cleanup your AWS enviroment. This function can be called by either the VIEWER or MASTER. Just call getChannelARN() command and deleteChannel() command.

/*gets the signal channel arn*/
await kinesisClient.getChannelARN(sessionName);

/*deletes the signaling channel*/
await kinesisClient.deleteChannel()

OR

// provide the channel ARN to deleteChannel function
await kinesisClient.deleteChannel('arn:aws:kinesisvideo:us-west-2:123456789012:channel/testChannel/1234567890') 

Other Events

We have provided other events that you can connect to and listen to users connecting and disconnecting in the channel.

// listen to all connection
kinesisClient.on("connected", (event) => {
  ....
})

// listen to all disconnection
kinesisClient.on("disconnected", (event) => {
  ....
})

Development

Running kinesis-video-webrtc example locally The example can be edited and run locally by following these instructions:

NodeJS version 8+ is required.

Run npm install to download dependencies.
Run npm run develop to run the webserver.
Open the WebRTC test page at http://localhost:1234
You will need to provide an AWS region, AWS credentials, and a Channel Name.

The source code for the test page is in the examples directory.

Notice

This project is licensed under the MIT License. see LICENSE for more information.