Last active
October 12, 2018 18:11
-
-
Save tsmalara/7798f8803a217dfc67f9359ebcd53447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(cmp, event, helper, isinit) { | |
var empApi = cmp.find("empApi"); | |
// Handle any errors and print them to the console. | |
var errorHandler = function (message) { | |
console.log("Received error ", message); | |
}.bind(this); | |
// Register the error listener | |
empApi.onError(errorHandler); | |
var channel='/event/Demo_EmpApi_Event__e'; | |
var sub; | |
// use -1 for new events | |
var replayId=-1; | |
var callback = function (message) { | |
alert(message); | |
}.bind(this); | |
empApi.subscribe(channel, replayId, callback).then(function(value) { | |
console.log("Subscribed to channel " + channel); | |
sub = value; | |
cmp.set("v.sub", sub); | |
}); | |
}, | |
doPublishEvent : function(cmp, event){ | |
var action = cmp.get("c.publishEvent"); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (cmp.isValid() && state === "SUCCESS") { | |
console.log("Event published successfully!"); | |
} | |
else { | |
console.log("Failed with state: " + state); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment