We haven't figure out how to get the signed request (sr) in the visualforce page where we have a canvas app.
We are publishing a canvas event in our external app like:
Sfdc.canvas.client.publish(sr.client,
{
name : "namespace.eventName",
payload : {status : 'Completed'}
}
);
And first we try to subscribe to the event in the VF page like:
<script type="text/javascript" src="/canvas/sdk/js/33.0/controller.js"></script>
<apex:canvasApp developerName="ourApp"/>
Sfdc.canvas(function() {
Sfdc.canvas.controller.subscribe(
{
name : ‘namespace.eventName’,
onData : function(e) {
console.log("Subscribed to custom event ", e);
}
});
});
but we are getting the error Uncaught TypeError: Cannot read property 'publish' of undefined
meaning that controller is undefined
So, we want to subscribe using the Sfdc.canvas.client.subscribe
but that method takes two parameters, one of them is the signed request which we don't know how to get in the VF page
Eg:
Sfdc.canvas(function() {
sr = JSON.parse('<%=signedRequestJson%>');
Sfdc.canvas.client.subscribe(sr.client,
{name : 'mynamespace.statusChanged', onData : function (event) {
console.log("Subscribed to custom event ", event);
}}
);
});
So, the question is, how can we populate the variable sr in the line sr = JSON.parse('<%=signedRequestJson%>');
?
Note: We have read this, this and been following the canvas developer guide