Skip to content

Commit

Permalink
Change the location of testSoundMeter
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Oct 19, 2024
1 parent 2ea22d1 commit 9c00e56
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/test/js/webrtc_adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,45 @@ describe("WebRTCAdaptor", function() {
sandbox.restore();

});

it("testSoundMeter", function(done) {
this.timeout(15000);
console.log("Starting testSoundMeter");

var adaptor = new WebRTCAdaptor({
websocketURL: "ws://localhost",
mediaConstraints: {
video: true,
audio: true
},
initializeComponents: false,
volumeMeterUrl: '/volume-meter-processor.js',
});

//fake stream in te browser is a period audio and silence, so getting sound level more than 0 requires

adaptor.initialize().then(() => {
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioContext.createOscillator();
oscillator.type = "sine";
oscillator.frequency.value = 800;
var mediaStreamSource = audioContext.createMediaStreamDestination();
oscillator.connect(mediaStreamSource);
var mediaStreamTrack = mediaStreamSource.stream.getAudioTracks()[0];
oscillator.start();

adaptor.mediaManager.localStream = new MediaStream([mediaStreamTrack])
adaptor.mediaManager.audioContext = audioContext;
adaptor.enableAudioLevelForLocalStream((level) => {
console.log("sound level -> " + level);
if (level > 0) {
done();
}
});

expect(adaptor.mediaManager.localStreamSoundMeter).to.not.be.null;
})
})


it("Initialize", async function() {
Expand Down Expand Up @@ -555,45 +594,6 @@ describe("WebRTCAdaptor", function() {
await adaptor.updateAudioTrack(stream, null, null);
});

it("testSoundMeter", function(done) {
this.timeout(15000);
console.log("Starting testSoundMeter");

var adaptor = new WebRTCAdaptor({
websocketURL: "ws://localhost",
mediaConstraints: {
video: true,
audio: true
},
initializeComponents: false,
volumeMeterUrl: '/volume-meter-processor.js',
});

//fake stream in te browser is a period audio and silence, so getting sound level more than 0 requires

adaptor.initialize().then(() => {
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioContext.createOscillator();
oscillator.type = "sine";
oscillator.frequency.value = 800;
var mediaStreamSource = audioContext.createMediaStreamDestination();
oscillator.connect(mediaStreamSource);
var mediaStreamTrack = mediaStreamSource.stream.getAudioTracks()[0];
oscillator.start();

adaptor.mediaManager.localStream = new MediaStream([mediaStreamTrack])
adaptor.mediaManager.audioContext = audioContext;
adaptor.enableAudioLevelForLocalStream((level) => {
console.log("sound level -> " + level);
if (level > 0) {
done();
}
});

expect(adaptor.mediaManager.localStreamSoundMeter).to.not.be.null;
})
})


it("takeConfiguration", async function() {
var adaptor = new WebRTCAdaptor({
Expand Down

0 comments on commit 9c00e56

Please sign in to comment.