From f785244e45d6a6476ad5397b8ce9f6c8fcd3b843 Mon Sep 17 00:00:00 2001 From: Andres Jaan Tack Date: Thu, 30 Nov 2017 15:35:59 +0200 Subject: [PATCH 1/2] Comment out configurations that cause token failure. --- .env.example | 6 +++--- app.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index da90356..4cc1e54 100644 --- a/.env.example +++ b/.env.example @@ -3,13 +3,13 @@ TWILIO_ACCOUNT_SID= TWILIO_API_KEY= TWILIO_API_SECRET= - # Required for Chat -TWILIO_CHAT_SERVICE_SID= +# TWILIO_CHAT_SERVICE_SID= # Required for Notify -TWILIO_NOTIFICATION_SERVICE_SID= +# TWILIO_NOTIFICATION_SERVICE_SID= # Optional for Sync # By default, this app will use the default instance for your account (named "default"). # TWILIO_SYNC_SERVICE_SID= + diff --git a/app.py b/app.py index 237565d..468fecb 100644 --- a/app.py +++ b/app.py @@ -50,11 +50,11 @@ def chat(): def config(): return jsonify( TWILIO_ACCOUNT_SID=os.environ['TWILIO_ACCOUNT_SID'], - TWILIO_NOTIFICATION_SERVICE_SID=os.environ['TWILIO_NOTIFICATION_SERVICE_SID'], + TWILIO_NOTIFICATION_SERVICE_SID=os.environ.get('TWILIO_NOTIFICATION_SERVICE_SID', None), TWILIO_API_KEY=os.environ['TWILIO_API_KEY'], TWILIO_API_SECRET=bool(os.environ['TWILIO_API_SECRET']), - TWILIO_CHAT_SERVICE_SID=os.environ['TWILIO_CHAT_SERVICE_SID'], - TWILIO_SYNC_SERVICE_SID=os.environ['TWILIO_SYNC_SERVICE_SID'], + TWILIO_CHAT_SERVICE_SID=os.environ.get('TWILIO_CHAT_SERVICE_SID', None), + TWILIO_SYNC_SERVICE_SID=os.environ.get('TWILIO_SYNC_SERVICE_SID', None), ) @app.route('/token', methods=['GET']) @@ -80,7 +80,7 @@ def generateToken(identity): api_key = os.environ['TWILIO_API_KEY'] api_secret = os.environ['TWILIO_API_SECRET'] sync_service_sid = os.environ.get('TWILIO_SYNC_SERVICE_SID', 'default') - chat_service_sid = os.environ['TWILIO_CHAT_SERVICE_SID'] + chat_service_sid = os.environ.get('TWILIO_CHAT_SERVICE_SID', None) # Create access token with credentials token = AccessToken(account_sid, api_key, api_secret, identity=identity) From 80e47447871529e49d8537f1b347493bfa27d00a Mon Sep 17 00:00:00 2001 From: Andres Jaan Tack Date: Thu, 30 Nov 2017 15:37:17 +0200 Subject: [PATCH 2/2] Make connection problems visible in the UI. --- static/sync/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/static/sync/index.js b/static/sync/index.js index d585191..45f28cd 100755 --- a/static/sync/index.js +++ b/static/sync/index.js @@ -19,6 +19,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 ' + state + ')…'); + } else { + $message.html('Sync is live!'); + } + }); //Let's pop a message on the screen to show that Sync is ready $message.html('Sync initialized!');