Twitch Onebox for Discourse

(Daniel Marquard) #1

Discourse Twitch Onebox

This plugin for Discourse extends Onebox to add support for properly embedding Twitch streams and videos in Discourse posts. Videos embed as protocol-relative (to work around a Onebox limitation) and with auto-play disabled.


See it in action and test it out for yourself on Crit Cola’s Discourse.


Add the plugin’s repository URL to your container’s app.yml file, for example:

    - exec:
        cd: $home/plugins
          - mkdir -p plugins
          - git clone

Rebuild the container:

cd /var/discourse
./launcher rebuild app

For the plugin to apply retroactively, you’ll need to rebake old posts:

cd /var/discourse
./launcher enter app
rake posts:rebake


The Discourse Twitch Onebox plugin is released under the MIT License.

Onebox doesn't prefer secure_url with HTTPS
Twitch embeds are small and shouldn't auto-play
(Régis Hanol) #2

I wonder why did you make a plugin rather than submitting a PR to the onebox repository?

(Daniel Marquard) #3

I didn’t consider it, only because the modules I saw on that repo seemed like they were fairly complex, whereas this and my other Onebox plugins are just simple iframe embeds.

Should I adapt this, Clyp, and for the official Onebox gem? I’ll need to learn more about how those are included, then maybe I can look into merging them.

(Régis Hanol) #4

Not all engines are complex :wink:

Sure, but submit 1 PR per site please.

Here’s what I do when I’m working on a new onebox

  • I git pulled the onebox repository locally
  • I changed the Gemfile in my local discourse repo to point to local onebox (ie, just add , path: '/path/to/onebox)
  • I create a new engine (ie. a new file in the lib/onebox/engine directory)
  • I require my file at the end of the lib/onebox/engine.rb file
  • I launch discourse (rails s) and test away :wink:

(Daniel Marquard) #5

OK, good to know. Also, I’m not confident I fully understand how the embeds scale. I know that a defined height is important for embeds in Discourse posts, but I’ve noticed that heights do not scale on mobile with my plugins.

(Daniel Marquard) #6

I’ve added support for embedding Twitch Clips.

(Travis) #7

@DanielMarquard, are you planning on integrating this into Onebox anytime soon? Trying to decide if I should go ahead with the plugin for now or wait.

(Daniel Marquard) #8

Eventually, yes, along with most of my other Onebox plugins. For now, it won’t hurt for you to install the Twitch Onebox plugin. Your embeds should continue to work properly when I add engines for Twitch in Onebox.

(Daniel Marquard) #9

Improved the accuracy of regex matching and fixed a bug where Twitch Clips without usernames did not embed.

(Robin Ward) #10

Thanks for your work on this. I used it as inspiration for this commit which adds the better twitch oneboxing into onebox:

(Jeff Atwood) closed #11