Skip to content

Instantly share code, notes, and snippets.

@neftaly
Created November 26, 2014 01:21
Show Gist options
  • Save neftaly/a9b2f3c6e4295411b9fe to your computer and use it in GitHub Desktop.
Save neftaly/a9b2f3c6e4295411b9fe to your computer and use it in GitHub Desktop.
bthack client-server promise
var promise = new Promise(function(resolve, reject) {
// Init provider connection
window.location.href = "bthack:" + this.key + "#" + this.appName;
/*
Failsafe: Show a dialog asking the user to install the Provider app.
Make them manually refresh the page when they're done.
*/
$.("#providerAppStoreDialog").show();
//
// Sockets code goes here
//
if (/* sockets successfully connected to provider */) {
$.("#providerAppStoreDialog").hide();
}
// Success: Requester-Provider connection has been approved & established
if (/* success */) {
resolve("Now we can start sending BLE data back and forth!");
}
// Fail: We couldn't generate a secure random key; Provider has given us a seed
else if (/* empty access key */) {
securityKey(seed);
reject(Error("Your key sucks, so provider has graciously generated a new seed"));
// Now we'll need to retry the connection
}
// Provider/User has rejected access
else if (/* connection established but request rejected */) {
reject(Error("Provider says you can bugger off!"));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment