SlideShare ist ein Scribd-Unternehmen logo
1 von 176
Downloaden Sie, um offline zu lesen
A web framework for
single page apps
Created by
Owen Barnes
@temporalwave
!
!

(my boss at a former company)
About me
Paul Jensen
@paulbjensen
!
!

(I’m the new lead developer)
Where to begin?
Why Single Page
Apps?
With a traditional web app,
the user has to refresh the
page to see new information
Client

Server

Time
GET/football/live

Client

Server

Time

HTTP/1.1
HTTP/1.1 200 OK

Client

Server

Time
20 seconds later…

Client

Server

Time
I wonder what the latest score is…
Let’s reload the page

Client

Server

Time
GET/football/live

Client

Server

Time

HTTP/1.1
HTTP/1.1 304 Not Modified

Client

Server

Time
Client

Server

Time
The user had to press F5
to get at any new information
Client

Server

Time
Client

Server

Time

Even though there was
no new information,
the server still had to serve
the HTTP request
This is not a fun experience
How do we make this
better?
Client

Server

Time
We could use AJAX to
update the page
We’d save the user
having to press the F5 key
What else can we do?
Client

Server

Time
Optimise the response
GZIP the response
data, and …
Avoid sending data we
already have on the client
We could also
separate the HTML
from the data
Reuse the HTML on
the client
…and use the server to
provide you with just
data
And the web site becomes a
client

Web App

Native App

Server

API User
The server is just an API
A beautiful separation
of concerns
Overview
•

The server becomes a REST API serving JSON

•

HTML compilation is done on the client

•

As a result, less processing & bandwidth is
consumed by the server
Why Realtime?
Client

Server

Time
Polling the server every
[n] seconds for new
data is redundant
There has to be a
better way
What if the server could
send its client(s) new
data as soon as it came
about?
We can, thanks to
WebSockets
WebSockets allows data
to be sent both ways
Client

Server

Time
Client

Server

Time

Goal
The server sends a message
to the client that an action has
occurred

Client

Server

Time

Goal
We eliminate the need
to poll the server for
new data
Overview
•

We can replace AJAX polling with WebSockets,
and provide a better user experience as a result

•

We also remove the need to make redundant
polling requests back to the server.

•

We use WebSockets for sending/receiving JSON
Single Page Apps
+
The Realtime Web
There are many ways
to build this kind of
app
You could build it
mostly from scratch, and
use Express + Socket.io
Or alternatively, you
could use a web
framework like Meteor
or Firebase
SocketStream is
somewhere in-between
these 2 approaches
It provides tools to help
with building realtime
single page apps...
... Whilst trying not to
restrict what
technologies you can
use with your app
For example, we don't
provide an ORM.
Instead, you choose the
database & the ORM
Also, we don't mandate using a
specific client-side framework
!

You can use BackBone, Angular,
Ember, or something else, that is
entirely your choice.
What we focus on
instead are these
things:
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
I'll run through each of
these, 1-by-1. But first,
let's look at how to use
SocketStream
Getting started

npm install -g socketstream
!

socketstream new my_app
Getting started
!

!
!
!

Success! Created app 'my_app' with:
✓ Basic chat demo (-m for minimal install)
✓ Javascript example code (-c if you prefer CoffeeScript)
✓ Plain HTML for views (-j if you prefer Jade)
Next, run the following commands:
cd my_app
[sudo] npm install
To start your app:
node app.js

Here's what the initial file/
folder structure looks like
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
Client code is organised
into 5 sub-folders
Client side code organisation
•

CODE stores client side JavaScript files and libraries

•

CSS stores CSS files

•

STATIC stores public files like images, font files, and other
assets

•

TEMPLATES stores HTML templates for the single page
app to render on the client

•

VIEWS stores HTML files that are rendered from the server
for the initial page
Those sub-folders have subfolders, but are optional
This is how we load them
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
// My SocketStream 0.3 app

!

var http = require('http'),
ss = require('socketstream');

!

// Define a single-page client called 'main'
ss.client.define('main', {
view: 'app.html',
css: ['libs/reset.css', 'app.styl'],
code: ['libs/jquery.min.js', 'app'],
tmpl: '*'
});

!

// Serve this client on the root URL
ss.http.route('/', function(req, res){
res.serveClient('main');
});
SocketStream uses
Browserify to handle
requiring JS files
Browserify allows us to
use a Node.js style of
requiring JS files
// This file automatically gets called first by
SocketStream and must always exist

!

// Make 'ss' available to all modules and the
browser console
window.ss = require('socketstream');

!

ss.server.on('disconnect', function(){
console.log('Connection down :-(');
});

!

ss.server.on('reconnect', function(){
console.log('Connection back up :-)');
});

!

ss.server.on('ready', function(){

!

!
!

// Wait for the DOM to finish loading
jQuery(function(){
// Load app
require('/app');
});

});
// This file automatically gets called first by
SocketStream and must always exist

!

// Make 'ss' available to all modules and the
browser console
window.ss = require('socketstream');

!

ss.server.on('disconnect', function(){
console.log('Connection down :-(');
});

!

ss.server.on('reconnect', function(){
console.log('Connection back up :-)');
});

!

ss.server.on('ready', function(){

!

!
!

// Wait for the DOM to finish loading
jQuery(function(){
// Load app
require('/app');
});

});
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
Over the years, developers
have come up with new
languages to generate
HTML, CSS, and JavaScript
SocketStream allows
developers to use these
code preprocessors in
their apps
Adding a preprocessor is simple

// Code Formatters
ss.client.formatters.add(require('ss-stylus'));
For Javascript

•

SS-COFFEE - supports using CoffeeScript

•

SS-GORILLA - supports using GorillaScript
For CSS

•

SS-STYLUS - supports using Stylus

•

SS-LESS - supports using Less
For HTML Views

•

SS-JADE - supports using Jade
For HTML Templating

•

SS-HOGAN - supports using Twitter's Hogan.js

•

SS-COFFEEKUP - supports using CoffeeKup
Setting a Templating engine

// Use server-side compiled Hogan (Mustache)
templates. Others engines available
ss.client.templateEngine.use(require('ss-hogan'));
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
Having to press F5 to reload
the page in order to view
changes to HTML/CSS/JS...
... is not a fun experience
In development mode,
SocketStream will watch the
client files for changes, and
reload the page when they
occur
In the case of CSS,
SocketStream will apply
the changes without
reloading the page
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
Client-side HTML
templates are made
available to the browser
via the ss.tmpl object
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
When you're building a
single page app, you'll
have a lot of JS files, and
maybe a few CSS files
But serving a HTML
page with lots of these
files can take time, and
is inefficient
SocketStream provides a
way to concatenate, minify,
and GZip these files into 1
JS and 1 CSS file
This saves bytes being
transferred, as well as
reducing the number of
HTTP requests you make
Also, you can tell
SocketStream to load
these files from a CDN
Setting a Templating engine

// Minimize and pack assets if you type: SS_ENV=production node app.js
if (ss.env === 'production') ss.client.packAssets();
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
Web Workers are handy
for intensive client-side
JS operations
SocketStream provides
support for using Web
Workers in your app
First, create a folder
Next, put your web worker files in
that folder
Then, load the worker in a client
code file, and enjoy
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
SocketStream uses
Connect middleware to
support HTTP features
SocketStream uses the following
middleware by default:
•

compress - for GZipping assets

•

cookieParser - for handling user tracking

•

favicon - for serving a favicon.ico file

•

session - for handling sessions

•

static - for serving static assets
SocketStream uses the following
middleware by default:
•

compress middleware is loaded first, before all
other middleware

•

static middleware is loaded last, after all other
middleware
SocketStream provides
a way to load custom
middleware into the
connect stack
ss.http.middleware.prepend()
ss.http.middleware.append()
This allows you to use all
of the connect
middleware out there
today, i.e. EveryAuth
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
We use connect’s session
middleware, so authentication
can be done with either
EveryAuth, PassportJS, or you
can roll your own.
We also recommend
using connect-redis
Both HTTP and
WebSocket interfaces
can get/set the session
data
Via HTTP
// app.js
ss.http.router.on('/updateSession', function(req, res) {
req.session.myVar = 4321;
res.end('req.session.myVar has been updated to', req.session.myVar);
});
Via WebSockets
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
RPC is a common
pattern for clients
requesting data from
the server
SocketStream provides
a way to construct RPC
APIs with flexibility
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
PubSub is a great
pattern for Single Page
Apps
SocketStream handles
this in various ways:
1 - Publishing to everyone
viewing the app right now
Server
ss.publish.all('newMessage', message);

// Broadcast the message to everyone

Client
// Listen out for newMessage events coming from the server
ss.event.on('newMessage', function(message) {
// do something with the message
});
2 - Sending to private channels
Server (subscribe/unsubscribe the session )
// in a /server/rpc file after calling req.use('session') middleware

!

req.session.channel.subscribe('disney')

!

req.session.channel.unsubscribe('kids')

!

req.session.channel.reset()

// unsubscribes the session from every channel

req.session.channel.list()

// shows what channels are subscribed to

!
2 - Sending to private channels
Server (publish to channel)
// in a /server/rpc file
ss.publish.channel('disney', 'chatMessage', {from: 'jerry', message: 'Has anyone seen
Tom?'});

Client (receive channel message)
// in a /client/code file
ss.event.on('chatMessage', function(msg, channelName){
console.log('The following message was sent to the ' + channelName + ' channel:', msg);
});
3 - Sending to users
Server
// in a /server/rpc file
ss.publish.user('fred', 'specialOffer', 'Here is a special offer just for you!');
4 - Sending to a browser
tab
Server
// in a /server/rpc file
ss.publish.socketId('254987654324567', 'justForMe', 'Just for one tab');
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
On top of RPC and PubSub,
SocketStream provides you
with a way to create custom
request responders
Request Response is
basically a WebSocket
message handler
It allows you to write
message handling for
games, where every
byte matters
HTML / CSS / JS
code preprocessing

Minifying CSS/JS for
production use

Client-side code
organisation

HTML Templates

WebSocket
Management

Live Reload

Building RPC APIs

Building PubSub APIs

Session Management

Building custom APIs
on top of WS

Web Workers

Connect middleware
compatibility
WebSockets are not
immortal…
They are mangled by
mobile networks…
Blocked by firewalls…
Routed to dead ends by
proxy servers
And severed by train
tunnels
Also, browser support
for WebSockets isn’t
guaranteed
You need a transport
strategy
Originally, SocketStream
used Socket.io
But Socket.io asserted
that if a browser
supported WebSockets,
then it would work
They learned from this,
by building Engine.io
I created the transport
wrapper for Engine.io in
SocketStream for
Bechtel & Dashku
And designed it to
reconnect the client
when severed
Months later, it made it’s
way into SocketStream’s
core.
SocketStream let’s you
use this, alongside
SockJS
…and that is
SocketStream in a
nutshell. Whew!
Let’s look at some
SocketStream apps in
the wild
Hollow
hollowdocumentary.com
Vmux
vmux.co
Dashku
dashku.com
SocketStream plugins
SS-BACKBONE
SS-ANGULAR
SS-CUCUMBER
Tips for deploying
SocketStream in
production
1 - Check your server’s
ulimit configuration
(This can bite you hard)
I learned this when Dashku went
#1 on Hacker News in 45min
2 - Use HTTPS, but
handle it at the load
balancer level rather
than at the app level
HTTPS helps to improve
the stability of WebSocket
connections, especially
on mobile devices
But Node’s HTTPS
implementation is
noticeably slower than
using HAProxy or Nginx
Where is SocketStream
going next?
We’re in the process of
getting SocketStream’s
test coverage up
We’re also trying to
close some ancient
bugs
We also need better
documentation
We’re giving the web
site an overhaul
And we want to
document how
SocketStream’s internals
function, to help build 0.4
but what about 0.4?
…0.4 is starting to look like these:
I promise you all, it’s
coming in June 2014
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloHTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloRobert Nyman
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for MobileRemy Sharp
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service WorkerChang W. Doh
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patternsStoyan Stefanov
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance PatternsStoyan Stefanov
 
High Performance Social Plugins
High Performance Social PluginsHigh Performance Social Plugins
High Performance Social PluginsStoyan Stefanov
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)Nicholas Zakas
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third PluginJustin Ryan
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Nicholas Zakas
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedPeter Lubbers
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!Nicholas Zakas
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery PluginsMarc Grabanski
 
Building a PWA - For Everyone Who Is Scared To
Building a PWA - For Everyone Who Is Scared ToBuilding a PWA - For Everyone Who Is Scared To
Building a PWA - For Everyone Who Is Scared ToRaymond Camden
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video PlayerJim Jeffers
 

Was ist angesagt? (20)

WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao PauloHTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
HTML5, The Open Web, and what it means for you - MDN Hack Day, Sao Paulo
 
Mastering Grunt
Mastering GruntMastering Grunt
Mastering Grunt
 
Developing for Mobile
Developing for MobileDeveloping for Mobile
Developing for Mobile
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service Worker
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
 
High Performance Social Plugins
High Performance Social PluginsHigh Performance Social Plugins
High Performance Social Plugins
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third Plugin
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
HTML5 Web Workers-unleashed
HTML5 Web Workers-unleashedHTML5 Web Workers-unleashed
HTML5 Web Workers-unleashed
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
 
Liking performance
Liking performanceLiking performance
Liking performance
 
Building a PWA - For Everyone Who Is Scared To
Building a PWA - For Everyone Who Is Scared ToBuilding a PWA - For Everyone Who Is Scared To
Building a PWA - For Everyone Who Is Scared To
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 

Andere mochten auch

Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 
Lambda Architecture with Spark
Lambda Architecture with SparkLambda Architecture with Spark
Lambda Architecture with SparkKnoldus Inc.
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1Yi-Huan Chan
 
Ese Neno Da Rua
Ese Neno Da RuaEse Neno Da Rua
Ese Neno Da Ruarosal0453
 
Springbreak Workshop
Springbreak WorkshopSpringbreak Workshop
Springbreak Workshopemmer
 
Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Syukran
 
Proyek penciptaan dan digitalisasi konten
Proyek penciptaan dan digitalisasi kontenProyek penciptaan dan digitalisasi konten
Proyek penciptaan dan digitalisasi kontenWikimedia Indonesia
 
Lesson16vocab
Lesson16vocabLesson16vocab
Lesson16vocabPEDH
 
洋服はあなたの良さを引き立てるコミュニケーション
洋服はあなたの良さを引き立てるコミュニケーション洋服はあなたの良さを引き立てるコミュニケーション
洋服はあなたの良さを引き立てるコミュニケーションNaoko Kawachi
 
Proposal Bebaskan Pengetahuan 2014
Proposal Bebaskan Pengetahuan 2014Proposal Bebaskan Pengetahuan 2014
Proposal Bebaskan Pengetahuan 2014Wikimedia Indonesia
 
how to get a job in advertising
how to get a job in advertisinghow to get a job in advertising
how to get a job in advertisingHelen Klein Ross
 
Presentatie ExcellentSecretary
Presentatie ExcellentSecretaryPresentatie ExcellentSecretary
Presentatie ExcellentSecretarymarckuipers
 
State and Capital Game
State and Capital GameState and Capital Game
State and Capital Gameorange_pizza
 
Vocab lesson 11
Vocab lesson 11Vocab lesson 11
Vocab lesson 11PEDH
 

Andere mochten auch (20)

Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
Lambda Architecture with Spark
Lambda Architecture with SparkLambda Architecture with Spark
Lambda Architecture with Spark
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1
 
Ese Neno Da Rua
Ese Neno Da RuaEse Neno Da Rua
Ese Neno Da Rua
 
Aspen Lion
Aspen LionAspen Lion
Aspen Lion
 
Segundo Caraujulca Galvez
Segundo Caraujulca GalvezSegundo Caraujulca Galvez
Segundo Caraujulca Galvez
 
Springbreak Workshop
Springbreak WorkshopSpringbreak Workshop
Springbreak Workshop
 
Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)
 
Proyek penciptaan dan digitalisasi konten
Proyek penciptaan dan digitalisasi kontenProyek penciptaan dan digitalisasi konten
Proyek penciptaan dan digitalisasi konten
 
Lontar class 2
Lontar class 2Lontar class 2
Lontar class 2
 
Lesson16vocab
Lesson16vocabLesson16vocab
Lesson16vocab
 
洋服はあなたの良さを引き立てるコミュニケーション
洋服はあなたの良さを引き立てるコミュニケーション洋服はあなたの良さを引き立てるコミュニケーション
洋服はあなたの良さを引き立てるコミュニケーション
 
Proposal Bebaskan Pengetahuan 2014
Proposal Bebaskan Pengetahuan 2014Proposal Bebaskan Pengetahuan 2014
Proposal Bebaskan Pengetahuan 2014
 
DoInk2'
DoInk2'DoInk2'
DoInk2'
 
how to get a job in advertising
how to get a job in advertisinghow to get a job in advertising
how to get a job in advertising
 
Presentatie ExcellentSecretary
Presentatie ExcellentSecretaryPresentatie ExcellentSecretary
Presentatie ExcellentSecretary
 
QUESTION 7
QUESTION 7QUESTION 7
QUESTION 7
 
State and Capital Game
State and Capital GameState and Capital Game
State and Capital Game
 
Kelas lontar 1
Kelas lontar 1Kelas lontar 1
Kelas lontar 1
 
Vocab lesson 11
Vocab lesson 11Vocab lesson 11
Vocab lesson 11
 

Ähnlich wie SocketStream

Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionParth Joshi
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.jsAyush Mishra
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.jsMd. Sohel Rana
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)Prof Ansari
 
3 Tips to Deliver Fast Performance Across Mobile Web
3 Tips to Deliver Fast Performance Across Mobile Web3 Tips to Deliver Fast Performance Across Mobile Web
3 Tips to Deliver Fast Performance Across Mobile WebDynatrace
 
Building ColdFusion And AngularJS Applications
Building ColdFusion And AngularJS ApplicationsBuilding ColdFusion And AngularJS Applications
Building ColdFusion And AngularJS ApplicationsColdFusionConference
 
Testable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascriptTestable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascriptTimothy Oxley
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The WhenFITC
 
Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a BottleZohar Arad
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern AppsMeteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern AppsSashko Stubailo
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat ClientPaul Klipp
 

Ähnlich wie SocketStream (20)

Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
Introduction to node.js
Introduction to  node.jsIntroduction to  node.js
Introduction to node.js
 
08 ajax
08 ajax08 ajax
08 ajax
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)
 
Node js getting started
Node js getting startedNode js getting started
Node js getting started
 
Play framework
Play frameworkPlay framework
Play framework
 
3 Tips to Deliver Fast Performance Across Mobile Web
3 Tips to Deliver Fast Performance Across Mobile Web3 Tips to Deliver Fast Performance Across Mobile Web
3 Tips to Deliver Fast Performance Across Mobile Web
 
Building ColdFusion And AngularJS Applications
Building ColdFusion And AngularJS ApplicationsBuilding ColdFusion And AngularJS Applications
Building ColdFusion And AngularJS Applications
 
Testable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascriptTestable client side_mvc_apps_in_javascript
Testable client side_mvc_apps_in_javascript
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a Bottle
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern AppsMeteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
Meteor MIT Tech Talk 9/18/14: Designing a New Platform For Modern Apps
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat Client
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 

Mehr von Paul Jensen

End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...Paul Jensen
 
Objection.js, a SQL ORM
Objection.js, a SQL ORMObjection.js, a SQL ORM
Objection.js, a SQL ORMPaul Jensen
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerPaul Jensen
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkitPaul Jensen
 
Geokit In Social Apps
Geokit In Social AppsGeokit In Social Apps
Geokit In Social AppsPaul Jensen
 

Mehr von Paul Jensen (6)

End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Objection.js, a SQL ORM
Objection.js, a SQL ORMObjection.js, a SQL ORM
Objection.js, a SQL ORM
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
Lnug jan 2018
Lnug jan 2018Lnug jan 2018
Lnug jan 2018
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
 
Geokit In Social Apps
Geokit In Social AppsGeokit In Social Apps
Geokit In Social Apps
 

Kürzlich hochgeladen

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

SocketStream

  • 1.
  • 2. A web framework for single page apps
  • 7. With a traditional web app, the user has to refresh the page to see new information
  • 12. I wonder what the latest score is… Let’s reload the page Client Server Time
  • 14. HTTP/1.1 304 Not Modified Client Server Time
  • 16. The user had to press F5 to get at any new information Client Server Time
  • 17. Client Server Time Even though there was no new information, the server still had to serve the HTTP request
  • 18. This is not a fun experience
  • 19. How do we make this better?
  • 21. We could use AJAX to update the page
  • 22. We’d save the user having to press the F5 key
  • 23. What else can we do?
  • 27. Avoid sending data we already have on the client
  • 28. We could also separate the HTML from the data
  • 29. Reuse the HTML on the client
  • 30. …and use the server to provide you with just data
  • 31. And the web site becomes a client Web App Native App Server API User
  • 32. The server is just an API
  • 34. Overview • The server becomes a REST API serving JSON • HTML compilation is done on the client • As a result, less processing & bandwidth is consumed by the server
  • 37. Polling the server every [n] seconds for new data is redundant
  • 38. There has to be a better way
  • 39. What if the server could send its client(s) new data as soon as it came about?
  • 40. We can, thanks to WebSockets
  • 41. WebSockets allows data to be sent both ways
  • 44. The server sends a message to the client that an action has occurred Client Server Time Goal
  • 45. We eliminate the need to poll the server for new data
  • 46. Overview • We can replace AJAX polling with WebSockets, and provide a better user experience as a result • We also remove the need to make redundant polling requests back to the server. • We use WebSockets for sending/receiving JSON
  • 47. Single Page Apps + The Realtime Web
  • 48. There are many ways to build this kind of app
  • 49. You could build it mostly from scratch, and use Express + Socket.io
  • 50. Or alternatively, you could use a web framework like Meteor or Firebase
  • 52. It provides tools to help with building realtime single page apps...
  • 53. ... Whilst trying not to restrict what technologies you can use with your app
  • 54. For example, we don't provide an ORM. Instead, you choose the database & the ORM
  • 55. Also, we don't mandate using a specific client-side framework ! You can use BackBone, Angular, Ember, or something else, that is entirely your choice.
  • 56. What we focus on instead are these things:
  • 57. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 58. I'll run through each of these, 1-by-1. But first, let's look at how to use SocketStream
  • 59. Getting started npm install -g socketstream ! socketstream new my_app
  • 60. Getting started ! ! ! ! Success! Created app 'my_app' with: ✓ Basic chat demo (-m for minimal install) ✓ Javascript example code (-c if you prefer CoffeeScript) ✓ Plain HTML for views (-j if you prefer Jade) Next, run the following commands: cd my_app [sudo] npm install To start your app: node app.js

  • 61. Here's what the initial file/ folder structure looks like
  • 62. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 63. Client code is organised into 5 sub-folders
  • 64. Client side code organisation • CODE stores client side JavaScript files and libraries • CSS stores CSS files • STATIC stores public files like images, font files, and other assets • TEMPLATES stores HTML templates for the single page app to render on the client • VIEWS stores HTML files that are rendered from the server for the initial page
  • 65. Those sub-folders have subfolders, but are optional
  • 66. This is how we load them // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 67. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 68. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 69. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 70. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 71. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 72. // My SocketStream 0.3 app ! var http = require('http'), ss = require('socketstream'); ! // Define a single-page client called 'main' ss.client.define('main', { view: 'app.html', css: ['libs/reset.css', 'app.styl'], code: ['libs/jquery.min.js', 'app'], tmpl: '*' }); ! // Serve this client on the root URL ss.http.route('/', function(req, res){ res.serveClient('main'); });
  • 73. SocketStream uses Browserify to handle requiring JS files
  • 74. Browserify allows us to use a Node.js style of requiring JS files
  • 75. // This file automatically gets called first by SocketStream and must always exist ! // Make 'ss' available to all modules and the browser console window.ss = require('socketstream'); ! ss.server.on('disconnect', function(){ console.log('Connection down :-('); }); ! ss.server.on('reconnect', function(){ console.log('Connection back up :-)'); }); ! ss.server.on('ready', function(){ ! ! ! // Wait for the DOM to finish loading jQuery(function(){ // Load app require('/app'); }); });
  • 76. // This file automatically gets called first by SocketStream and must always exist ! // Make 'ss' available to all modules and the browser console window.ss = require('socketstream'); ! ss.server.on('disconnect', function(){ console.log('Connection down :-('); }); ! ss.server.on('reconnect', function(){ console.log('Connection back up :-)'); }); ! ss.server.on('ready', function(){ ! ! ! // Wait for the DOM to finish loading jQuery(function(){ // Load app require('/app'); }); });
  • 77. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 78. Over the years, developers have come up with new languages to generate HTML, CSS, and JavaScript
  • 79. SocketStream allows developers to use these code preprocessors in their apps
  • 80. Adding a preprocessor is simple // Code Formatters ss.client.formatters.add(require('ss-stylus'));
  • 81. For Javascript • SS-COFFEE - supports using CoffeeScript • SS-GORILLA - supports using GorillaScript
  • 82. For CSS • SS-STYLUS - supports using Stylus • SS-LESS - supports using Less
  • 83. For HTML Views • SS-JADE - supports using Jade
  • 84. For HTML Templating • SS-HOGAN - supports using Twitter's Hogan.js • SS-COFFEEKUP - supports using CoffeeKup
  • 85. Setting a Templating engine // Use server-side compiled Hogan (Mustache) templates. Others engines available ss.client.templateEngine.use(require('ss-hogan'));
  • 86. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 87. Having to press F5 to reload the page in order to view changes to HTML/CSS/JS...
  • 88. ... is not a fun experience
  • 89. In development mode, SocketStream will watch the client files for changes, and reload the page when they occur
  • 90. In the case of CSS, SocketStream will apply the changes without reloading the page
  • 91. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 92. Client-side HTML templates are made available to the browser via the ss.tmpl object
  • 93.
  • 94. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 95. When you're building a single page app, you'll have a lot of JS files, and maybe a few CSS files
  • 96. But serving a HTML page with lots of these files can take time, and is inefficient
  • 97. SocketStream provides a way to concatenate, minify, and GZip these files into 1 JS and 1 CSS file
  • 98. This saves bytes being transferred, as well as reducing the number of HTTP requests you make
  • 99. Also, you can tell SocketStream to load these files from a CDN
  • 100. Setting a Templating engine // Minimize and pack assets if you type: SS_ENV=production node app.js if (ss.env === 'production') ss.client.packAssets();
  • 101. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 102. Web Workers are handy for intensive client-side JS operations
  • 103. SocketStream provides support for using Web Workers in your app
  • 104. First, create a folder
  • 105. Next, put your web worker files in that folder
  • 106. Then, load the worker in a client code file, and enjoy
  • 107. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 108. SocketStream uses Connect middleware to support HTTP features
  • 109. SocketStream uses the following middleware by default: • compress - for GZipping assets • cookieParser - for handling user tracking • favicon - for serving a favicon.ico file • session - for handling sessions • static - for serving static assets
  • 110. SocketStream uses the following middleware by default: • compress middleware is loaded first, before all other middleware • static middleware is loaded last, after all other middleware
  • 111. SocketStream provides a way to load custom middleware into the connect stack
  • 113. This allows you to use all of the connect middleware out there today, i.e. EveryAuth
  • 114. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 115. We use connect’s session middleware, so authentication can be done with either EveryAuth, PassportJS, or you can roll your own.
  • 116. We also recommend using connect-redis
  • 117. Both HTTP and WebSocket interfaces can get/set the session data
  • 118. Via HTTP // app.js ss.http.router.on('/updateSession', function(req, res) { req.session.myVar = 4321; res.end('req.session.myVar has been updated to', req.session.myVar); });
  • 120. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 121. RPC is a common pattern for clients requesting data from the server
  • 122. SocketStream provides a way to construct RPC APIs with flexibility
  • 123.
  • 124.
  • 125. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 126. PubSub is a great pattern for Single Page Apps
  • 128. 1 - Publishing to everyone viewing the app right now Server ss.publish.all('newMessage', message); // Broadcast the message to everyone Client // Listen out for newMessage events coming from the server ss.event.on('newMessage', function(message) { // do something with the message });
  • 129. 2 - Sending to private channels Server (subscribe/unsubscribe the session ) // in a /server/rpc file after calling req.use('session') middleware ! req.session.channel.subscribe('disney') ! req.session.channel.unsubscribe('kids') ! req.session.channel.reset() // unsubscribes the session from every channel req.session.channel.list() // shows what channels are subscribed to !
  • 130. 2 - Sending to private channels Server (publish to channel) // in a /server/rpc file ss.publish.channel('disney', 'chatMessage', {from: 'jerry', message: 'Has anyone seen Tom?'}); Client (receive channel message) // in a /client/code file ss.event.on('chatMessage', function(msg, channelName){ console.log('The following message was sent to the ' + channelName + ' channel:', msg); });
  • 131. 3 - Sending to users Server // in a /server/rpc file ss.publish.user('fred', 'specialOffer', 'Here is a special offer just for you!');
  • 132. 4 - Sending to a browser tab Server // in a /server/rpc file ss.publish.socketId('254987654324567', 'justForMe', 'Just for one tab');
  • 133. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 134. On top of RPC and PubSub, SocketStream provides you with a way to create custom request responders
  • 135. Request Response is basically a WebSocket message handler
  • 136. It allows you to write message handling for games, where every byte matters
  • 137. HTML / CSS / JS code preprocessing Minifying CSS/JS for production use Client-side code organisation HTML Templates WebSocket Management Live Reload Building RPC APIs Building PubSub APIs Session Management Building custom APIs on top of WS Web Workers Connect middleware compatibility
  • 139. They are mangled by mobile networks…
  • 141. Routed to dead ends by proxy servers
  • 142. And severed by train tunnels
  • 143. Also, browser support for WebSockets isn’t guaranteed
  • 144. You need a transport strategy
  • 146. But Socket.io asserted that if a browser supported WebSockets, then it would work
  • 147. They learned from this, by building Engine.io
  • 148. I created the transport wrapper for Engine.io in SocketStream for Bechtel & Dashku
  • 149. And designed it to reconnect the client when severed
  • 150. Months later, it made it’s way into SocketStream’s core.
  • 151. SocketStream let’s you use this, alongside SockJS
  • 152. …and that is SocketStream in a nutshell. Whew!
  • 153. Let’s look at some SocketStream apps in the wild
  • 162. 1 - Check your server’s ulimit configuration (This can bite you hard)
  • 163. I learned this when Dashku went #1 on Hacker News in 45min
  • 164. 2 - Use HTTPS, but handle it at the load balancer level rather than at the app level
  • 165. HTTPS helps to improve the stability of WebSocket connections, especially on mobile devices
  • 166. But Node’s HTTPS implementation is noticeably slower than using HAProxy or Nginx
  • 168. We’re in the process of getting SocketStream’s test coverage up
  • 169. We’re also trying to close some ancient bugs
  • 170. We also need better documentation
  • 171. We’re giving the web site an overhaul
  • 172. And we want to document how SocketStream’s internals function, to help build 0.4
  • 173. but what about 0.4?
  • 174. …0.4 is starting to look like these:
  • 175. I promise you all, it’s coming in June 2014