Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Client-side function that invokes the subscribe method on the empApi component.
- subscribe: function (component, event, helper) {
- // Get the empApi component.
- console.log('calling to subscribe');
- debugger;
- var empApi = component.find('empApi');
- // Get the channel from the attribute.
- var channel = component.get('v.channel');
- // Subscription option to get only new events.
- var replayId = -1;
- // Callback function to be passed in the subscribe call.
- // After an event is received, this callback prints the event
- // payload to the console. A helper method displays the message
- // in the console app.
- var subscribeCallback = function (message) {
- console.log('Event Received : ' + JSON.stringify(message));
- helper.onReceiveNotification(component, message);
- };
- // Subscribe to the channel and save the returned subscription object.
- empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
- console.log('Subscribed to channel ' + channel);
- component.set('v.subscription', newSubscription);
- }));
- /*.catch(
- function(error) {
- console.error('cant subscribe to event ', JSON.stringify(error));
- }
- );*/
- },
- empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
- console.log('Subscribed to channel ' + channel);
- component.set('v.subscription', newSubscription);
- }));
Add Comment
Please, Sign In to add comment