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 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
};
}
tap.test("OutgoingMediaStreamTrack::mute",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("mute",function(test){
try {
test.plan(4);
//Create new local stream
const outgoingStream = transport.createOutgoingStream({
video: true
});
//Should not fire
outgoingStream.on("muted",(muted)=>{
test.fail();
});
//Get video track
const videoTrack = outgoingStream.getVideoTracks()[0];
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()
});
let ssrc = 100;
suite.test("audio+video",async function(test){
//Create stream
const streamInfo = new StreamInfo("stream0");
//Create track
let track = new TrackInfo("video", "track1");
//Get ssrc, rtx and fec
const media = ssrc++;
const rtx = ssrc++;
const fec = ssrc++;
//Add ssrcs to track
track.addSSRC(media);
track.addSSRC(rtx);
suite.test("audio+video duplicated ssrc fail",async function(test){
//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()
});
try {
//Create new local stream
const outgoingStream = transport.createOutgoingStream({
audio: {
id: "testaudio",
ssrcs : { media: 1},
},
video: {
id: "testvideo",
ssrcs : { media: 1, rtx: 3, fec: 4}
}
});
test.noOk(outgoingStream);
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 DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const Setup = SemanticSDP.Setup;
const Direction = SemanticSDP.Direction;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Promise.all([
tap.test("Transport",async function(suite){
suite.test("ice+dtls",async function(test){
test.plan(4);
//create endpoints
const localEndpoint = MediaServer.createEndpoint ("127.0.0.1");
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");
//Add ssrc
track.addSSRC(ssrc++);
//Add it
streamInfo.addTrack(track);
//Create new incoming stream
const incomingStream = transport.createIncomingStream(streamInfo);
//Get audio track
const audioTrack = incomingStream.getAudioTracks()[0];
const Native = require("./Native");
const EventEmitter = require('events').EventEmitter;
const SemanticSDP = require("semantic-sdp");
const IncomingStreamTrack = require("./IncomingStreamTrack");
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;
/**
* The incoming streams represent the recived media stream from a remote peer.
*/
class IncomingStream
{
/**
* @ignore
* @hideconstructor
* private constructor
*/
constructor(transport,receiver,info)
{
//Store stream info
const EventEmitter = require('events').EventEmitter;
const Logger = require("./Logger");
//Get Semantic SDP objects
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
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 Direction = SemanticSDP.Direction;
const CodecInfo = SemanticSDP.CodecInfo;
//Get the Medooze Media Server interface
const MediaServer = require("medooze-media-server");
const Participant = require("./Participant");
class Room
{
constructor(id,ip)
{
//Store id
this.id = id;
const Native = require("./Native");
const EventEmitter = require('events').EventEmitter;
const SemanticSDP = require("semantic-sdp");
const OutgoingStreamTrack = require("./OutgoingStreamTrack");
const uuidV4 = require('uuid/v4');
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;
/**
* The incoming streams represent the media stream sent to a remote peer.
*/
class OutgoingStream
{
/**
* @ignore
* @hideconstructor
* private constructor
*/
constructor(transport,lfsr,info)
{
//Store stream info
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