@100mslive/hmsvideo-web
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

hmsvideo-sdk

Endpoint Healthcheck

Web SDK for the 100mslive backend.

Installation

npm install @100mslive/hmsvideo-web

Usage

import { HMSPeer, HMSClientConfig, HMSClient, HMSMediaStreamConstraints } from "@100mslive/hmsvideo-web';

const peer = new HMSPeer(userName:"<userName here>",authToken:"<authToken here>")
const config = new HMSClientConfig({
    endpoint: "<endpoint URL here>"
})
const client = new HMSClient(peer, config)

// Setup handlers
client.on('connect',() => {
    // This is where we can call `join(room)`
});
client.on('disconnect', () => {});
client.on('peer-join', (room, peer) => {
    // Show a notification or toast message in the UI
});
client.on('peer-leave', (room, peer) => {
    // Show a notification or toast message in the UI
});
client.on('stream-add', (room, peer,  streamInfo) => {
    // subscribe to the stream if needed
});
client.on('stream-remove', (room, peer, streamInfo) => {
    // Remove remote stream if needed
});
client.on('broadcast', (room, peer ,message) => {
    // Show a notification or update chat UI
});

// Connect
try {
    await client.connect()
} catch(err) {
    // Handle error
}


// Join a room using a unique room id
const room = <some unique room id>
try {
    await client.join(room);
} catch(err) {
    // Handle error
}


// Get a local stream
const constraints = new HMSMediaStreamConstraints()
try {
    const localStream = await client.getLocalStream(constraints: HMSMediaStreamConstraints);
} catch(err) {
    // Handle error
}


// Publish local stream
try {
    await client.publish(localStream, room);
} catch(err) {
    // handle the error
}


// Unpublish local stream
try {
    await client.unpublish(localStream, room);
} catch(err) {
    // handle error
}


// Subscribe to a remote stream
try {
    const remoteStream = await client.subscribe(mid, roomId);
    // Do something with remoteStream
} catch(err) {
    // Handle error
}


// Unsubscribe from a stream
try {
    await client.unsubscribe(remoteStream, roomId);
} catch(err) {
    // Handle error
}


// Broadcast a payload to the room
try {
    await client.broadcast(payload, roomId);
} catch(err) {
    // Handle error
}


// Close client connection
client.disconnect();

Package Sidebar

Install

npm i @100mslive/hmsvideo-web

Weekly Downloads

5

Version

1.0.9

License

MIT

Unpacked Size

84.4 kB

Total Files

24

Last publish

Collaborators

  • stanwolverine
  • saikatmitra-100ms
  • yogeshfromhms
  • aniketb
  • aniket100ms
  • amit-100ms
  • eswar-clynn
  • aditya3356
  • ashish17
  • nikhilghodke
  • nikhil-sachdeva
  • deepcodes
  • triptu
  • vishal09
  • vivek9patel
  • ashwins93
  • ravitheja83