Skip to content

Instantly share code, notes, and snippets.

@smschauhan
Created February 23, 2014 04:50
Show Gist options
  • Save smschauhan/9167000 to your computer and use it in GitHub Desktop.
Save smschauhan/9167000 to your computer and use it in GitHub Desktop.
window.onload = function () {
rclient = RClient.create({
debug: false,
host: (location.protocol == "https:") ? ("wss://"+location.hostname+":8083/") : ("ws://"+location.hostname+":8081/"),
on_connect: function(ocaps) {
rcloud = RCloud.create(ocaps.rcloud);
if (rcloud.authenticated) {
rcloud.session_init(rcloud.username(), rcloud.github_token(), function(hello) {
rclient.post_response(hello);
});
} else {
rcloud.anonymous_session_init(function(hello) {
rclient.post_response(hello);
});
}
rcloud.init_client_side_data();
var extern=undefined;
rcloud.get_ocaps('foo','ocaps', function(ocaps){
if(ocaps.ok)
extern=ocaps.extern;
});
if(extern)
extern.my_ocap(function(v) {console.log("hello"+v)});
return true;
}, on_error: function(msg, status_code) {
// debugger;
if (msg == 'Login failed. Shutting down!') {
window.location =
(window.location.protocol +
'//' + window.location.host +
'/login.R?redirect=' +
encodeURIComponent(window.location.pathname + window.location.search));
return true;
} else
return false;
}
});
}
my.ocap <- function() {
v <- "dolly"
}
ocaps <- function() {
make.oc<-rcloud.support:::make.oc
list(
ok=TRUE,
extern=list(
my_ocap=make.oc(my_ocap)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment