Startup Slam!
Vic Startups Talk. Real Code. Real Technology.
On September 20th, 2014, five ambitious startups visited the University of Victoria (UVic). Kiind, Tiny Mob Games, Kano Apps, Sendwithus, and Pretio Interactive delievered tech talks to UVic students.
2. About Pretio
We power reward-based advertising on mobile apps and FB games
3.
4.
5. Why this Project
We wanted to start making visualizations of our data
See patterns in geographic location
Show traffic changes and shifts in popularity as they happen
Investors like pretty graphs!
6. Where's the Data From?
Mobile Ad Unit API
Traffic from one of our US-only publishers
12. Why not Websockets??
Bidirectional, more flexibility
Special server support needed
SSE - lines of text from a long HTTP connection
Auto reconnects!
14. In the browser
// Connect to server
var source = new EventSource('server/path/to/events');
source.addEventListener('open', function(e) {
console.log('Connected!');
});
// Listen for "location" events
source.addEventListener('location', function(e) {
// We're sending data as JSON
var data = JSON.parse(e.data);
displayOnMap(data.latitude, data.longitude);
});
15. node.js
So hot right now
Event-driven JavaScript on the server
Good for building "real-time" apps
16. The app
Uses Express
for rendering web pages
Simple UDP server that receives events
17. Listening for UDP packets
var udpServer = udp.createSocket('udp4', function(msg, remote) {
console.log('Received message from ' + remote.address + ':' + remote.port);
try {
var data = JSON.parse(msg);
// Send out as event
events.emit('received', data);
} catch(err) {
console.error('Error parsing message: ' + err);
}
});
// Listen for UDP messages
udpServer.bind(PORT, '0.0.0.0');
18. Event Stream
app.get('/events', function(req, res) {
console.log('New client connected!');
res.status(200)
.set({
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
// Listen for events from UDP server
events.on('received', function(data) {
// Send new "location" event to browser
res.write('event: locationn');
res.write('data: ' + JSON.stringify(data) + 'nn');
});
});
19. Logstash
A tool for parsing, rewriting and shipping logs
Continuous pipeline of events
Connects to almost everything (log files, queues, sockets, DBs, etc.)
IP » Geo is built-in