Guest User

Untitled

a guest
Dec 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. // Client-side function that invokes the subscribe method on the empApi component.
  2. subscribe: function (component, event, helper) {
  3. // Get the empApi component.
  4. console.log('calling to subscribe');
  5. debugger;
  6. var empApi = component.find('empApi');
  7. // Get the channel from the attribute.
  8. var channel = component.get('v.channel');
  9. // Subscription option to get only new events.
  10. var replayId = -1;
  11. // Callback function to be passed in the subscribe call.
  12. // After an event is received, this callback prints the event
  13. // payload to the console. A helper method displays the message
  14. // in the console app.
  15. var subscribeCallback = function (message) {
  16. console.log('Event Received : ' + JSON.stringify(message));
  17. helper.onReceiveNotification(component, message);
  18. };
  19. // Subscribe to the channel and save the returned subscription object.
  20. empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
  21. console.log('Subscribed to channel ' + channel);
  22. component.set('v.subscription', newSubscription);
  23. }));
  24.  
  25. /*.catch(
  26. function(error) {
  27. console.error('cant subscribe to event ', JSON.stringify(error));
  28. }
  29. );*/
  30. },
  31.  
  32. empApi.subscribe(channel, replayId, subscribeCallback).then($A.getCallback(function (newSubscription) {
  33. console.log('Subscribed to channel ' + channel);
  34. component.set('v.subscription', newSubscription);
  35. }));
Add Comment
Please, Sign In to add comment