Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions src/lib/SoundMeter.js

This file was deleted.

83 changes: 83 additions & 0 deletions src/lib/SoundMeter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*
* This code is modified to be used as a JS module from original source at
* https://github.com/webrtc/samples/blob/gh-pages/src/content/getusermedia/volume/js/soundmeter.js
*
* Typescript migration by @farandal - Francisco Aranda - farandal@gmail.com - http://linkedin.com/in/farandal
*
*/


'use strict';

// Meter class that generates a number correlated to audio volume.
// The meter class itself displays nothing, but it makes the
// instantaneous and time-decaying volumes available for inspection.
// It also reports on the fraction of samples that were at or near
// the top of the measurement range.

class SoundMeter {

greeting: string;
context: AudioContext;
instant: number;
slow: number;
clip: number;
script: ScriptProcessorNode;
mic:MediaStreamAudioSourceNode;

constructor(context: AudioContext) {
this.context = context;
this.instant = 0.0;
this.slow = 0.0;
this.clip = 0.0;
this.script = context.createScriptProcessor(2048, 1, 1);
const that = this;
this.script.onaudioprocess = function(event) {
const input = event.inputBuffer.getChannelData(0);
let i;
let sum = 0.0;
let clipcount = 0;
for (i = 0; i < input.length; ++i) {
sum += input[i] * input[i];
if (Math.abs(input[i]) > 0.99) {
clipcount += 1;
}
}
that.instant = Math.sqrt(sum / input.length);
that.slow = 0.95 * that.slow + 0.05 * that.instant;
that.clip = clipcount / input.length;
};
}

public connectToSource = (stream:MediaStream, callback:Function) => {
try {
this.mic = this.context.createMediaStreamSource(stream);
this.mic.connect(this.script);
// necessary to make sample run, but should not be.
this.script.connect(this.context.destination);
if (typeof callback !== 'undefined') {
callback(null);
}
} catch (e) {
console.error(e);
if (typeof callback !== 'undefined') {
callback(e);
}
}
};

public stop = () => {
this.mic.disconnect();
this.script.disconnect();
};

}


export default SoundMeter;
39 changes: 26 additions & 13 deletions src/lib/WowzaMungeSDP.js → src/lib/WowzaMungeSDP.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/*
* This code and all components (c) Copyright 2019-2020, Wowza Media Systems, LLC. All rights reserved.
* This code is licensed pursuant to the BSD 3-Clause License.
*
* Typescript migration by @farandal - Francisco Aranda - farandal@gmail.com - http://linkedin.com/in/farandal
*
*/

const browserDetails = window.adapter.browserDetails;
// @ts-ignore
import Bowser from "bowser";
//const browserDetails = window.adapter.browserDetails;

let SDPOutput;
let SDPOutput:Object;
let videoChoice;
let audioChoice;
let videoIndex;
let audioIndex;

function addAudio(sdpStr, audioLine) {
const addAudio = (sdpStr:string, audioLine:string) => {
let sdpLines = sdpStr.split(/\r\n/);
let sdpSection = 'header';
let hitMID = false;
Expand All @@ -35,7 +40,7 @@ function addAudio(sdpStr, audioLine) {
return sdpStrRet;
}

function addVideo(sdpStr, videoLine) {
const addVideo = (sdpStr:string, videoLine:string) => {
let sdpLines = sdpStr.split(/\r\n/);
let sdpSection = 'header';
let hitMID = false;
Expand Down Expand Up @@ -86,7 +91,7 @@ function addVideo(sdpStr, videoLine) {
}

// Filter codec offerings
function deliverCheckLine(profile, type) {
const deliverCheckLine = (profile:string, type:string) => {
for (let line in SDPOutput) {
let lineInUse = SDPOutput[line];
if (lineInUse.includes(profile)) {
Expand Down Expand Up @@ -130,12 +135,13 @@ function deliverCheckLine(profile, type) {
return '';
}

function checkLine(line) {
const checkLine = (line:string) => {
if (line.startsWith("a=rtpmap") || line.startsWith("a=rtcp-fb") || line.startsWith("a=fmtp")) {
let res = line.split(":");

if (res.length > 1) {
let number = res[1].split(" ");
let x = res[1].split(" ");
let number:number = parseInt(x[0]); // TODO! Debug this! to check!
if (!isNaN(number[0])) {
if (!number[1].startsWith("http") && !number[1].startsWith("ur")) {
let currentString = SDPOutput[number[0]];
Expand All @@ -153,13 +159,20 @@ function checkLine(line) {
return true;
}

function getrtpMapID(line) {
const getrtpMapID = (line:string) => {
let findid = new RegExp('a=rtpmap:(\\d+) (\\w+)/(\\d+)');
let found = line.match(findid);
return (found && found.length >= 3) ? found : null;
}

export function mungeSDPPublish(sdpStr, mungeData) {


export const mungeSDPPublish = (sdpStr: string, mungeData: { videoCodec: string; audioCodec: string; audioBitrate: string; videoBitrate: string; videoFrameRate: string; }) => {


const browser = Bowser.getParser(window.navigator.userAgent);
console.log("BROWSER",browser.getBrowser());


SDPOutput = new Object();
videoChoice = "42e01f";
Expand Down Expand Up @@ -205,7 +218,7 @@ export function mungeSDPPublish(sdpStr, mungeData) {
if (sdpLine.length <= 0)
continue;

if (browserDetails.browser === 'chrome') {
if (browser.getBrowser().name === 'Chrome') {
let audioMLines;
if (sdpLine.indexOf("m=audio") == 0 && audioIndex !== -1) {
audioMLines = sdpLine.split(" ");
Expand Down Expand Up @@ -235,7 +248,7 @@ export function mungeSDPPublish(sdpStr, mungeData) {
hitMID = false;
}

if (browserDetails.browser === 'chrome') {
if (browser.getBrowser().name === 'Chrome') {
if (sdpLine.indexOf("a=mid:") === 0 || sdpLine.indexOf("a=rtpmap") == 0) {
if (!hitMID) {
if ('audio'.localeCompare(sdpSection) == 0) {
Expand Down Expand Up @@ -279,7 +292,7 @@ export function mungeSDPPublish(sdpStr, mungeData) {
}
}

if (browserDetails.browser === 'firefox' || browserDetails.browser === 'safari') {
if (browser.getBrowser().name === 'firefox' || browser.getBrowser().name === 'safari') {
if ( sdpLine.indexOf("c=IN") ==0 )
{
if ('audio'.localeCompare(sdpSection) == 0)
Expand Down Expand Up @@ -308,7 +321,7 @@ export function mungeSDPPublish(sdpStr, mungeData) {
return sdpStrRet;
}

export function mungeSDPPlay(sdpStr) {
export const mungeSDPPlay = (sdpStr:string) => {

// For greatest playback compatibility,
// force H.264 playback to baseline (42e01f).
Expand Down
Loading