Original Question: This doesn't answer the original question of what's the latest version of CometD that can be used with Streaming API (@crmprogdev answer of CometD version 2.2.0 is by all accounts correct).
Edited Question: But the following is a work-around to use any version of jQuery while still using jQuery 1.5.1 for Streaming API:
Instead of using Streaming API on the Visualforce Page in question, use it on another Page which is then embedded in an iframe
on the Page in question.
On the Parent Page
, use any version of jQuery, and create a JS function to handle the Streaming API response. For example, call the function handleStreamingApiResponse(meassage)
.
Then on the Iframed Page
, use the version of jQuery required for Streaming API and do all of the Streaming API JavaScript here. To handle the Streaming API response call the Parent's Streaming API Handler. In the example, this would be window.parent.handleStreamingApiResponse(message)
.
Note: The Example below follows the Streaming API Visualforce Code Example.
Parent Page
<apex:page ... >
<apex:includeScript value="{!URLFOR($Resource.jQuery_1_11_1}"/>
<script>
var $ = jQuery.noConflict();
function handleStreamingApiResponse(message){
...
}
</script>
<apex:iframe src="/apex/iframedPage" height="0"/>
...
</apex>
Iframed Page
<apex:page ...>
<apex:includeScript value="{!$Resource.cometd}"/>
<apex:includeScript value="{!$Resource.jquery_1_5_1}"/>
<apex:includeScript value="{!$Resource.json2}"/>
<apex:includeScript value="{!$Resource.jquery_cometd}"/>
<script>
var $ = jQuery.noConflict();
(function($){
$(document).ready(function() {
// Connect to the CometD endpoint
$.cometd.init({
url: window.location.protocol + '//' + window.location.hostname + '/cometd/24.0/',
requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
});
// Subscribe to a topic. JSON-encoded update will be returned in the callback
$.cometd.subscribe('/topic/MyTopic', function(message) {
window.parent.handleStreamingApiResponse(message);
});
});
})(jQuery)
function disconnect() {
$.cometd.disconnect();
}
window.onbeforeunload = disconnect;
</script>
</apex:page>
Note: When viewing the Parent Page
with Development Mode
turned on, the function window.parent.handleStreamingApiResponse(message)
won't work because the Development Mode Panel changes the order of iframes. It turns out that with Development Mode on, Parent Page
isn't the direct parent of Iframed Page
nor is Parent Page
the top-most window
(in case you wanted to try window.top.handleStreamingApiResponse(message)
).
If you turn off Development Mode, you will see handleStreamingApiResponse()
work.