I successfully registered on a FreeSwitch instance and I can make calls.
The only problem I have is that I cannot hear call progress tones.
I guessed that the problem was related to the fact that I attached the media stream only on "accepted" event.
(function () {
var config = {
// Replace this IP address with your FreeSWITCH IP address
// Replace this IP address with your FreeSWITCH IP address
// and replace the port with your FreeSWITCH port
// FreeSWITCH Default Username
authorizationUser: '1001',
// FreeSWITCH Default Password
password: '1234'
};
var session;
function onAccepted () {
//gets the video elements
var remoteVideo = document.getElementById('remoteVideo');
var localVideo = document.getElementById('localVideo');
//attached the received video stream to the Video Elements
attachMediaStream(remoteVideo, session.mediaHandler.getRemoteStreams()[0]);
attachMediaStream(localVideo, session.mediaHandler.getLocalStreams()[0]);
//plays the Video Elements
remoteVideo.play();
localVideo.play();
}
//var endButton = document.getElementById('endCall');
//endButton.addEventListener("click", function() {
// session.bye();
// alert("Call Ended");
//}, false);
//here you determine whether the call has video and audio
var options = {
mediaConstraints: {
audio: true,
video: false
}
};
function attachMediaStream(element, stream) {
if (typeof element.srcObject !== 'undefined') {
element.srcObject = stream;
} else if (typeof element.mozSrcObject !== 'undefined') {
element.mozSrcObject = stream;
} else if (typeof element.src !== 'undefined') {
element.src = URL.createObjectURL(stream);
} else {
console.log('Error attaching stream to element.');
}
}
var endButton = document.getElementById('endCall');
endButton.addEventListener("click", function() {
session.bye();
alert("Call Ended");
}, false);
//makes the call
session.on('accepted', onAccepted);
}) ();