Git Product home page Git Product logo

webrtmp-sdk's Introduction

webrtmp-sdk npm version

JavaScript SDK for streaming media via RTMP from the Web. Originally designed for Livepeer.com, but can be used for any other service by running your own webrtmp-server.

This SDK works best on Chrome Desktop, as it currently only supports WebSocket on H.264-capable browsers. We are working on WebRTC support to allow the use of non-Chrome and non-Desktop browsers. Check out the Browser Support section for more.

Installation

CDN

Add the following script tag to the header of your HTML file:

<script src="https://unpkg.com/@livepeer/[email protected]/dist/index.js"></script>

The API will be available as a global named webRTMP:

const { Client } = webRTMP

Package Managers

yarn

yarn add @livepeer/webrtmp-sdk

npm

npm install @livepeer/webrtmp-sdk

The API can then be imported as a regular module:

const { Client } = require('webrtmp-sdk')

Usage

In order to stream through Livepeer, you are going to need a secret streamKey, which can be obtained by following these steps:

  1. Create Livepeer Account at livepeer.com;
  2. Go to the Livepeer Streams Dashboard;
  3. Create a stream;
  4. Grab the stream key and replace the {{STREAM_KEY}} in the example below.
const client = new Client()

async function start() {
  const streamKey = '{{STREAM_KEY}}'

  const stream = await navigator.mediaDevices.getUserMedia({
    video: true,
    audio: true
  })

  const session = client.cast(stream, streamKey)

  session.on('open', () => {
    console.log('Stream started.')
  })

  session.on('close', () => {
    console.log('Stream stopped.')
  })

  session.on('error', (err) => {
    console.log('Stream error.', err.message)
  })
}

start()

NOTE: If you have multiple streaming users you will need a separate streamKey for each of them. So you should have a backend service programmatically create a stream through Livepeer API and return the streamKey for your front-end. Check out Livepeer API Documentation on how to get an API key and then how to create a stream.

Browser Support

We provide a utility function to check whether the current browser is supported by the SDK:

const { isSupported } = require('@livepeer/webrtmp-sdk')

if (!isSupported()) {
  alert('webrtmp-sdk is not currently supported on this browser')
}

Examples

The examples folder at the root of this repository contains two projects:

For a full working example, check out justcast.it (source code).

Contributing

Pull Requests are always welcome!

License

MIT

webrtmp-sdk's People

Contributors

samuelmtimbo avatar victorges avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.