Skip to content
Open
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
8 changes: 7 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<body>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script type="application/javascript" src="/out/connect-rtc-debug.js"></script>
<script type="application/javascript" src="/out/connect-rtc-debug.js"></script>
<script type="application/javascript" src="./index.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.7.20.min.js"></script>


<h1>Amazon Connect RTC Demo</h1>
<p>See <a href="https://github.com/aws/amazon-connect-streams/blob/9acf8d23ee836382c29a21d691943e5001b1c907/src/softphone.js#L77">amazon-connect-streams</a> for how to get the softphone media info</p>
Expand All @@ -32,6 +34,10 @@ <h1>Amazon Connect RTC Demo</h1>
<p> Video Stream connected with the other side</p>
<video id="remoteVideo" autoplay="" style="display: inline"></video>
</div>

<br>
<input type='file' id='fileInput' style="width:15em">
<button id='playFile'>Play file over telephone</button>
</body>

</html>
22 changes: 20 additions & 2 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -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)));
Expand All @@ -13,7 +14,6 @@ $(document).ready(function () {
rtcConfig.iceServers,
mediaInfo.callContextToken,
console);

session.echoCancellation = $('#echoCancellationOption').is(':checked');

session.remoteAudioElement = audioElement;
Expand All @@ -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(() => {
Expand All @@ -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) {
Expand Down Expand Up @@ -67,7 +83,9 @@ $(document).ready(function () {
}
}
});

session.connect();
});
$('#playFile').click(function(){
playFromFile = true;
});
});