Update to Sync SDK v0.7.

This commit is contained in:
Andres Jaan Tack
2017-11-30 15:48:52 +02:00
parent fe3016a362
commit 65c4710f02
2 changed files with 6 additions and 3 deletions

View File

@@ -44,7 +44,7 @@
</section>
<script src="//media.twiliocdn.com/sdk/js/sync/v0.5/twilio-sync.min.js"></script>
<script src="//media.twiliocdn.com/sdk/js/sync/v0.7/twilio-sync.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="index.js"></script>
</body>

View File

@@ -26,14 +26,17 @@ $(function () {
//Note the use of promises
syncClient.document('SyncGame').then(function(syncDoc) {
//Initialize game board UI to current state (if it exists)
var data = syncDoc.get();
var data = syncDoc.value;
if (data.board) {
updateUserInterface(data);
}
//Let's subscribe to changes on this document, so when something
//changes on this document, we can trigger our UI to update
syncDoc.on('updated', updateUserInterface);
syncDoc.on('updated', function(event) {
console.debug("Board was updated", event.isLocal? "locally." : "by the other guy.");
updateUserInterface(event.value);
});
//Whenever a board button is clicked, update that document.
$buttons.on('click', function (e) {