Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Native = require("./Native");
const EventEmitter = require("events").EventEmitter;
const LayerInfo = require("./LayerInfo");
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const TrackEncodingInfo = SemanticSDP.TrackEncodingInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
function getStatsFromIncomingSource(source)
{
const stats = {
lostPackets : source.lostPackets,
dropPackets : source.dropPackets,
numPackets : source.numPackets,
numRTCPPackets : source.numRTCPPackets,
totalBytes : source.totalBytes,
totalRTCPBytes : source.totalRTCPBytes,
totalPLIs : source.totalPLIs,
totalNACKs : source.totalNACKs,
bitrate : source.bitrate, // Acumulator window is 1000ms so Instant==InstantAvg
layers : [],
};
const Native = require("./Native");
const EventEmitter = require('events').EventEmitter;
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const Transponder = require("./Transponder");
function getStatsFromOutgoingSource(source)
{
return {
numPackets : source.numPackets,
numRTCPPackets : source.numRTCPPackets,
totalBytes : source.totalBytes,
totalRTCPBytes : source.totalRTCPBytes,
bitrate : source.bitrate // Acumulator window is 1000ms so Instant==InstantAvg
};
}
/**
* Audio or Video track of a media stream sent to a remote peer
const tap = require("tap");
const MediaServer = require("../index");
const SemanticSDP = require("semantic-sdp");
MediaServer.enableLog(false);
MediaServer.enableDebug(false);
MediaServer.enableUltraDebug(false);
const endpoint = MediaServer.createEndpoint("127.0.0.1");
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const Setup = SemanticSDP.Setup;
const Direction = SemanticSDP.Direction;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const CodecInfo = SemanticSDP.CodecInfo;
tap.test("IncomingMediaStream::create",async function(suite){
//Init test
const transport = endpoint.createTransport({
dtls : SemanticSDP.DTLSInfo.expand({
"hash" : "sha-256",
"fingerprint" : "F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F"
}),
ice : SemanticSDP.ICEInfo.generate()
});
suite.test("create",async function(test){
let ssrc = 100;
//Create stream
const tap = require("tap");
const MediaServer = require("../index");
const SemanticSDP = require("semantic-sdp");
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const Setup = SemanticSDP.Setup;
const Direction = SemanticSDP.Direction;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const CodecInfo = SemanticSDP.CodecInfo;
const TrackEncodingInfo = SemanticSDP.TrackEncodingInfo;
MediaServer.enableLog(false);
let ssrc = 1;
tap.test("IncomingStream",function(suite){
//Create UDP server endpoints
const endpoint = MediaServer.createEndpoint("127.0.0.1");
const mirror = MediaServer.createEndpoint("127.0.0.1");
//Init test
const transport = endpoint.createTransport({
const tap = require("tap");
const MediaServer = require("../index");
const SemanticSDP = require("semantic-sdp");
MediaServer.enableLog(false);
MediaServer.enableDebug(false);
MediaServer.enableUltraDebug(false);
const endpoint = MediaServer.createEndpoint("127.0.0.1");
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const Setup = SemanticSDP.Setup;
const Direction = SemanticSDP.Direction;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const CodecInfo = SemanticSDP.CodecInfo;
//Init test
const transport = endpoint.createTransport({
dtls : SemanticSDP.DTLSInfo.expand({
"hash" : "sha-256",
"fingerprint" : "F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F"
}),
ice : SemanticSDP.ICEInfo.generate()
});
let ssrc = 110;
//Create stream
const streamInfo = new StreamInfo("sream1");
//Create track
let track = new TrackInfo("audio", "track2");
const tap = require("tap");
const MediaServer = require("../index");
const SemanticSDP = require("semantic-sdp");
MediaServer.enableLog(false);
MediaServer.enableDebug(false);
MediaServer.enableUltraDebug(false);
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const Setup = SemanticSDP.Setup;
const Direction = SemanticSDP.Direction;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const CodecInfo = SemanticSDP.CodecInfo;
const TrackEncodingInfo = SemanticSDP.TrackEncodingInfo;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const Capabilities = {
audio : {
codecs : ["opus"],
},
video : {
codecs : ["vp8","h264"],
rtx : true,
rtcpfbs : [
{ "id": "goog-remb"},
const EventEmitter = require('events').EventEmitter;
const LFSR = require('lfsr');
const uuidV4 = require('uuid/v4');
const SemanticSDP = require("semantic-sdp");
const IncomingStream = require("./IncomingStream");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const Utils = require("./Utils");
/**
* An emulated transport reads data from a unencrypted pcap file (typically from a transport dump), and acts like if it was a live transport from a remote peer.
* You must create the incoming streams as signaled on the remote SDP as any incoming RTP with an unknown ssrc will be ignored. The emulated transport does not allow creating outgoing streams.
*/
class EmulatedTransport
{
/**
* @ignore
* @hideconstructor
* private constructor
*/
constructor(pcap)
{
const Native = require("./Native");
const EventEmitter = require("events").EventEmitter;
const LayerInfo = require("./LayerInfo");
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const TrackEncodingInfo = SemanticSDP.TrackEncodingInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
/**
* Mirror incoming stream from another endpoint. Used to avoid inter-thread synchronization when attaching multiple output streams.
*/
class IncomingStreamTrackMirrored
{
/**
* @ignore
* @hideconstructor
* private constructor
*/
constructor(incomingStreamTrack,timeService)
{
//Store original track and receiver
this.track = incomingStreamTrack;
this.receiver = incomingStreamTrack.receiver;
const SDPManager = require("./SDPManager");
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
class SDPManagerPlanB extends SDPManager
{
constructor(endpoint,capabilities)
{
//Init parent
super();
//Store params
this.endpoint = endpoint;
this.capabilities = capabilities;
//Renegotiation needed flag
this.renegotiationNeeded = false;
}
const SDPManager = require("./SDPManager");
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const Setup = SemanticSDP.Setup;
const MediaInfo = SemanticSDP.MediaInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const SourceGroupInfo = SemanticSDP.SourceGroupInfo;
const Direction = SemanticSDP.Direction;
class SDPManagerUnified extends SDPManager
{
constructor(endpoint,capabilities)
{
//Init parent
super();
//Store params
this.endpoint = endpoint;
this.capabilities = capabilities;
//The list of transceivers
this.transceivers = [];
//The pending list of local tracks not assigned to transceivers
this.pending = new Set();