Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Building Real-Time Applications in Ember.js
Search
Steve Kinney
March 04, 2015
Technology
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Building Real-Time Applications in Ember.js
Steve Kinney
March 04, 2015
More Decks by Steve Kinney
See All by Steve Kinney
Enterprise UI, v2
stevekinney
0
300
React_Performance__2022.pdf
stevekinney
0
51
React Performance v2
stevekinney
0
87
Introduction to Testing
stevekinney
0
200
Web Security, Frontend Masters
stevekinney
0
4.5k
Making Music with the Web Audio API, JSConf Colombia 2023
stevekinney
0
140
React and TypeScript, Turing School
stevekinney
0
390
Redux Workshop, 2021-05-05
stevekinney
2
2.2k
TypeScript and React Utility Types
stevekinney
1
230
Other Decks in Technology
See All in Technology
AI時代のGraphQL
joere
1
290
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
130
Local CI × GitHub Actions
gogutan
3
260
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
210
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
220
Let's Change Our World—Again
snoozer05
PRO
3
260
Codex を使った障害対応机上演習の実際
orgachem
PRO
0
220
その Valkey 使いこなしていますか?
onk
PRO
5
1.8k
会社説明資料
persolserverworks
0
9.8k
LLM Content Moderationを支える評価・改善ループの実践
suikabar
2
260
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
PRO
0
450
CTO Night|NotionのAIエージェントとFDE
kzkhykw1991
0
300
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
530
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Designing for humans not robots
tammielis
254
26k
Site-Speed That Sticks
csswizardry
13
1.6k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
59k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
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/