twilio_client_phonegap
twilio_client_phonegap copied to clipboard
Receive call works only on first run
Hello,
I'm having a strange problem when using the library, everything works correctly the first time you run the application, after that, only back to receive calls if I clear the application data on the settings menu.
On the second run, the app receive the Twilio.ready() but dont receive the incoming, i tested on an Android Phone 5.0 (lollipop) and an Android Tablet 4.2.2 (Jelly Bean)
Someone also had or are having this problem?
Here is a sample code:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>
</head>
<body>
<div id="teste">
<div id="message"></div>
<input type="button" id="btAtender" value="Atender" style="display:none">
<input type="button" id="btDesligar" value="Desligar" style="display:none">
<input type="button" id="btDesconectar" value="Desconectar" style="display: none">
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/tcPlugin.js"></script>
<script type="text/javascript">
var message = $("#message");
$("#btDesligar").click(function () {
Twilio.Device.disconnectAll();
});
$("#btDesconectar").click(function () {
Twilio.Connection.disconnect();
});
function deviceReady() {
window.localStorage.clear();
navigator.app.clearCache();
$.ajax(
{
url: "{URL_TO_GET_TOKEN}",
success: function(token){
console.log(token);
Twilio.Device.setup(token);
Twilio.Connection.setSpeaker("on");
Twilio.Device.ready(function() {
console.log("Twilio ready");
message.html("Twilio ready");
// Could be called multiple times if network drops and comes back.
// When the TOKEN allows incoming connections, this is called when
// the incoming channel is open.
});
Twilio.Device.offline(function() {
console.log("Twilio offline");
message.html("Offline");
// Called on network connection lost.
});
Twilio.Device.incoming(function(conn) {
console.log("Incoming");
message.html("Recebendo ligação");
$("#btAtender").show();
$("#btAtender").click(function () {
conn.accept();
$("#btAtender").hide();
$("#btDesligar").show();
message.html("Em ligação");
});
// conn.status // => "connecting"
});
Twilio.Device.cancel(function(conn) {
console.log("Cancel");
console.log(conn.parameters.From); // who canceled the call
conn.status // => "closed"
});
Twilio.Device.connect(function (conn) {
console.log("Connect");
// Called for all new connections
console.log(conn.status);
});
Twilio.Device.disconnect(function (conn) {
//Twilio.Connection.disconnect();
console.log("Disconnected");
message.html("Desconectado");
$("#btAtender").hide();
$("#btDesligar").hide();
// $("#btReiniciar").show();
});
Twilio.Device.presence(function (presenceEvent) {
console.log("Presence")
// Called for each available client when this device becomes ready
// and every time another client's availability changes.
presenceEvent.from // => name of client whose availability changed
presenceEvent.available // => true or false
});
Twilio.Device.error(function (e) {
console.log(e.message + " for " + e.connection);
});
}
}
);
message.html("Starting twilio setup");
}
</script>
</body>
</html>
I solved this issue by adding this line:
Twilio.shutdown();
In the onDestroy function of the file TCPlugin.java after the super.onDestroy ();
OnDestroy function:
@Override
public void onDestroy() {
super.onDestroy();
Twilio.shutdown();
//lifecycle events
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(cordova
.getActivity());
lbm.unregisterReceiver(mBroadcastReceiver);
}
Maybe publish a fix?
Thanks
Hi,
Thanks! Glad you could find a fix. I'll fix it in the code and update the repo.
This fixes it for Android, but the same problem also exists for iOS.
Thanks! Definitely agree on that. I'll test out the fixes and update the plugin.
on iOS, do you have a fix, @gulfpearl ?
Sorry I don't. I imagine its the same solution, was going to try for a fix tomorrow based on @emersonqueiroz response.
Something I don't understand though, both for Android and iOS, the SDK can keep running in the background and is supposed to call the phonegap app using the callback provided to Twilio.Connection.showNotification.
Right now its not an issue because showNotification doesn't work for me, we are just using a confirm dialog when a call comes in and the phonegap part is running, but if showNotification can be fixed (unless my understanding is wrong and it works as its supposed to) then probably another fix to this problem would be ideal so the SDK can keep running in the background, and accept calls, specially for iOS
Hi everyone,
I have the same issue on Android (tested on Android 4.4.2).
After reopen the app Twilio can't handle the incoming call, but Twilio on device is ready and offline (logs from Twilio.Device.ready
function and Twilio.Device.offline
function, see example in first comment).
I've added the Twilio.shutdown();
to the onDestroy
method in TCPlugin.java - the same issue.
Any ideas?
Thanks, Alexander
Hi,
I solved this issue by adding the line:
Twilio.shutdown();
There is a need to remove and add again the platform for applying this feature.
Thanks, Alexander