I created a soft phone that uses the Twilio Javascript tutorial (quickstart), it works ok...my problem is:
i have a system that will receive the call from twilio (browser notification) and i want that the user, answer that call on a new window (pop up), that will show only a mute and a hangup button.
Thats the problem, the Twilio object were created on the parent window and works ok, but i was unable to "take" the call in the new (child) window, because once a redeclare the twilio object on the new window, i dont have a notification of the call (that are still ringing on the parent window).
Someone know how to tell to the javascript on the child window to answer a specific call id?
My code:
device = new Twilio.Device(tokentwilio, {
// Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
// providing better audio quality in restrained network conditions. Opus will be default in 2.0.
codecPreferences: ['opus', 'pcmu'],
// Use fake DTMF tones client-side. Real tones are still sent to the other end of the call,
// but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone
// a second time and sending the tone twice. This will be default in 2.0.
fakeLocalDTMF: true,
});
device.on('ready',function (device) {
log('Twilio.Device Ready!');
document.getElementById('call-controls').style.display = 'block';
});
device.on('connect', function (conn) {
log('Successfully established call!');
console.log(conn.parameters.CallSid);
document.getElementById('button-call').style.display = 'none';
document.getElementById('button-hangup').style.display = 'inline';
});
device.on('disconnect', function (conn) {
console.log(conn);
document.getElementById('button-call').style.display = 'inline';
document.getElementById('button-hangup').style.display = 'none';
});
device.on('incoming', function (conn) {
connp = conn;
log('Incoming connection from ' + conn.parameters.From);
document.getElementById('btatender').style.display = 'inline';
console.log("NOVA LIGACAO ****");
conn.ignore(); //i ignore the call so i can try to answer on the child window
});