Updated Sync library to 0.5, removed endpoint id
This commit is contained in:
6
app.py
6
app.py
@@ -60,16 +60,12 @@ def token():
|
|||||||
# create a randomly generated username for the client
|
# create a randomly generated username for the client
|
||||||
identity = fake.user_name()
|
identity = fake.user_name()
|
||||||
|
|
||||||
# Create a unique endpoint ID for the
|
|
||||||
device_id = request.args.get('device')
|
|
||||||
endpoint = "TwilioAppDemo:{0}:{1}".format(identity, device_id)
|
|
||||||
|
|
||||||
# Create access token with credentials
|
# Create access token with credentials
|
||||||
token = AccessToken(account_sid, api_key, api_secret, identity)
|
token = AccessToken(account_sid, api_key, api_secret, identity)
|
||||||
|
|
||||||
# Create a Sync grant and add to token
|
# Create a Sync grant and add to token
|
||||||
if sync_service_sid:
|
if sync_service_sid:
|
||||||
sync_grant = SyncGrant(endpoint_id=endpoint, service_sid=sync_service_sid)
|
sync_grant = SyncGrant(service_sid=sync_service_sid)
|
||||||
token.add_grant(sync_grant)
|
token.add_grant(sync_grant)
|
||||||
|
|
||||||
# Create a Video grant and add to token
|
# Create a Video grant and add to token
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
<script src="//media.twiliocdn.com/sdk/js/sync/v0.3/twilio-sync.min.js"></script>
|
<script src="//media.twiliocdn.com/sdk/js/sync/v0.5/twilio-sync.min.js"></script>
|
||||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ $(function () {
|
|||||||
//Get handle to the game board buttons
|
//Get handle to the game board buttons
|
||||||
var $buttons = $('#board .board-row button');
|
var $buttons = $('#board .board-row button');
|
||||||
|
|
||||||
//Manages the state of our access token we got from the server
|
|
||||||
var accessManager;
|
|
||||||
|
|
||||||
//Our interface to the Sync service
|
//Our interface to the Sync service
|
||||||
var syncClient;
|
var syncClient;
|
||||||
|
|
||||||
@@ -19,11 +16,9 @@ $(function () {
|
|||||||
//In browser-based apps, every tab is like its own unique device
|
//In browser-based apps, every tab is like its own unique device
|
||||||
//synchronizing state -- so we'll use a random UUID to identify
|
//synchronizing state -- so we'll use a random UUID to identify
|
||||||
//this tab.
|
//this tab.
|
||||||
$.getJSON('/token', {
|
$.getJSON('/token', function (tokenResponse) {
|
||||||
device: getDeviceId()
|
|
||||||
}, function (tokenResponse) {
|
|
||||||
//Initialize the Sync client
|
//Initialize the Sync client
|
||||||
syncClient = new Twilio.Sync.Client(tokenResponse.token);
|
syncClient = new Twilio.Sync.Client(tokenResponse.token, { logLevel: 'info' });
|
||||||
|
|
||||||
//Let's pop a message on the screen to show that Sync is ready
|
//Let's pop a message on the screen to show that Sync is ready
|
||||||
$message.html('Sync initialized!');
|
$message.html('Sync initialized!');
|
||||||
@@ -78,17 +73,6 @@ $(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate random UUID to identify this browser tab
|
|
||||||
//For a more robust solution consider a library like
|
|
||||||
//fingerprintjs2: https://github.com/Valve/fingerprintjs2
|
|
||||||
function getDeviceId() {
|
|
||||||
return 'browser-' +
|
|
||||||
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
||||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//Read the state of the UI and create a new document
|
//Read the state of the UI and create a new document
|
||||||
function readGameBoardFromUserInterface() {
|
function readGameBoardFromUserInterface() {
|
||||||
var board = [
|
var board = [
|
||||||
@@ -120,4 +104,4 @@ $(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user