Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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({
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("empty mirror",function(test){
//Create stream
const streamInfo = new StreamInfo("stream0");
//Create new incoming stream
const incomingStream = transport.createIncomingStream(streamInfo);
test.ok(incomingStream);
//Mirror it
const mirrored = mirror.mirrorIncomingStream(incomingStream);
test.ok(mirrored)
//Mirror it again
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
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");
//Add ssrc
track.addSSRC(ssrc++);
//Add it
streamInfo.addTrack(track);
//Create new incoming stream
//Server IP address
const ip = "127.0.0.1";
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 sdp = "v=0\r\n" +
"o=- 4327261771880257373 2 IN IP4 127.0.0.1\r\n" +
"s=-\r\n" +
"t=0 0\r\n" +
"a=group:BUNDLE audio video\r\n" +
"a=msid-semantic: WMS xIKmAwWv4ft4ULxNJGhkHzvPaCkc8EKo4SGj\r\n" +
"m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"a=rtcp:9 IN IP4 0.0.0.0\r\n" +
"a=ice-ufrag:ez5G\r\n" +
"a=ice-pwd:1F1qS++jzWLSQi0qQDZkX/QV\r\n" +
//Get the Medooze Media Server interface
const MediaServer = require("medooze-media-server");
//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;
const Capabilities = {
video : {
codecs : ["vp9"],
rtx : true,
rtcpfbs : [
{ "id": "transport-cc"},
{ "id": "ccm", "params": ["fir"]},
{ "id": "nack"},
{ "id": "nack", "params": ["pli"]}
],
const getPort = require('get-port');
const medoozeMediaServer = require('medooze-media-server');
const format = require('string-format');
const execa = require('execa');
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;
const videoPt = 96;
const audioPt = 100;
const videoCodec = 'h264';
const audioCodec = 'opus';
let videoPort = null;
let audioPort = null;
//const RTMP_TO_RTP = 'ffmpeg -fflags nobuffer -i rtmp://ali.wangxiao.eaydu.com/live_bak/x_100_rtc_test -vcodec copy -an -bsf:v h264_mp4toannexb -f rtp -payload_type {pt} rtp://127.0.0.1:{port}'
const EventEmitter = require('events').EventEmitter;
const LFSR = require('lfsr');
const uuidV4 = require('uuid/v4');
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;
/**
* Manager of remoe peer connecion clients
*/
class PeerConnectionServer
{
/**
* @ignore
* @hideconstructor
* private constructor
*/
import { EventEmitter } from 'events'
import Room from './room'
import Server from './server'
import config from './config'
import Logger from './logger'
import * as request from './request'
const MediaServer = require('medooze-media-server')
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
const log = new Logger('peer')
/**
*
*
* @class Peer
* @extends {EventEmitter}
*/
class Peer extends EventEmitter {
const Native = require("./Native");
const EventEmitter = require('events').EventEmitter;
const Transport = require("./Transport");
const PeerConnectionServer = require("./PeerConnectionServer");
const SDPManagerUnified = require("./SDPManagerUnified");
const SDPManagerPlanB = require("./SDPManagerPlanB");
const IncomingStream = require("./IncomingStream");
const IncomingStreamTrackMirrored = require("./IncomingStreamTrackMirrored");
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 Setup = SemanticSDP.Setup;
/**
* An endpoint represent an UDP server socket.
* The endpoint will process STUN requests in order to be able to associate the remote ip:port with the registered transport and forward any further data comming from that transport.
* Being a server it is ICE-lite.
*/
class Endpoint
{
/**
* @ignore
* @hideconstructor
* private constructor
//Server IP address
const ip = "127.0.0.1";
const SemanticSDP = require("semantic-sdp");
const SDPInfo = SemanticSDP.SDPInfo;
const MediaInfo = SemanticSDP.MediaInfo;
const CodecInfo = SemanticSDP.CodecInfo;
const CandidateInfo = SemanticSDP.CandidateInfo;
const DTLSInfo = SemanticSDP.DTLSInfo;
const ICEInfo = SemanticSDP.ICEInfo;
const StreamInfo = SemanticSDP.StreamInfo;
const TrackInfo = SemanticSDP.TrackInfo;
const Setup = SemanticSDP.Setup;
//Get the Medooze Media Server interface
const MediaServer = require("../index");
//Enable debug
//MediaServer.enableDebug(true);
//MediaServer.enableUltraDebug(true);
const player = MediaServer.createPlayer("/tmp/recording.mp4");
//Create RTP properties
const rtp = {