To run:
git clone git@github.com:richiepreece/adobe-livestream-demo
cd adobe-livestream-demo
cp example.config.json config.json
// Populate config file
npm install
npm start
This lab uses the following software: *Adobe Brackets *NodeJS *Mac OS Terminal
- Download the code.
- Go to the bookmarks in Chrome and select
https://github.com/richiepreece/adobe-livestream-demo
- Click the download green button
- Select “Download ZIP”
- Go to the bookmarks in Chrome and select
- Move the file and unzip it.
- Using Finder, locate the file in the Downloads folder.
- Move the file to your home directory.
- Unzip the file by double clicking it.
- Prepare the NodeJS app.
- Go to the terminal and navigate to the folder.
- Run “npm install” and wait.
- Copy the config file
cp example.config.json config.json
- Configure the app.
- Open the code in Brackets.
- Select the "File" (drop-down) -> "Open Folder".
- Select the folder of the app in your home directory.
- Update the config
- Open "config.json"
- Update the URL
- Update the username
- Update the password
- Change the name of the config file
- Run the app.
- To start the app, type this command in the terminal:
npm start
- To stop the app, push
control
+c
at the same time on the keyboard.
- Go to line 14 of
livestream_listener.js
. - Enter this block of code:
// Kill after after a certain # of hits.
if (hits == stopAfter) {
process.exit();
}
- Add the
stopAfter
variable on about line 6 with a value of1
;
var stopAfter = 1;
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
- To display the number of hits, we need a place in the app to do so when our processing is complete.
- Go to line 23 of
livestream_listener.js
. - Add this block of code:
var result = {
totalHits: hits
};
return result;
- Change the
stopAfter
value to10
on line 6. - Change the
console.log
on line 12 to give simple feedback when a hit is received.
console.log('hit');
- Save
livestream_listener.js
. - Go to
connector.js
line 35. - Add this block of code:
process.on("exit", function() {
write();
});
function write () {
_.each(callbacks.writeToDB, function (item) {
var result = item();
console.log(result); //TODO write to db
});
}
- Save
connector.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
. - On line 7, add the following variables:
var recentHits = 0;
- Change the
stopAfter
value to1000
on line 9. - On line 12, add:
// Increment total hit counter.
++recentHits;
- Update line 27 to look like this:
totalHits: hits,
recentHits: recentHits
- Add this block under the
result
variable:
recentHits = 0;
- Save
livestream_listener.js
. - Go to
connector.js
. - Add this block of code on line 47:
setInterval(function () {
write();
}, 5000)
- Save
connector.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
and add a variable for Active Visitors on line 8:
var uniqueVisitors = {};
- Add the code to calculate Active Visitors at about line 17:
// Calculate Active Visitors on site.
if(!uniqueVisitors[hit.visIdLow + '' + hit.visIdHigh]) {
uniqueVisitors[hit.visIdLow + '' + hit.visIdHigh] = true;
}
- Update the
result
variable on line 33 to be:
recentHits: recentHits,
uniqueVisitors: _.keys(uniqueVisitors).length
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
. - Add a variable for Events, Props, and eVars on about line 8;
var events = {};
var props = {};
var eVars = {};
- Add processing for Events, Props, and eVars by adding this block of code under the Active Visitors section:
// All Events.
if(hit.events) {
_.each(hit.events, function (item, key) {
events[key] = events[key] ? events[key] + 1 : 1;
});
}
// All Props.
if(hit.props) {
_.each(hit.props, function (item, key) {
props[key] = props[key] ? props[key] + 1 : 1;
props[key] = props[key] || {};
props[key][item] = props[key][item] ? props[key][item] + 1 : 1;
});
}
// All eVars.
if(hit.evars && hit.evars.evars) {
_.each(hit.evars.evars, function (item, key) {
eVars[key] = eVars[key] || {};
eVars[key][item] = eVars[key][item] ? eVars[key][item] + 1 : 1;
});
}
- Update the
result
variable on line 33 to be:
uniqueVisitors: _.keys(uniqueVisitors).length,
events: events,
props: props,
eVars: eVars
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
Extra Credit.