Skip to content

Instantly share code, notes, and snippets.

@robertour
Created August 28, 2019 07:19
Show Gist options
  • Save robertour/43364940c2a3b9f528ec6c987a19fa21 to your computer and use it in GitHub Desktop.
Save robertour/43364940c2a3b9f528ec6c987a19fa21 to your computer and use it in GitHub Desktop.
creates a binder session on the background
fetch = function() {
// URL of the repository
var apiUrl = 'https://notebooks.gesis.org/binder/build/gh/gesiscss/smm_demo/master';
eventSource = new EventSource(apiUrl);
eventSource.onerror = function(err) {
console.error("Failed to construct event stream", err);
};
eventSource.addEventListener("message", function(event) {
var data = JSON.parse(event.data);
if (data.phase == 'ready') {
// data['url'] and data['token'] are both required to assemble the URL
console.log(data['url'] + '?token=' + data['token']);
eventSource.close();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment