Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building Real-Time Applications in Ember.js
Search
Steve Kinney
March 04, 2015
Technology
0
120
Building Real-Time Applications in Ember.js
Steve Kinney
March 04, 2015
Tweet
Share
More Decks by Steve Kinney
See All by Steve Kinney
Introduction to Testing
stevekinney
0
130
Web Security, Frontend Masters
stevekinney
0
3.3k
Making Music with the Web Audio API, JSConf Colombia 2023
stevekinney
0
110
React and TypeScript, Turing School
stevekinney
0
350
Redux Workshop, 2021-05-05
stevekinney
2
2.2k
TypeScript and React Utility Types
stevekinney
1
200
A Gentle Introduction to GraphQL Resolvers
stevekinney
1
170
React State
stevekinney
11
10k
React State: useEffect and Custom Hooks
stevekinney
0
250
Other Decks in Technology
See All in Technology
Zephyr RTOS の発表をOpen Source Summit Japan 2025で行った件
iotengineer22
0
280
一番人に近いコードレビューア CodeRabbit
kinopeee
0
110
Git Training GitHub
yuhattor
1
270
SMTP完全に理解した ✉️
yamatai1212
0
110
OCI技術資料 : OS管理ハブ 概要
ocise
2
4.3k
ビジュアルプログラミングIoTLT vol.22
1ftseabass
PRO
0
140
ファシリテーション勉強中 その場に何が求められるかを考えるようになるまで / 20260123 Naoki Takahashi
shift_evolve
PRO
3
390
Security Hub と出会ってから 1年半が過ぎました
rch850
0
190
新規事業 toitta におけるAI 機能評価の話 / AI Feature Evaluation in toitta
pokutuna
0
280
メルカリのAI活用を支えるAIセキュリティ
s3h
7
4.7k
ドメイン駆動セキュリティへの道しるべ
pandayumi
0
180
ReproでのicebergのStreaming Writeの検証と実運用にむけた取り組み
joker1007
0
490
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
57
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
110
Information Architects: The Missing Link in Design Systems
soysaucechin
0
750
Designing Experiences People Love
moore
144
24k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Claude Code のすすめ
schroneko
67
210k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
50
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
280
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Become a Pro
speakerdeck
PRO
31
5.8k
Transcript
Building Real-Time Applications in Ember EmberConf 2015
Hi. I'm Steve. @stevekinney |
[email protected]
None
None
Let's talk about building real-time applications with Ember.
This is a story about WebSockets…
It's also a story about integrating all sorts of browser
functionality and third-party code into our applications.
What even is a WebSocket?
WebSockets are an HTTP independent, bi-directional, TCP-based protocol over port
80 standardized in 2011 by the IETF as RFC 6455.
Duh.
None
What are WebSockets used for?
Quick Demo
Can I actually use WebSockets?
None
None
Now, that we know everything there is to know about
WebSockets, let’s get to implementing them.
None
None
Step Zero: We need a WebSocket server, right?
A WebSocket server in fourteen lines.
var WebSocketServer = require('ws').Server; var socket = new WebSocketServer({ port:
8080 }); socket.on('connection', function(connection) { connection.on('message', function(message) { socket.broadcast(message); }); }); socket.broadcast = function(data) { this.clients.forEach(function (client) { client.send(data); }); };
What does this look like on the client?
A Traditional Example var socket = io(); $('form').submit(function(){ socket.emit('chat message',
$('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li>').text(msg)); });
Ugh. DOM/selector- based development. #fail
—Erik Bryn “Selector-based programming”
We can do better.
Let's try two or three different approaches.
Approach #1: A standalone controller
ember generate controller websocket
app/controllers/ websocket.js
None
None
None
None
None
None
None
None
None
None
app/controllers/ chatroom.js
None
None
None
None
None
None
None
app/routes/ chatroom.js
None
None
Quick Demo
This approach works great, but it's somewhat limited.
None
Approach #2: Dependency Injection with Services
ember generate service websocket
installing create app/services/websocket.js create app/initializers/websocket.js
app/initializers/ websocket.js
None
None
None
None
None
Let's move that code from the controller into our service.
rm -rf app/controllers/websocket.js
app/controllers/ chatroom.js
None
None
That's it.
Approach #3: Using Socket.io
Point of Interest: Socket.io is both a server- and client-
side library.
To each her own.
Let's set up a Socket.io server
None
None
bower install sio-client
None
app/services/ websocket.js
None
app/controllers/ chatroom.js
None
None
Thank you. Code example: stevekinney/emberconf-chat Twitter and Github: @stevekinney Email:
[email protected]
Hire our students: http://people.turing.io/