Skip to content

SDK for building a realtime broadcaster using the Millicast platform.

License

Notifications You must be signed in to change notification settings

brianathere/millicast-sdk

 
 

Repository files navigation

Millicast SDK for JavaScript

npm (scoped) GitHub release (latest by date) Check tests

This Software Development Kit (SDK) for JavaScript allows developers to simplify Millicast services integration into their own web apps.

Table of Contents

Installation

You can use the CDN version of the SDK adding this tag to your document's <head>. Then millicast global variable will be available to use it.

<script src='https://cdn.jsdelivr.net/npm/@millicast/sdk@latest/dist/millicast.umd.js'></script>

Or if you are building an application with Node.js, you can install the SDK package to your dependencies.

npm i --save @millicast/sdk

Basic Usage

This simple example will show how to broadcast the user camera and microphone to Millicast Media Servers and viewing it.

You will need a Millicast account and a valid publishing token that you can find it in your dashboard (link here).

Publisher app

import { Director, Publish } from '@millicast/sdk'
//Define callback for generate new tokens
const tokenGenerator = () => Director.getPublisher({
    token: 'my-publishing-token', 
    streamName: 'my-stream-name'
  })

//Create a new instance
const millicastPublish = new Publish(streamName, tokenGenerator)

//Get User camera and microphone
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })

//Publishing Options
const broadcastOptions = {
  mediaStream
}

//Start broadcast
try {
  await millicastPublish.connect(broadcastOptions)
} catch (e) {
  console.log('Connection failed, handle error', e)
}

Viewer app

index.html

<html>
  <head>
    ...
  </head>
  <body>
    <video id="my-video"></video>
    
    <script src='viewer.js'></script>
  </body>
</html>

viewer.js

import { Director, View } from '@millicast/sdk'

// Get Media Element
const video = document.getElementById('my-video')

//Define callback for generate new token
const tokenGenerator = () => Director.getSubscriber({
    streamName: 'my-stream-name', 
    streamAccountId: 'my-account-id'
  })

//Create a new instance
const millicastView = new View(streamName, tokenGenerator, video)

//Start connection to publisher
try {
  await millicastView.connect()
} catch (e) {
  console.log('Connection failed, handle error', e)
}

API Reference

You can find the latest, most up to date, SDK documentation at our API Reference page. There are more examples with every module available.

Samples

In this repo there are two packages that implement a broadcaster and viewer application using the SDK. You can clone this repo and following the steps indicated in each example:

SDK developer information

To develop and contribute to this project, there are some instructions of how to set up your environment to start contributing. Follow this link.

License

Please refer to LICENSE file.

About

SDK for building a realtime broadcaster using the Millicast platform.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 74.4%
  • HTML 13.6%
  • Gherkin 8.3%
  • CSS 3.7%