diff --git a/demo/index.html b/demo/index.html index 6275484..01fa8c2 100644 --- a/demo/index.html +++ b/demo/index.html @@ -7,8 +7,10 @@ - + + +

Amazon Connect RTC Demo

See amazon-connect-streams for how to get the softphone media info

@@ -32,6 +34,10 @@

Amazon Connect RTC Demo

Video Stream connected with the other side

+ +
+ + diff --git a/demo/index.js b/demo/index.js index c6e95bc..8675105 100644 --- a/demo/index.js +++ b/demo/index.js @@ -1,6 +1,7 @@ $(document).ready(function () { var audioElement = $('#remoteAudio')[0]; var videoElement = $('#remoteVideo')[0]; + var playFromFile = false; if (window.location.hash) { $('#softphoneMediaInfo').val(decodeURIComponent(window.location.hash.substr(1))); @@ -13,7 +14,6 @@ $(document).ready(function () { rtcConfig.iceServers, mediaInfo.callContextToken, console); - session.echoCancellation = $('#echoCancellationOption').is(':checked'); session.remoteAudioElement = audioElement; @@ -32,6 +32,17 @@ $(document).ready(function () { session.remoteVideoElement = null; } + if (playFromFile){ + var fileToPlay = $('#fileInput')[0].files[0]; + var audioToPlay = new Audio(URL.createObjectURL(fileToPlay)); + var fileStream = audioToPlay.captureStream(); + var context = new AudioContext(); + var source = context.createMediaElementSource(audioToPlay); + var remote = context.createMediaStreamDestination(); + source.connect(remote); + session.mediaStream = remote.stream; + } + var statsCollector; session.onSessionConnected = () => { statsCollector = setInterval(() => { @@ -40,6 +51,11 @@ $(document).ready(function () { console.log(collectTime, JSON.stringify(streamStats)); }); }, 2000); + + if (playFromFile){ + console.log("Playing file"); + audioToPlay.play(); + } }; session.onSessionCompleted = () => { if (statsCollector) { @@ -67,7 +83,9 @@ $(document).ready(function () { } } }); - session.connect(); }); + $('#playFile').click(function(){ + playFromFile = true; + }); });