mediasoup-client v3
JavaScript client side library for building mediasoup based applications.
Website and Documentation
Support Forum
Usage Example
import { Device } from 'mediasoup-client';
import mySignaling from './my-signaling';
const device = new Device();
const routerRtpCapabilities = await mySignaling.request('getRouterCapabilities');
await device.load({ routerRtpCapabilities });
if (!device.canProduce('video'))
{
console.warn('cannot produce video');
}
const {
id,
iceParameters,
iceCandidates,
dtlsParameters,
sctpParameters
} = await mySignaling.request(
'createTransport',
{
sctpCapabilities : device.sctpCapabilities
});
const sendTransport = device.createSendTransport(
{
id,
iceParameters,
iceCandidates,
dtlsParameters,
sctpParameters
});
sendTransport.on('connect', async ({ dtlsParameters }, callback, errback) =>
{
try
{
await mySignaling.request(
'transport-connect',
{
transportId: sendTransport.id,
dtlsParameters
});
callback();
}
catch (error)
{
errback(error);
}
});
sendTransport.on(
'produce',
async ({ kind, rtpParameters, appData }, callback, errback) =>
{
try
{
const { id } = await mySignaling.request(
'produce',
{
transportId : sendTransport.id,
kind,
rtpParameters,
appData
});
callback({ id });
}
catch (error)
{
errback(error);
}
});
sendTransport.on(
'producedata',
async ({ sctpStreamParameters, label, protocol, appData }, callback, errback) =>
{
try
{
const { id } = await mySignaling.request(
'produceData',
{
transportId : sendTransport.id,
sctpStreamParameters,
label,
protocol,
appData
});
callback({ id });
}
catch (error)
{
errback(error);
}
});
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const webcamTrack = stream.getVideoTracks()[0];
const webcamProducer = await sendTransport.produce({ track: webcamTrack });
const dataProducer =
await sendTransport.produceData({ ordered: true, label: 'foo' });
Authors
Social
You can support mediasoup by sponsoring it. Thanks!
License
ISC