Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SocketStream NYCCamp 2015

SocketStream NYCCamp 2015

The slides from the presentation about SocketStream at NYCCamp 2015

Paul Jensen

July 17, 2015
Tweet

More Decks by Paul Jensen

Other Decks in Technology

Transcript

  1. SocketStream • Created by Owen Barnes back in 2011 •

    Built on Node.js • Geared towards building Single Page Applications • Uses WebSockets to transmit data between the client and the server
  2. SocketStream • Used to build apps as opposed to sites

    • Current apps in the wild include chat apps, games, dashboards, line of business applications, financial trading platforms
  3. Peter Lubbers Senior Program Manager, Scalable Developer Programs at Google

    Formerly at Kaazing Author of “Pro HTML5 Programming” by APress …and he owns that numberplate!
  4. The next day, at the company hack- day they create

    a WebSockets API that powers a web traffic tool
  5. They think it’s cool, work on it more over the

    next couple of months, and turn it into a company
  6. My boss (Owen Barnes) attends Peter’s training event at Skills

    Matter in London, UK (same event, 1year on)
  7. – Owen Barnes “What would happen if we sent all

    of the data your app needs over a WebSocket?”
  8. RPC

  9. RPC • This is a request/response API over WebSockets •

    We use it to send data from the client to the server, and have the server send back a response • Useful for handling data sent from the web app, that needs to be validated or verified as having been received
  10. RPC • From the client, demo.sendMessage calls the sendMessage function

    in the server/rpc/demo.js file. • This convention allows you to structure the RPC API that you want in line with your files, so they are easy to create, find and modify. • It is one of the “opinions” of the framework
  11. Pub/Sub • A publish/subscribe API over WebSockets • The server

    does the publish/subscribe actions, and the client listens for events • Commonly used for public and private communications (.e.g chat rooms, activity feeds, announcements, events in games)
  12. Pub/Sub • That example broadcasts to all browsers, but Pub/

    Sub also supports sending to: • Private channels • A specific user • Even a single browser tab
  13. Pub/Sub • SocketStream supports Pub/Sub through 2 methods - internally

    within the Node.js process with EventEmitter (simple to start with, but means you lose channel subscriptions when the process is restarted • For that reason, SocketStream has a Pub/Sub plugin that uses Redis to persist the channels and subscriptions • There is even a 3rd-party Pub/Sub plugin using MongoDB to persist the data
  14. Pub/Sub - app patterns • If you have a need

    for authenticated channels, implement an authentication method via RPC, and create a subscription with a channel name unique for that user, if the authentication succeeds • Always use Redis for Pub/Sub persistence when in staging/production modes • It’s a good idea to design the app so that channel subscriptions are kept at a minimum.
  15. Code Stores the client-side Javascript files CSS Stores the Cascading

    Style Sheets Static Stores any assets that need to be served statically (images, favicon.ico, fonts)
  16. Templates Stores the client-side HTML templates that are rendered on

    the client Views Stores the HTML page that is sent to the browser from the server
  17. HTML Templates are loaded by the app based on their

    location in the templates folder
  18. Henrik (a contributor) has been working on the bundler, making

    it pluggable, so it can support using tools like WebPack and JSPM
  19. We support the following transpilers HTML CSS JS Jade EJS

    CoffeeKup RActive Handlebars Toffee JSX Stylus Less Scss Sass CoffeeScript IcedCoffeeScript TypeScript LiveScript GorillaScript
  20. We do this so that the Single Page App consists

    of just 1 JS file, 1 CSS file, 1 HTML file, the favicon, and the WebSocket connection (excluding images/other static assets)
  21. There are more features… • Use either Engine.io or SockJS

    for the WebSocket transport
 • Load an Express app with SocketStream, and share Cookie information
 • Create your own WebSocket responder protocols (for ultra-efficient communication - e.g. game data) • Use Web Workers for doing intensive processing in non-blocking threads in the browser
  22. There are more features… • Reconnect WebSockets that die (due

    to train tunnels and general lack of Internet connectivity) • There are some neat 3rd-party plugins for integrating with Backbone and Angular applications
 • We also have a tool for testing your web apps with Cucumber and Selenium, called SS-cucumber
  23. if I try to run through them then all we’re

    going to miss Lunch… See socketstream.com for more details on those features
  24. I have met 2 people who I would call “Ninja

    coders”, and Owen is one of them
  25. Do 2 things: 1 - Get a code coverage tool

    2 - Read the code 3 - Write tests
  26. Code coverage tools • Istanbul, from Krishnan Anantheswaran at Yahoo!

    • https://github.com/gotwarlost/istanbul • Let’s you check what code is covered by tests • Gives you colourful reports that highlight the weak areas of your codebase
  27. Read the code • Joel Spolsky once said that people

    find reading code hard • The source code was written in CoffeeScript • I converted it by hand to JavaScript, and ported the code comments over
  28. Write the tests • Myself, Roman Minkin, and Henrik Vendelbo

    have been chipping away at writing tests for the framework for some time • The framework’s code coverage is now at 76% • We still have some way to go, but we’re getting there
  29. And when work on 0.4 became stagnant, it lead people

    to question whether the framework was dead
  30. When I became the new lead developer, I originally wanted

    to maintain both the current 0.3 branch, and then launch 0.4 by June 2014
  31. It didn’t happen. In the end I chose to focus

    on 0.3 and cancel the 0.4 branch
  32. It was not the easiest thing to do, but it

    made things better in the long run
  33. Scaling • At the moment, scaling requires a load balancer

    with session affinity enabled to make sure that long-polling handshakes go to the right servers • We want to explore an approach that doesn’t depend on session affinity
  34. Test Coverage • As mentioned earlier, we want to get

    to as close to 100% as is reasonable (currently at 76%) • Once we’re there, we can have confidence in refactoring whole swathes of the codebase.
  35. Removing sync calls • There are some synchronous calls in

    the codebase (mainly around file reading/app generation) • We want to remove all of them
  36. Making the codebase modular • We’ve started to breakout SocketStream’s

    functionality into modules • This has the benefit of making the codebase easier to look through, test, and refactor • App generation was the first part of the code to break out into a module
  37. Hybrid app support • Single Page Apps are not good

    for SEO • React has become a very popular tool • We’re looking to improve support for building hybrid apps (server-side rendering + client-side rendering) - which currently exists with React and Flux
  38. Looking for a new sponsor • At the very start

    of the project, AOL allowed Owen to work on SocketStream full time • But it meant he longer ran the Ad Ops team, who were merged into another team • The change along with company re-orgs ended up stifling momentum on the project
  39. Looking for a new sponsor • Last year, I became

    a consultant, and managed to sponsor work on SocketStream through Anephenix (my company) • But ultimately, I am 1 person, and there is only so much I can support by myself • We’re looking for a sponsor
  40. I felt like I had to prove that I wasn’t

    a bad developer I had to build something
  41. I spend every day for 2 months working on this

    app, and then I post it to Hacker News
  42. I also meet with a Dashboard company in London, and

    try to sell the app to them (without success)
  43. I finally get a job in London, decide to focus

    hard on it, and open source Dashku
  44. What happens next • I get contacted by a Indian

    Health startup, who want me to work for them to extend Dashku for their products • I get a free Ninja Block from the guys at Ninja Blocks, who ask me to work for them • Dashku gets ripped off by tazaboard.com • Another IoT company asks to use it for their product