├── README.md └── src ├── aura ├── Streamer │ ├── Streamer.cmp │ ├── Streamer.cmp-meta.xml │ ├── StreamerController.js │ └── StreamerHelper.js └── StreamerEvent │ ├── StreamerEvent.evt │ └── StreamerEvent.evt-meta.xml ├── classes ├── StreamerCtrl.cls ├── StreamerCtrl.cls-meta.xml ├── StreamerCtrlTest.cls └── StreamerCtrlTest.cls-meta.xml ├── package.xml └── staticresources ├── streaming.resource └── streaming.resource-meta.xml /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated. Archived. 2 | 3 | ## You should not use this for anything--use the new lightning:empApi (winter19 release). 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | --- 14 | 15 | LightningStreamer 16 | 17 | 1. gets a sessionId via apex 18 | 2. subscribes to a push topic or platform event that you set as an attribute 19 | 3. listens for messages, and emits the messages uncensored as a lightning standard *application* event 20 | 4. Then your other components listen for that event 21 | 22 | ### Setup 23 | 24 | * Install 25 | * create a push topic or platform event (google if you don't know how) 26 | * use in another component or in your app like this 27 | 28 | ``` 29 | 30 | ``` 31 | 32 | or 33 | 34 | ``` 35 | 36 | ``` 37 | 38 | other components should listen thusly: 39 | 40 | ``` 41 | 42 | 43 | ``` 44 | in the controller handler function: 45 | 46 | ``` 47 | var message = event.getParam("message"); 48 | var channel = event.getParam("channel"); //channel = 'streamingAPISubscriber' 49 | ``` 50 | 51 | the message is the typical streaming api message: message.data.sobject (streaming topic) or message.data.payload (events) 52 | 53 | 54 | ### Philosopy 55 | Streamer is very stupid, it just listens and repeats everthing it hears--no traffic control or directed communications. 56 | 57 | It's the job of the other components to handle all messages, deciding what they should do with them, if anything. 58 | 59 | 60 | Deploy to Salesforce 62 | 63 | -------------------------------------------------------------------------------- /src/aura/Streamer/Streamer.cmp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/aura/Streamer/Streamer.cmp-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36.0 4 | A Lightning Component Bundle 5 | 6 | -------------------------------------------------------------------------------- /src/aura/Streamer/StreamerController.js: -------------------------------------------------------------------------------- 1 | /* global $ */ 2 | 3 | ({ 4 | doInit : function(component, event, helper) { 5 | console.log('doing init on streamer'); 6 | 7 | // Retrieve the session id and initialize cometd 8 | let sessionAction = component.get("c.sessionId"); 9 | let url = helper.buildUrl(component); 10 | 11 | sessionAction.setCallback(this, function(response) { 12 | let state = response.getState(); 13 | if(state === "SUCCESS") { 14 | let sessionId = response.getReturnValue(); 15 | let authstring = "OAuth " + sessionId; 16 | 17 | //authenticate to the Streaming API 18 | $.cometd.init({ 19 | url: window.location.protocol + '//' + window.location.hostname + '/cometd/40.0/', 20 | requestHeaders: { Authorization: authstring }, 21 | appendMessageTypeToURL : false 22 | }); 23 | 24 | $.cometd.subscribe(url, function (message){ 25 | let evt = $A.get("e.ltng:sendMessage"); 26 | evt.setParams({"message" : message, "channel" : "streamingAPISubscriber"}); 27 | evt.fire(); 28 | }); 29 | } 30 | 31 | }); 32 | 33 | $A.enqueueAction(sessionAction); 34 | } 35 | }) -------------------------------------------------------------------------------- /src/aura/Streamer/StreamerHelper.js: -------------------------------------------------------------------------------- 1 | ({ 2 | buildUrl : function(component) { 3 | if (component.get("v.topic")){ 4 | return '/topic/'+component.get("v.topic"); 5 | } else if (component.get("v.platformEvent")){ 6 | return '/event/'+component.get("v.platformEvent"); 7 | } else { 8 | console.error('Neither the topic nor the platform event is specified'); 9 | } 10 | 11 | } 12 | }) -------------------------------------------------------------------------------- /src/aura/StreamerEvent/StreamerEvent.evt: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/aura/StreamerEvent/StreamerEvent.evt-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36.0 4 | A Lightning Component Bundle 5 | 6 | -------------------------------------------------------------------------------- /src/classes/StreamerCtrl.cls: -------------------------------------------------------------------------------- 1 | public class StreamerCtrl { 2 | 3 | @AuraEnabled 4 | public static String sessionId() { 5 | return UserInfo.getSessionId(); 6 | } 7 | 8 | 9 | } -------------------------------------------------------------------------------- /src/classes/StreamerCtrl.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /src/classes/StreamerCtrlTest.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | private class StreamerCtrlTest 3 | { 4 | @isTest 5 | static void itShouldReturnSessionId() 6 | { 7 | string sid = StreamerCtrl.sessionId(); 8 | system.assertNotEquals(sid, null); 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /src/classes/StreamerCtrlTest.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 34.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /src/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | StreamerCtrl 5 | StreamerCtrlTest 6 | ApexClass 7 | 8 | 9 | Streamer 10 | StreamerEvent 11 | AuraDefinitionBundle 12 | 13 | 14 | streaming 15 | StaticResource 16 | 17 | 34.0 18 | -------------------------------------------------------------------------------- /src/staticresources/streaming.resource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mshanemc/lightningStreamer/eb8c2872b14ca0f28a10b2c9b4c36b1ada278d59/src/staticresources/streaming.resource -------------------------------------------------------------------------------- /src/staticresources/streaming.resource-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Private 4 | application/octet-stream 5 | 6 | --------------------------------------------------------------------------------