← All projects

Rumbrella

The completed project from the book Programming Phoenix: an Elixir umbrella with Rumbl, a Phoenix app for annotating YouTube videos together in real time, and InfoSys, an OTP app that answers annotations with Wolfram Alpha.

A dark code card of rumbrella/apps/rumbl/web/channels/video_channel.ex, lines 28 to 45: handle_in for new_annotation builds an annotation for the user and the socket's video, inserts it with Repo.insert, and on success broadcasts it, starts a Task to compute additional info and replies ok, or replies with the changeset errors.
Handling a new annotation in Rumbl's video channel, rendered from apps/rumbl/web/channels/video_channel.ex.

Rumbrella is the finished tutorial project from Programming Phoenix, the book by Chris McCord, Bruce Tate and José Valim. The design is the book’s. The repository’s single commit, from November 27, 2016, is titled “Programming Phoenix Completed Project”, and its database migrations were generated on November 26 and 27.

It’s an Elixir umbrella project with two applications:

  • Rumbl, a Phoenix app where people sign up, add YouTube videos and annotate them while they watch. Each annotation is pinned to a moment in the video and shows up for every viewer in real time.
  • InfoSys, an OTP application that sends a question to outside services and returns the best answers. Its one backend is Wolfram Alpha.

The two meet in the video channel. Every new annotation also goes to InfoSys, and if Wolfram Alpha has an answer, it’s posted on the video as an annotation from a user named “wolfram”.

Rumbl

Users register with a username and a password hashed with bcrypt, log in with a session, and manage their videos under /manage, which requires a login. A video has a URL, title, description and category, and a slug, so its watch page lives at an address like /watch/12-my-video.

The watch page embeds the video with YouTube’s IFrame API next to an annotations panel. Posting a comment sends it over a Phoenix channel with the player’s current time, and the server saves it with Ecto and PostgreSQL and broadcasts it to everyone watching. When you open a video, the channel sends its saved annotations and the page plays them back in step with the video, each one appearing when playback reaches its time. Clicking an annotation seeks to that moment, and after a reconnect the channel only sends annotations newer than the last one seen.

A code card of video_channel.ex, lines 47 to 68: broadcast_annotation preloads the user, renders annotation.json and broadcasts new_annotation. compute_additional_info runs InfoSys.compute on the annotation body with limit 1 and a 10_000 timeout, then inserts each result as an annotation from the user named after the backend and broadcasts it.
Broadcasting an annotation, and turning an InfoSys answer into an annotation from the backend's own user.

InfoSys

InfoSys.compute starts one process per backend under a simple_one_for_one supervisor, monitors each, and waits up to a timeout (10 seconds by default) before killing any that haven’t answered. The results come back sorted by score. The Wolfram backend sends the query to the Wolfram Alpha v2 API and pulls the “Result” or “Definitions” text out of the XML with SweetXml. Its tests swap in a local HTTP client that answers 1 + 1 with a recorded XML fixture, so they run without the network or a real app ID.

How it’s built

Rumbl uses Phoenix 1.2 with Phoenix channels over WebSockets, Ecto through phoenix_ecto 3 with Postgrex, Comeonin 2 for bcrypt, and Brunch 2.7 with Babel for the JavaScript. InfoSys depends only on SweetXml. Each app has its own config and tests, and the umbrella shares one build folder, deps folder and lockfile. Rumbl also keeps a small Counter GenServer that counts down once a second and raises “boom!” at zero. Nothing else in the app uses it.

The creation date shown here is the GitHub repository’s UTC creation date. The images are code cards rendered from the repository’s source files, with their real line numbers.

Keyboard shortcuts

Shortcuts stay out of text fields. Extra shortcuts are off until you enable them on this device. Ctrl or Command K is always available.

?
Open this help
Ctrl / ⌘ K
Open site search
Alt A
Browse articles
Alt R
Open your reading list
Alt T
Browse topics
Escape
Close dialogs or leave article focus mode