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

@millicast/sdk-interactivity

v0.2.0

Published

Dolby Millicast Interactivity SDK

Downloads

96

Readme

GitHub Documentation

This project is an SDK built on top of the @millicast/sdk library to provide an easier way to manage bi-directional communications on the Dolby Millicast platform.

Getting Started

To get started, install this SDK into your web application. The @millicast/sdk library will be installed as a dependency.

npm install @millicast/sdk-interactivity

To import this SDK via script, you will need to load the SDK as UMD as well as the Millicast SDK. An example is provided in the example folder of this repository.

<script src="https://cdn.jsdelivr.net/npm/@millicast/sdk/dist/millicast.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@millicast/sdk-interactivity/dist/millicast-sdk-interactivity.min.js"></script>

Then you can use the SDK using the variable MillicastInteractivity.

Events

The SDK can trigger the following events:

  • publisherJoined - Event triggered when a new publisher starts publishing to the stream.
  • publisherLeft - Event triggered when a publisher stops publishing to the stream.
  • sourceAdded - Event triggered when a new source is being published to the stream.
  • sourceRemoved - Event triggered when a source stopped being published.
  • viewercount - Event triggered from time to time to indicate the number of viewers connected to the stream.
import { Publisher, Room, Source } from '@millicast/sdk-interactivity';

const room = new Room({
    streamName,
    streamAccountId,
});

room.on('viewercount', (count: number) => console.log('Viewer count is', count));

room.on('sourceAdded', async (publisher: Publisher, source: Source) => {
    const { sourceId } = source;
    console.log(`New ${sourceId.sourceType} source: ${sourceId.sourceName}`);
    console.log(`is available from ${publisher.name}.`);

    // Request to receive the source
    await source.receive();

    // Display the source on the UI
    const videoElement = document.getElementById('video');
    videoElement.srcObject = new MediaStream([source.videoTrack]);
    videoElement.play();
});

Connect to a stream

To publish your camera into a stream and listen to the available sources, call the connect function. Once connected, the SDK will trigger a series of publisherJoined and sourceAdded events that you must subscribe to in order to get the audio / video streams coming from the platform, and display them on your web page.

import { Publisher, Room, Source } from '@millicast/sdk-interactivity';

const room = new Room({
    streamName,
    streamAccountId,
});

room.on('publisherJoined', (publisher: Publisher) => {
    console.log(`${publisher.name} joined.`);
});
room.on('sourceAdded', (publisher: Publisher, source: Source) => {
    const { sourceId } = source;
    console.log(`New ${sourceId.sourceType} source: ${sourceId.sourceName}`);
    console.log(`is available from ${publisher.name}.`);
});

// Let the SDK handle the getUserMedia
const publishedSource = await room.connect({
    publishToken,
    publisherName,
    constraints: {
        // Set WebRTC Media Stream constraints
        audio: true,
        video: true,
    },
});

// If you want to provide your own media stream, use the following code
const customPublishedSource = await room.connect({
    publishToken,
    publisherName,
    mediaStream,
});

// Stop publishing sources
room.unpublish(publishedSource);
room.unpublish(customPublishedSource);

Watch to a stream

To watch a stream, call the watch function. Once connected, the SDK will trigger a series of publisherJoined and sourceAdded events that you must subscribe to in order to get the audio / video streams coming from the platform, and display them on your web page.

import { Publisher, Room, Source } from '@millicast/sdk-interactivity';

const room = new Room({
    streamName,
    streamAccountId,
});

room.on('publisherJoined', (publisher: Publisher) => {
    console.log(`${publisher.name} joined.`);
});
room.on('sourceAdded', (publisher: Publisher, source: Source) => {
    const { sourceId } = source;
    console.log(`New ${sourceId.sourceType} source: ${sourceId.sourceName}`);
    console.log(`is available from ${publisher.name}.`);
});

await room.watch();

Publish a new source to a stream

To publish another source into a stream, call the publish function.

// Will publish another source
await room.publish({
    publishToken,
    constraints: {
        // Set WebRTC Media Stream constraints
        audio: true,
        video: true,
    },
});

To publish a screenshare into the stream, call the getDisplayMedia function to get the screenshare stream. and the publish function.

import { SourceType } from '@millicast/sdk-interactivity';

// Prompts the user to select and grant permission to capture the contents
// of a display or portion thereof (such as a window).
const mediaStream = await navigator.mediaDevices.getDisplayMedia({});

const source = await room.publish({
    mediaStream,
    releaseOnLeave: true,
    publishToken,
    sourceType: SourceType.Screenshare,
    sourceName: 'My Screenshare',
});

// Display the screenshare on the page
const videoElement = document.getElementById('screenshare');
videoElement.srcObject = new MediaStream([source.videoTrack]);
videoElement.play();

How to

The unit tests are built on Jest, to execute the tests, run the following command.

npm run test

Create distribution package:

npm run build

The documentation is built on TypeDoc, to generate the doc, run the following command. You will find the HTML files in the docs folder.

npm run docs

You can also print the logs in the console and select the log level by using the following code.

import { Logger } from '@millicast/sdk-interactivity';

Logger.useDefaults({
    defaultLevel: Logger.TRACE,
});

Related Projects