Last active
August 29, 2015 14:17
-
-
Save daviddahl/bd7a5d7d24f6e6f5a3d7 to your computer and use it in GitHub Desktop.
Crypton Items API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We use session.getOrCreateItem in order to create a new item that we can share with others | |
app.session.getOrCreateItem('myReport', function (err, report) { | |
if (err) { | |
callback(err); | |
return console.error(err); | |
} | |
// update the report | |
report.value = { updated: Date.now(), reportContent: app.reportContent }; | |
// share this data: | |
report.share(app.session.peers.alice, function (err) { | |
if (err) { | |
return console.error(err); | |
} | |
console.log('successfully shared report'); | |
// From now on each time this report item object is updated, the peer will be notified that there is new data to fetch | |
}); | |
}); | |
// Peer is notified of new data to fetch: | |
app.session.events.onSharedItemUpdate = function sharedItemUpdate(item) { | |
// The event handler is triggered when a shared item is updated | |
if (item.value.reportContent) { | |
app.readReport(item.value); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment