Merge pull request #31 from ajtack/connection-failure-visibility

Avoid a token error, make the problem visible in the UI
This commit is contained in:
Wellington Mendoza
2017-11-30 09:50:33 -05:00
committed by GitHub
3 changed files with 14 additions and 7 deletions

View File

@@ -15,6 +15,13 @@ $(function () {
$.getJSON('/token', function (tokenResponse) {
//Initialize the Sync client
syncClient = new Twilio.Sync.Client(tokenResponse.token, { logLevel: 'info' });
syncClient.on('connectionStateChanged', function(state) {
if (state != 'connected') {
$message.html('Sync is not live (websocket connection <span style="color: red">' + state + '</span>)…');
} else {
$message.html('Sync is live!');
}
});
//Let's pop a message on the screen to show that Sync is ready
$message.html('Sync initialized!');