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
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
180
React_Performance__2022.pdf
stevekinney
0
43
React Performance v2
stevekinney
0
62
Introduction to Testing
stevekinney
0
180
Web Security, Frontend Masters
stevekinney
0
4.1k
Making Music with the Web Audio API, JSConf Colombia 2023
stevekinney
0
130
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
平文パスワードはログに“残り” ── 肝心の侵入は“痕跡すら残らない”
kuroneko13
0
110
AI・HPC開発を支えるGPU環境の新しい選択肢 液冷GPUシステム「AquSys」の取り組み
gpuunite_official
0
170
関東Kaggler会発表資料
takoi
1
280
英語が話せなくてもKubeConスタッフに参加した話
yusuke427
1
1.1k
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
290
Rust×eBPFでEDRっぽいものをつくる
sunlife3
2
690
AI for Science時代を切り開く、政府の次世代HPC戦略の展望
gpuunite_official
0
150
[potatotips #96] Give Your AI Agent the Flutter Playbook
korodroid
0
130
Kiro入門|仕様駆動開発で変わるAI時代の開発スタイル
cmkudo
0
290
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
LanceDB入門
mocobeta
9
660
ホームラボ紹介
y_sera15
0
220
Featured
See All Featured
Between Models and Reality
mayunak
4
400
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
470
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
380
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Site-Speed That Sticks
csswizardry
13
1.5k
Done Done
chrislema
186
16k
A Soul's Torment
seathinner
6
3.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
How to make the Groovebox
asonas
2
2.3k
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/