It’s all about Lightning right now and rightly so it’s the future; a good looking, exciting future. So what have I been doing with all of this then? I always find new technology is best learnt when you have a real use case and I have been lucky enough to have one to work on over the past few weeks. Not only that but it’s one that has lead me to have to do something that I couldn’t find documented anywhere!I’m not going to regal you with the details of the project right now – if you’re at Dreamforce though drop by the IoT zone and find, myself, Paul Battisson or Will Coleman and you should be able to see the fruits of our labour. If you’re not at DF then I’ll follow up in a couple of weeks time.
Anyway, “The Project” has required a custom user interface to be built in Salesforce and after an initial prototype in Visualforce we decided to shift across to Lightning – it’s what all the cool kids seem to be doing! One of the challenges that we had was to make the user interface play audio on demand. The playing piece is pretty easy, just use the <audio> tag it’s the “on demand” piece that proved more of a challenge.
Who Are You?
How fantastic! But why is this really of any interest? It helped immeasurably with this project but does it have any wider application, should you care about it? Well actually, yes, I think it does have broader appeal. Lightning is pretty cool, it looks good and it has this fantastic event driven architecture behind it allowing components to communicate with each other. But that’s all client side, what happens if there’s an event on the server side that you want your UI to react to. Sure you could build your own polling solution to look for those changes and then send out the relevant client side events. But that’s what the Streaming API does for us, so why would you ever rebuild something that already exists?! Using this code we can create ourselves a simple component that connects to the Streaming API, listens to Push Topics and then raises client side events for all our other component to react to. Taking this code and extending that isn’t a massive jump and something I’ll leave you to do yourselves – doing is the best learning remember 😉
So, whilst it’s not pretty it certainly works and is a great way to get Streaming API functionality into your Lightning components and consequently raise events on the client side for changes on the server. As for it’s robustness, well I’ll leave that one up to you – it’s clearly not going to be documented or supported by Salesforce. But it works and often that’s all that matters.