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
Building Real-Time Applications in Ember.js
Steve Kinney
March 04, 2015
More Decks by Steve Kinney
See All by Steve Kinney
React_Performance__2022.pdf
stevekinney
0
28
React Performance v2
stevekinney
0
34
Introduction to Testing
stevekinney
0
150
Web Security, Frontend Masters
stevekinney
0
3.8k
Making Music with the Web Audio API, JSConf Colombia 2023
stevekinney
0
120
React and TypeScript, Turing School
stevekinney
0
370
Redux Workshop, 2021-05-05
stevekinney
2
2.2k
TypeScript and React Utility Types
stevekinney
1
220
A Gentle Introduction to GraphQL Resolvers
stevekinney
1
170
Other Decks in Technology
See All in Technology
自称宇宙最速で不合格となったAIP-C01にリベンジを果たすべくAIで問題集アプリを作ってみた。
yama3133
0
220
Don't Just Patch — MOTTAINAI! Learn Security from Laravel CVE Diffs
codmoninc
0
140
イベントで大活躍する電子ペーパー名札 〜その3〜 / ビジュアルプログラミングIoTLT vol.23
you
PRO
0
160
AI時代から振り返るTerraform drift運用の歴史 / AI Age Reflections on the History of Terraform Drift Operations
aeonpeople
0
540
DI コンテナ自動生成ツールを実装してみた / intro-autodi
uhzz
0
870
AI駆動開発でなんでもハンズオン環境をつくってみた
yoshimi0227
0
160
はじめてのDatadog
kairim0
0
140
類似画像検索モデルの開発ノウハウ
lycorptech_jp
PRO
4
990
RubyでRuby拡張を書いたらRubyより35倍速になったってどういうこと??
kazuho
3
660
AI時代に改めて考える、ドメイン駆動設計 - モデリングが「AIへの共通言語」になる
littlehands
8
2.7k
個人AIからチームAIへ:開発における品質と生産性の再設計
moongift
PRO
0
250
layerx-fde-practices
cipepser
6
2.8k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
24k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Building an army of robots
kneath
306
46k
エンジニアに許された特別な時間の終わり
watany
107
240k
Designing Experiences People Love
moore
143
24k
We Are The Robots
honzajavorek
0
230
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
310
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
270
Skip the Path - Find Your Career Trail
mkilby
1
130
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/