@100mslive/hmsvideo-web
v1.0.9
Published
A web SDK for 100mslive sfu
Downloads
341
Readme
hmsvideo-sdk
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();