SlideShare a Scribd company logo
Kuba Niechcial
ember-socket-guru - common API for
websockets providers
Introduction
Who am I?
Kuba Niechcial
Senior Tech Leader @ Netguru
Leading 25 frontends and 50 backends
What have we built?
Netguru’s Ember Team
eslint-plugin-ember ember-socket-guru ember-cli-deploy-rollbar
10+ Ember.js blogposts
WIP
ember-multi-language capistrano-ember_cli
The problem
ember-socket-guru
What is the problem?
The problem
ember-socket-guru
Each WebSockets provider has different API for the same
(or basically the same) set of features.
It is a common use case to start with SaaS and eventually
migrate to custom infrastructure.
The solution
ember-socket-guru
What is the solution?
Built mostly by @jacek_bandura, our senior developer
How to use it?
How to use it?
Shared Socket Service
1. import SocketGuruService from 'ember-socket-guru/services/socket-guru';
2.
3. export default SocketGuruService.extend({
4. socketClient: 'pusher', // might be also ActionCable, Socket.IO or Phoenix - API stays the same
5. config: { // obligatory config that is adapter-based, different for each provider
6. pusherKey: 'PUSHER_KEY',
7. },
8. observedChannels: { // common structure that defines what channels should we subscribe to and what events listen to
9. channel1: ['event1'],
10. },
11. });
Configure shared service
Socket.io does not have channels abstraction. In this case observedChannels is a flat array of events.
How to use it?
Shared mixin for objects
1. import Ember from 'ember';
2. import SocketEventHandler from 'ember-socket-guru/mixins/socket-event-handler';
3.
4. const { Route } = Ember;
5.
6. export default Route.extend(SocketEventHandler, {
7. socketActions: {
8. onEvent1(data) { // handle events based on its name onEVENT_NAME
9. // handle event1
10. },
11. },
12.
13. onSocketAction(eventName, eventData) { // handler for all events - not obligatory
14. // handle all events, including event1
15. },
16. });
Shared mixin for objects
How does it work?
How does it work?
Adapter pattern
ActionCable Socket.ioPusher Phoenix
setup subscribe unsubscribe disconnect
emit
How does it work?
Setup
1. setup(config, eventHandler) {
2. const PusherService = get(this, 'pusherService');
3. this._checkConfig(config); // internal custom implementation for config check in Pusher
4. setProperties(this, {
5. eventHandler,
6. socket: new PusherService(get(config, 'pusherKey'), config),
7. });
8.
9. get(this, 'socket').connection
10. .bind('connected', () => this._handleConnected()); // use Pusher API to connect to Pusher servers
11. },
Example setup code in Pusher adapter
How does it work?
Subscribe
1. subscribe(observedChannels) {
2. Object.keys(observedChannels).forEach((channelName) => {
3. const channel = get(this, 'socket').subscribe(channelName); // usage of Pusher API to subscribe to channel
4. const joinedChannels = get(this, 'joinedChannels');
5. set(this, 'joinedChannels', Object.assign({}, joinedChannels, {
6. [channelName]: channel,
7. }));
8. observedChannels[channelName].forEach((event) => {
9. channel.bind(event, (data) => { // usage of Pusher API to bind for events
10. run(() => get(this, 'eventHandler')(event, data));
11. });
12. });
13. });
14. },
Example subscribe code in Pusher adapter
How does it work?
Emit
1. emit(channelName, eventName, eventData) {
2. const channel = get(this, `joinedChannels.${channelName}`);
3. if (!channel) { // make guard clauses to make sure that Pusher API can be used
4. return warn(
5. `[ember-socket-guru] You need to join channel ${channelName} before pushing events!`,
6. channel,
7. { id: 'ember-socket-guru.channel-not-joined' }
8. );
9. }
10. channel.push(eventName, eventData); // again, use Pusher API to emit the event
11. },
Example emit code in Pusher adapter
Summary
What it gives?
Adapter approach that allows us to use multiple
WebSockets providers with one common API.
Summary
Tech insights
Reliable TestedConventional
It works. It’s tested.Introduce
convention for
websockets.
Summary
Non-tech insights
Solves real
problem
Landing page
that you trust
Good,
dedicated
docs
Thanks!
https://github.com/netguru/ember-socket-guru
@jakubniechcial

More Related Content

What's hot (20)

PPTX
Asynchronous Task Queues with Celery
Kishor Kumar
 
PPTX
Automating Windows Azure
Ido Flatow
 
PDF
Burrow in basel
Rachel Davison
 
PDF
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
KEY
Socket.io
Timothy Fitz
 
PDF
Socket.IO
Arnout Kazemier
 
PDF
Migrating to Openshift - Reyhan Fabianto
DevOpsDaysJKT
 
PDF
iscsid remains stopped in redhat EL 6
Ashwin Pawar
 
KEY
Django Celery
Mat Clayton
 
PDF
Going realtime with Socket.IO
Christian Joudrey
 
PDF
Big Master Data PHP BLT #1
Masahiro Nagano
 
PDF
How To Connect Amazon AWS EC2 with Key Pair – Linux
VCP Muthukrishna
 
PDF
Resources and providers chef conf 2013
rosekolodny
 
PDF
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
PDF
ReactJS & Material-ui Hello world
Daniel Lim
 
KEY
JRuby最新事情@札幌
Naoto Takai
 
PDF
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
mfrancis
 
PDF
Socket.io (part 1)
Andrea Tarquini
 
RTF
Database sql-mirroring
ARUN SUNDAR B
 
PDF
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
Asynchronous Task Queues with Celery
Kishor Kumar
 
Automating Windows Azure
Ido Flatow
 
Burrow in basel
Rachel Davison
 
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
Socket.io
Timothy Fitz
 
Socket.IO
Arnout Kazemier
 
Migrating to Openshift - Reyhan Fabianto
DevOpsDaysJKT
 
iscsid remains stopped in redhat EL 6
Ashwin Pawar
 
Django Celery
Mat Clayton
 
Going realtime with Socket.IO
Christian Joudrey
 
Big Master Data PHP BLT #1
Masahiro Nagano
 
How To Connect Amazon AWS EC2 with Key Pair – Linux
VCP Muthukrishna
 
Resources and providers chef conf 2013
rosekolodny
 
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
ReactJS & Material-ui Hello world
Daniel Lim
 
JRuby最新事情@札幌
Naoto Takai
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
mfrancis
 
Socket.io (part 1)
Andrea Tarquini
 
Database sql-mirroring
ARUN SUNDAR B
 
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 

Similar to ember-socket-guru - common api for websockets providers (20)

PDF
Express node js
Yashprit Singh
 
PPT
RESTful API In Node Js using Express
Jeetendra singh
 
PDF
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
Matt Raible
 
PDF
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
PPTX
Protractor framework architecture with example
shadabgilani
 
PPTX
Let's play with adf 3.0
Eugenio Romano
 
PPTX
Das kannste schon so machen
André Goliath
 
PDF
How to use Cypress Intercept to Stub API Responses.pdf
Steve Wortham
 
PDF
NestJS
Wilson Su
 
PDF
SCR Annotations for Fun and Profit
Mike Pfaff
 
PDF
Pixels_Camp
Nelson Gomes
 
PDF
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
PDF
Writing & Sharing Great Modules - Puppet Camp Boston
Puppet
 
PPT
Java util concurrent
Roger Xia
 
PDF
Ch ch-changes cake php2
markstory
 
KEY
Multi Client Development with Spring
Joshua Long
 
PDF
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
PPTX
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
PPTX
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
 
PDF
Build Web Apps using Node.js
davidchubbs
 
Express node js
Yashprit Singh
 
RESTful API In Node Js using Express
Jeetendra singh
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
Matt Raible
 
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
Protractor framework architecture with example
shadabgilani
 
Let's play with adf 3.0
Eugenio Romano
 
Das kannste schon so machen
André Goliath
 
How to use Cypress Intercept to Stub API Responses.pdf
Steve Wortham
 
NestJS
Wilson Su
 
SCR Annotations for Fun and Profit
Mike Pfaff
 
Pixels_Camp
Nelson Gomes
 
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
Writing & Sharing Great Modules - Puppet Camp Boston
Puppet
 
Java util concurrent
Roger Xia
 
Ch ch-changes cake php2
markstory
 
Multi Client Development with Spring
Joshua Long
 
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
 
Build Web Apps using Node.js
davidchubbs
 
Ad

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in Network Security & Its Applications.pdf
IJNSA Journal
 
PDF
Non Text Magic Studio Magic Design for Presentations L&P.pdf
rajpal7872
 
PDF
BEE331-Week 04-SU25.pdf semiconductors UW
faemoxley
 
PDF
NOISE CONTROL ppt - SHRESTH SUDHIR KOKNE
SHRESTHKOKNE
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
PPTX
Fluid statistics and Numerical on pascal law
Ravindra Kolhe
 
PPTX
00-ClimateChangeImpactCIAProcess_PPTon23.12.2024-ByDr.VijayanGurumurthyIyer1....
praz3
 
PDF
Natural Language processing and web deigning notes
AnithaSakthivel3
 
PPTX
Mining Presentation Underground - Copy.pptx
patallenmoore
 
PPTX
drones for disaster prevention response.pptx
NawrasShatnawi1
 
PPTX
waterconservation-211128055737.pptx Jaswanth
SandulaAnilBabu
 
PPTX
Abstract Data Types (ADTs) in Data Structures
mwaslam2303
 
PDF
SMART HOME AUTOMATION PPT BY - SHRESTH SUDHIR KOKNE
SHRESTHKOKNE
 
PPTX
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
PPTX
Dolphin_Conservation_AI_txhasvssbxbanvgdghng
jeeaspirant2026fr
 
PDF
MRI Tool Kit E2I0500BC Plus Presentation
Ing. Ph. J. Daum GmbH & Co. KG
 
PDF
13th International Conference of Networks and Communications (NC 2025)
JohannesPaulides
 
PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PPTX
Cyclic_Redundancy_Check_Presentation.pptx
alhjranyblalhmwdbdal
 
July 2025 - Top 10 Read Articles in Network Security & Its Applications.pdf
IJNSA Journal
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
rajpal7872
 
BEE331-Week 04-SU25.pdf semiconductors UW
faemoxley
 
NOISE CONTROL ppt - SHRESTH SUDHIR KOKNE
SHRESTHKOKNE
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
Fluid statistics and Numerical on pascal law
Ravindra Kolhe
 
00-ClimateChangeImpactCIAProcess_PPTon23.12.2024-ByDr.VijayanGurumurthyIyer1....
praz3
 
Natural Language processing and web deigning notes
AnithaSakthivel3
 
Mining Presentation Underground - Copy.pptx
patallenmoore
 
drones for disaster prevention response.pptx
NawrasShatnawi1
 
waterconservation-211128055737.pptx Jaswanth
SandulaAnilBabu
 
Abstract Data Types (ADTs) in Data Structures
mwaslam2303
 
SMART HOME AUTOMATION PPT BY - SHRESTH SUDHIR KOKNE
SHRESTHKOKNE
 
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
Dolphin_Conservation_AI_txhasvssbxbanvgdghng
jeeaspirant2026fr
 
MRI Tool Kit E2I0500BC Plus Presentation
Ing. Ph. J. Daum GmbH & Co. KG
 
13th International Conference of Networks and Communications (NC 2025)
JohannesPaulides
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
Cyclic_Redundancy_Check_Presentation.pptx
alhjranyblalhmwdbdal
 
Ad

ember-socket-guru - common api for websockets providers

  • 1. Kuba Niechcial ember-socket-guru - common API for websockets providers
  • 2. Introduction Who am I? Kuba Niechcial Senior Tech Leader @ Netguru Leading 25 frontends and 50 backends
  • 3. What have we built? Netguru’s Ember Team eslint-plugin-ember ember-socket-guru ember-cli-deploy-rollbar 10+ Ember.js blogposts WIP ember-multi-language capistrano-ember_cli
  • 5. The problem ember-socket-guru Each WebSockets provider has different API for the same (or basically the same) set of features. It is a common use case to start with SaaS and eventually migrate to custom infrastructure.
  • 6. The solution ember-socket-guru What is the solution? Built mostly by @jacek_bandura, our senior developer
  • 8. How to use it? Shared Socket Service 1. import SocketGuruService from 'ember-socket-guru/services/socket-guru'; 2. 3. export default SocketGuruService.extend({ 4. socketClient: 'pusher', // might be also ActionCable, Socket.IO or Phoenix - API stays the same 5. config: { // obligatory config that is adapter-based, different for each provider 6. pusherKey: 'PUSHER_KEY', 7. }, 8. observedChannels: { // common structure that defines what channels should we subscribe to and what events listen to 9. channel1: ['event1'], 10. }, 11. }); Configure shared service Socket.io does not have channels abstraction. In this case observedChannels is a flat array of events.
  • 9. How to use it? Shared mixin for objects 1. import Ember from 'ember'; 2. import SocketEventHandler from 'ember-socket-guru/mixins/socket-event-handler'; 3. 4. const { Route } = Ember; 5. 6. export default Route.extend(SocketEventHandler, { 7. socketActions: { 8. onEvent1(data) { // handle events based on its name onEVENT_NAME 9. // handle event1 10. }, 11. }, 12. 13. onSocketAction(eventName, eventData) { // handler for all events - not obligatory 14. // handle all events, including event1 15. }, 16. }); Shared mixin for objects
  • 10. How does it work?
  • 11. How does it work? Adapter pattern ActionCable Socket.ioPusher Phoenix setup subscribe unsubscribe disconnect emit
  • 12. How does it work? Setup 1. setup(config, eventHandler) { 2. const PusherService = get(this, 'pusherService'); 3. this._checkConfig(config); // internal custom implementation for config check in Pusher 4. setProperties(this, { 5. eventHandler, 6. socket: new PusherService(get(config, 'pusherKey'), config), 7. }); 8. 9. get(this, 'socket').connection 10. .bind('connected', () => this._handleConnected()); // use Pusher API to connect to Pusher servers 11. }, Example setup code in Pusher adapter
  • 13. How does it work? Subscribe 1. subscribe(observedChannels) { 2. Object.keys(observedChannels).forEach((channelName) => { 3. const channel = get(this, 'socket').subscribe(channelName); // usage of Pusher API to subscribe to channel 4. const joinedChannels = get(this, 'joinedChannels'); 5. set(this, 'joinedChannels', Object.assign({}, joinedChannels, { 6. [channelName]: channel, 7. })); 8. observedChannels[channelName].forEach((event) => { 9. channel.bind(event, (data) => { // usage of Pusher API to bind for events 10. run(() => get(this, 'eventHandler')(event, data)); 11. }); 12. }); 13. }); 14. }, Example subscribe code in Pusher adapter
  • 14. How does it work? Emit 1. emit(channelName, eventName, eventData) { 2. const channel = get(this, `joinedChannels.${channelName}`); 3. if (!channel) { // make guard clauses to make sure that Pusher API can be used 4. return warn( 5. `[ember-socket-guru] You need to join channel ${channelName} before pushing events!`, 6. channel, 7. { id: 'ember-socket-guru.channel-not-joined' } 8. ); 9. } 10. channel.push(eventName, eventData); // again, use Pusher API to emit the event 11. }, Example emit code in Pusher adapter
  • 15. Summary What it gives? Adapter approach that allows us to use multiple WebSockets providers with one common API.
  • 16. Summary Tech insights Reliable TestedConventional It works. It’s tested.Introduce convention for websockets.
  • 17. Summary Non-tech insights Solves real problem Landing page that you trust Good, dedicated docs