We have been using cometd with pushTopic. But we facing an issue an issue in summer 18 org that handshake with cometd is failing in lightning component. if we use lightning component directly in lightning page cometd is working. But if we use a visual force(ltng:outApp) page to display component cometd is not working. In spring 18 it used to work in both classic and lightning.
Here is sample code for that is working in spring 18 but not in summer 18.
TestPage.vf
<apex:page sidebar="false">
<apex:includeLightning />
<div id="lightning" />
<script>
$Lightning.use("c:TestApp", function() {
$Lightning.createComponent("c:TestComp",{},"lightning",function(cmp) {});
});
</script>
</apex:page>
TestController.cls
public class TestController {
@auraEnabled public static String fetchSessionId() {
return UserInfo.getSessionId();
}
}
TestApp.app
<aura:application extends ="ltng:outApp">
<aura:dependency resource="markup://c:TestComp"/>
</aura:application>
TestComp.cmp
<aura:component controller="TestController" implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes,force:lightningQuickAction">
<aura:attribute name="isPushTopicWorking" type="Boolean" default="false"/>
<ltng:require scripts="{!join(',',
$Resource.<staticResouceName> + '/cometd.js',
$Resource.<staticResouceName> + '/jquery_1_5_1.js',
$Resource.<staticResouceName> + '/json2.js',
$Resource.<staticResouceName> + '/jquery_cometd.js')}"
afterScriptsLoaded="{!c.afterScriptsLoaded}" />
isPushTopicWorking = {!v.isPushTopicWorking}
</aura:component>
Testcontroller.js
({
afterScriptsLoaded : function(component, event, helper) {
var action = component.get('c.fetchSessionId');
action.setCallback(this, function (response) {
var sessionId = response.getReturnValue();
helper.setupCometd(component, helper, sessionId);
});
$A.enqueueAction(action);
},
})
Helper.js
({
setupCometd : function(component, helper, sessionId) {
console.log($.cometd);
$.cometd.init({
url: window.location.protocol+'//'+window.location.hostname+'/cometd/24.0/',
requestHeaders: { Authorization:'OAuth '+sessionId}
});
$.cometd.addListener('/meta/handshake', function(message) {
console.log(message.successful);
});
$.cometd.subscribe('/topic/pustopicname', $A.getCallback(function(message) {
component.set('v.isPushTopicWorking',true);
}));
}
})
In summer 18 org we can see error is console log
There is no documentation in release notes for change in cometd. What can be causing this issue.