<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cao Wen</title>
    <description>The latest articles on DEV Community by Cao Wen (@durianlive).</description>
    <link>https://dev.to/durianlive</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242932%2F6da30ad1-2a84-40a1-ae12-c240a98c5fff.png</url>
      <title>DEV Community: Cao Wen</title>
      <link>https://dev.to/durianlive</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/durianlive"/>
    <language>en</language>
    <item>
      <title>Stripping comments from a 500 KB JS bundle without breaking inline onclick</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Sat, 28 Nov 2026 08:52:27 +0000</pubDate>
      <link>https://dev.to/durianlive/stripping-comments-from-a-500-kb-js-bundle-without-breaking-inline-onclick-19i8</link>
      <guid>https://dev.to/durianlive/stripping-comments-from-a-500-kb-js-bundle-without-breaking-inline-onclick-19i8</guid>
      <description>&lt;p&gt;Our widget ships as one hand-concatenated file: six source modules are joined into &lt;code&gt;shell.js&lt;/code&gt;, and the server serves that file directly. No bundler, no module graph, no build server.&lt;/p&gt;

&lt;p&gt;That worked fine until the file reached ~500 KB and every internal note, fix log, and TODO was publicly readable. The fix sounds trivial — strip comments — until you remember the page calls global functions from inline &lt;code&gt;onclick&lt;/code&gt; attributes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint that rules out normal minification
&lt;/h2&gt;

&lt;p&gt;The widget's markup is generated as strings, and buttons look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"livenetGift()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Send&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every handler is a global function on &lt;code&gt;window&lt;/code&gt;. A normal minifier renames those functions to &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt;, and every inline handler breaks at runtime with &lt;code&gt;livenetGift is not defined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So the rule is: &lt;strong&gt;remove comments and whitespace, never rename identifiers.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Attempt 1: terser
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx terser shell.js -c &lt;span class="kc"&gt;false&lt;/span&gt; -m &lt;span class="kc"&gt;false&lt;/span&gt; --comments &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That version of terser rejected the flags:&lt;/p&gt;

&lt;p&gt;Terser is built for full minification; disabling both compression and mangling is not a supported path in every release.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attempt 2: esbuild with whitespace-only minification
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx --yes esbuild shell.js \
  --minify-whitespace \
  --legal-comments=none \
  --outfile=shell.min.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--minify-whitespace&lt;/code&gt; removes comments, blank lines, and extra spaces. It does &lt;strong&gt;not&lt;/strong&gt; rename identifiers or rewrite syntax. &lt;code&gt;--legal-comments=none&lt;/code&gt; drops license comments too.&lt;/p&gt;

&lt;p&gt;Result: same function names, same behaviour, no comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify before shipping
&lt;/h2&gt;

&lt;p&gt;Two cheap checks in the build script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node --check shell.min.js
grep -c &lt;span class="s2"&gt;"function livenetGift"&lt;/span&gt; shell.min.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first catches syntax errors. The second catches the failure mode that matters: a handler that used to exist but no longer does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the build fail safe
&lt;/h2&gt;

&lt;p&gt;The build script should never leave you without a working file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$tmp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Join&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="nv"&gt;$scriptDir&lt;/span&gt; &lt;span class="s2"&gt;"shell.__min.js"&lt;/span&gt;
&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;npx&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt; &lt;span class="n"&gt;esbuild&lt;/span&gt; &lt;span class="nv"&gt;$outFile&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;minify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;legal&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;comments&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;outfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$tmp&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$LASTEXITCODE&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;eq&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Move&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Force&lt;/span&gt; &lt;span class="nv"&gt;$tmp&lt;/span&gt; &lt;span class="nv"&gt;$outFile&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Remove&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt; &lt;span class="nv"&gt;$tmp&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ErrorAction&lt;/span&gt; &lt;span class="nc"&gt;SilentlyContinue&lt;/span&gt;
    &lt;span class="nc"&gt;Write&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt; &lt;span class="s2"&gt;"esbuild unavailable - keeping unminified build"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;npx&lt;/code&gt; cannot reach the registry, the build keeps the unminified file instead of failing. A slightly larger bundle is better than a broken deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this does not solve
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stack traces now point to different line numbers. Keep the unminified file for local development.&lt;/li&gt;
&lt;li&gt;It is not obfuscation. Anyone can still read the logic; they just cannot read your comments.&lt;/li&gt;
&lt;li&gt;It does not replace a real bundler. The concatenation order is still manual.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  For a small widget served as a single file, that trade-off is fine. The build stays a shell script, the page keeps working, and the internal notes stay internal.
&lt;/h2&gt;

&lt;p&gt;This build serves the widget at &lt;a href="https://durianlive.com/?utm_source=devto&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;durianlive.com&lt;/a&gt;. If you're evaluating live shopping tools, the merchant-facing checklist — commission, viewer caps, replay ownership — is here: &lt;a href="https://durianlive.com/blog/live-shopping-plugin-without-commission?utm_source=devto&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;Choosing a live shopping plugin without commission&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>tooling</category>
    </item>
    <item>
      <title>100 concurrent viewers is a chat problem, not a video problem</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Thu, 26 Nov 2026 12:47:05 +0000</pubDate>
      <link>https://dev.to/durianlive/100-concurrent-viewers-is-a-chat-problem-not-a-video-problem-14hd</link>
      <guid>https://dev.to/durianlive/100-concurrent-viewers-is-a-chat-problem-not-a-video-problem-14hd</guid>
      <description>&lt;p&gt;Every live shopping demo works with three viewers. At 100, the video is usually still fine. What breaks is the side channel: chat, presence, product pins, and the reconnect storm after a deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Video is a fan-out you can cache
&lt;/h2&gt;

&lt;p&gt;One RTMP/HTTP-FLV ingest into SRS. Every viewer pulls the same stream. No per-viewer transcode, no per-viewer process. CPU stays roughly flat as viewers join; bandwidth grows linearly. The failure modes are mundane: a bad cache header, a proxy that buffers, a player that keeps the last frame after the encoder reconnects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Chat is a connection fan-out
&lt;/h2&gt;

&lt;p&gt;Every viewer opens a WebSocket for chat, presence, and product pins. 100 sockets is not a lot. What hurts is what happens around them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A deploy drops all sockets at once; 100 clients reconnect in the same second.&lt;/li&gt;
&lt;li&gt;One slow consumer backs up the fan-out queue.&lt;/li&gt;
&lt;li&gt;A new viewer asks for history and gets the entire stream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix is boring: bounded history, drop-oldest backpressure, jittered reconnect, and a heartbeat that closes dead sockets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Product pins need ordering
&lt;/h2&gt;

&lt;p&gt;A pinned product is a small state machine. Two events can arrive out of order after a reconnect. If the client applies the older one last, the stream shows the wrong product. Put a monotonic id on every event and ignore anything older than the last applied id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;lastId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;onEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;lastId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;lastId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reconnect is the real test
&lt;/h2&gt;

&lt;p&gt;The encoder will drop. The player will reconnect. The UI must say "reconnecting" instead of pretending the last frame is live. The cart must survive the reconnect. The chat should backfill a bounded window, not the whole session.&lt;/p&gt;

&lt;p&gt;We test this by killing the ingest mid-stream and checking three things: the player state, the pinned product, and the cart. If any of them resets, the widget is not ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we changed
&lt;/h2&gt;

&lt;p&gt;We separated video from events. Video is a pull; events are one WebSocket. Chat history is capped. Reconnects use jitter. Product pins are idempotent. None of this is exotic; it is just the part that does not fit in a demo.&lt;/p&gt;

&lt;p&gt;If you run Shopify or WooCommerce, the widget is free up to 100 concurrent viewers, 0% commission. Setup notes: &lt;a href="https://durianlive.com/?utm_source=devto&amp;amp;utm_medium=article" rel="noopener noreferrer"&gt;https://durianlive.com/?utm_source=devto&amp;amp;utm_medium=article&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>video</category>
      <category>websocket</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Validating postMessage from an iframe you don't control</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Tue, 24 Nov 2026 13:05:38 +0000</pubDate>
      <link>https://dev.to/durianlive/validating-postmessage-from-an-iframe-you-dont-control-44c7</link>
      <guid>https://dev.to/durianlive/validating-postmessage-from-an-iframe-you-dont-control-44c7</guid>
      <description>&lt;p&gt;When your widget is embedded on domains you don't own, the usual &lt;code&gt;event.origin&lt;/code&gt; check doesn't work. There is no fixed list of merchant domains to whitelist, and accepting everything means any page can drive your UI. The fix is one line: compare &lt;code&gt;event.source&lt;/code&gt; with the &lt;code&gt;contentWindow&lt;/code&gt; of the iframe you created.&lt;/p&gt;

&lt;h2&gt;
  
  
  The handler with no sender check
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'widget-frame'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'panel_state'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'375px'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'667px'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any window that can get a reference to your page can post the same message and change the layout. On a merchant's site that includes every ad and analytics script.&lt;/p&gt;

&lt;p&gt;An origin whitelist doesn't survive contact with reality: merchants embed you on their own domain, their staging domain, a page-builder subdomain. You cannot enumerate them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare the source instead
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;MessageEvent.source&lt;/code&gt; is the &lt;code&gt;WindowProxy&lt;/code&gt; of the sender. For an iframe you own, it is exactly that iframe's &lt;code&gt;contentWindow&lt;/code&gt; — even cross-origin, even after the iframe navigates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'widget-frame'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contentWindow&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'panel_state'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'375px'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'667px'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;contentWindow&lt;/code&gt; is a live reference and stays stable across iframe reloads.&lt;/li&gt;
&lt;li&gt;This does not replace validating the payload. Check &lt;code&gt;.type&lt;/code&gt; against an allowlist and clamp numbers.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The sending side
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;postMessage&lt;/code&gt; with &lt;code&gt;'*'&lt;/code&gt; leaks the message to whoever ends up in that window. If the parent is same-origin, name it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'payment_paid'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'billing'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the parent can really be any merchant domain, keep &lt;code&gt;'*'&lt;/code&gt; but never put tokens, customer data, or credential-bearing URLs in the payload. The message should be a UI signal, not a data channel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Every &lt;code&gt;message&lt;/code&gt; listener checks &lt;code&gt;event.source&lt;/code&gt; against the iframe it owns&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;event.data&lt;/code&gt; is treated as untrusted input&lt;/li&gt;
&lt;li&gt;[ ] Outbound messages use an explicit &lt;code&gt;targetOrigin&lt;/code&gt; when known&lt;/li&gt;
&lt;li&gt;[ ] No secrets in messages that must use &lt;code&gt;'*'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] One listener per iframe, not a global one comparing the last-known frame&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole fix is about ten lines. The hard part is remembering that "we're behind an iframe" doesn't make the parent page a trusted sender.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>I accidentally published my own analytics — and a stream key</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:24:33 +0000</pubDate>
      <link>https://dev.to/durianlive/i-accidentally-published-my-own-analytics-and-a-stream-key-4cgk</link>
      <guid>https://dev.to/durianlive/i-accidentally-published-my-own-analytics-and-a-stream-key-4cgk</guid>
      <description>&lt;p&gt;I added a nightly GoAccess report to my site for convenience. It wrote index.html and a dated snapshot into /static, fire-and-forget.&lt;/p&gt;

&lt;p&gt;It worked. It also published every request URL, including query strings.&lt;/p&gt;

&lt;p&gt;One of those URLs was:&lt;/p&gt;

&lt;p&gt;/api/stream/token?key=&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;a&gt;

&lt;p&gt;Two shop keys were sitting in a public HTML file for nine days. No admin path, no internal token, no customer emails — but a stream key is a credential. Anyone who found the URL could publish to that room.&lt;/p&gt;

&lt;p&gt;What I did:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Moved the report output out of the web root (it now lives in a private directory).&lt;/li&gt;
&lt;li&gt;Added --no-query-string to GoAccess so URLs are logged without query strings.&lt;/li&gt;
&lt;li&gt;Kept --anonymize-ip and --ignore-crawlers.&lt;/li&gt;
&lt;li&gt;Checked access logs: 35 requests over nine days, six IPs, almost all my own. No sign of scraping. Lucky, not safe.&lt;/li&gt;
&lt;li&gt;Rotated the exposed keys.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What I should have known:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;robots.txt is not access control. It keeps crawlers out, not people.&lt;/li&gt;
&lt;li&gt;A static directory is public by definition. "Nobody knows the URL" is not a security model.&lt;/li&gt;
&lt;li&gt;Query strings are where credentials leak: tokens, keys, signed URLs, password-reset links.&lt;/li&gt;
&lt;li&gt;Analytics dashboards are sensitive data, not a convenience page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run a small SaaS, do this today: fetch your public HTML and grep for &lt;code&gt;?key=&lt;/code&gt;, &lt;code&gt;?token=&lt;/code&gt;, and &lt;code&gt;signature=&lt;/code&gt;. Then check anything that writes reports into a served directory.&lt;/p&gt;

&lt;p&gt;The boring fix took ten minutes. The leak had already been live for nine days.&lt;/p&gt;

&lt;/a&gt;

</description>
      <category>cybersecurity</category>
      <category>infosec</category>
      <category>security</category>
    </item>
    <item>
      <title>Submitting a WordPress plugin in 2026: slug, Plugin Check, and a 250-character form</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Sat, 21 Nov 2026 12:50:45 +0000</pubDate>
      <link>https://dev.to/durianlive/submitting-a-wordpress-plugin-in-2026-slug-plugin-check-and-a-250-character-form-52aa</link>
      <guid>https://dev.to/durianlive/submitting-a-wordpress-plugin-in-2026-slug-plugin-check-and-a-250-character-form-52aa</guid>
      <description>&lt;p&gt;I just submitted a small WordPress plugin to the directory. The form is not what I expected.&lt;/p&gt;

&lt;p&gt;You don't fill in a name, description, or tags. You upload a zip, and WordPress derives everything from the plugin header and readme.txt. The "additional information" box is the only place to talk to a human, and it's optional.&lt;/p&gt;

&lt;p&gt;What actually matters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The readme is the product page. Description, installation, FAQ, privacy, changelog — reviewers read it before they read your code.&lt;/li&gt;
&lt;li&gt;The slug is derived from your plugin name. Mine came out as durianlive-live-selling-widget because the name ends with "Widget". You can request one change before review, and after approval it's permanent.&lt;/li&gt;
&lt;li&gt;Plugin Check is the cheapest review you'll ever get. Run every category — General, Plugin Repo, Security, Performance, Accessibility — with errors and warnings enabled. Fix what it flags before submitting.&lt;/li&gt;
&lt;li&gt;The queue is real. 621 plugins were waiting for a first review when I submitted. Don't plan a launch around the approval date.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The plugin itself is about 120 lines of PHP. The submission took longer than the code, and that's probably the right ratio for anything you want other people to install.&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>webdev</category>
      <category>wordpress</category>
    </item>
    <item>
      <title>The FLV cache bug that makes your second live stream go black</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Fri, 20 Nov 2026 13:41:57 +0000</pubDate>
      <link>https://dev.to/durianlive/the-flv-cache-bug-that-makes-your-second-live-stream-go-black-1fe2</link>
      <guid>https://dev.to/durianlive/the-flv-cache-bug-that-makes-your-second-live-stream-go-black-1fe2</guid>
      <description>&lt;p&gt;We run a small relay in front of SRS so late viewers can start decoding immediately: cache the FLV header (metadata + AVC/AAC sequence headers) plus the current GOP, then replay both to anyone who joins mid-stream.&lt;/p&gt;

&lt;p&gt;It worked for months. Then a second live room went permanently black — with a valid H.264 stream, valid audio, no console errors.&lt;/p&gt;

&lt;p&gt;The header replayed fine. The problem was the GOP cache.&lt;/p&gt;

&lt;p&gt;FLV is a tag stream: each tag has an 11-byte header with a 24-bit size field. Our GOP buffer was appended from arbitrary io.Writer chunks, so it often started in the middle of a tag. The scanner then read a random byte as a tag type and a random 24-bit number as a length, misaligned forever, and replayed raw bytes that looked nothing like video to the decoder.&lt;/p&gt;

&lt;p&gt;The fix is two lines of discipline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Seed the GOP buffer from the header buffer. The header buffer is only marked "done" after a complete tag, so it always ends on a boundary.&lt;/li&gt;
&lt;li&gt;Only replay the GOP buffer when its first tag is a keyframe video tag. Otherwise skip the replay and wait for the next IDR.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lesson: any cache of a binary container format has to start on a record boundary. "It works on my first stream" is not evidence — the chunk boundary just happened to land somewhere else that time.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>debugging</category>
      <category>streaming</category>
    </item>
    <item>
      <title>The buy button should never open a new tab</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Thu, 19 Nov 2026 14:56:41 +0000</pubDate>
      <link>https://dev.to/durianlive/the-buy-button-should-never-open-a-new-tab-l3d</link>
      <guid>https://dev.to/durianlive/the-buy-button-should-never-open-a-new-tab-l3d</guid>
      <description>&lt;p&gt;Every live shopping demo I've seen does the same thing: the product card opens a new tab&lt;br&gt;
with the product page.&lt;/p&gt;

&lt;p&gt;The viewer leaves the stream. Once they leave, they don't come back — they finish checkout,&lt;br&gt;
get distracted, and the stream keeps talking to an empty room.&lt;/p&gt;

&lt;p&gt;We keep the product page inside the same iframe the stream is playing in. The video keeps&lt;br&gt;
running behind it, and "back" returns to the stream instead of a blank history entry.&lt;/p&gt;

&lt;p&gt;It's not a technical breakthrough. It's a decision about which surface owns the checkout,&lt;br&gt;
and it's the difference between a live event and a product page with a video in the corner.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>ecommerce</category>
      <category>webdev</category>
    </item>
    <item>
      <title>HTTP-FLV freezes after a reconnect — the FLV header is the reason</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:32:55 +0000</pubDate>
      <link>https://dev.to/durianlive/http-flv-freezes-after-a-reconnect-the-flv-header-is-the-reason-h1a</link>
      <guid>https://dev.to/durianlive/http-flv-freezes-after-a-reconnect-the-flv-header-is-the-reason-h1a</guid>
      <description>&lt;p&gt;Symptom first, because it's the part that wastes days: your HTTP-FLV stream plays fine, the network blips for a second, the player reconnects — and then the picture freezes permanently. Not a rebuffer. Not an error event.&lt;code&gt;buffered&lt;/code&gt; stops growing,&lt;code&gt;currentTime&lt;/code&gt; stops advancing, and only a full page reload fixes it.&lt;/p&gt;

&lt;p&gt;Everything looks healthy from the outside. Bytes are still arriving. The connection is open. The player just refuses to move.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually happened
&lt;/h2&gt;

&lt;p&gt;An HTTP-FLV connection is not a continuation of the previous one. Every new connection begins with:&lt;/p&gt;

&lt;p&gt;FLV header (9 bytes) + sequence header + the last GOP from the server's gop cache&lt;/p&gt;

&lt;p&gt;That is a complete, independently decodable prefix — but its timestamps start before the ones already in your&lt;code&gt;SourceBuffer&lt;/code&gt; . When you append it as if it were the next chunk of the old stream, the demuxer sees a second FLV header and a timestamp going backwards. Some players throw. Most just stop advancing, which is worse, because nothing in your logs looks like an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: treat reconnect as a generation change
&lt;/h2&gt;

&lt;p&gt;Don't patch the stream. Replace it:&lt;/p&gt;

&lt;p&gt;function onReconnect() {&lt;br&gt;
  gen++;                      // new generation id&lt;br&gt;
  resetPrefixCache();         // drop FLV header / GOP parts&lt;br&gt;
  player.unload();            // destroy the MSE state&lt;br&gt;
  connect(url);               // reconnect, take the fresh prefix as-is&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Two details matter more than the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Downstream consumers need the same treatment. If anything relays your bytes (a peer, a worker, a proxy), it has to forward a generation marker followed by the full prefix — not mid-stream bytes. Otherwise the downstream keeps feeding old chunks into a new decoder and you get artifacts that look like corruption.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Drop queued bytes on reconnect, not on error. The trap is that send queues look healthy while the pipeline is already dead. Clear the queue when the generation changes; the prefix replay will refill it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The cost
&lt;/h2&gt;

&lt;p&gt;Destroying and rebuilding the buffer costs roughly 200–400ms of black frame. That feels bad until you compare it to the alternative: a viewer staring at a frozen image until they reload the page, with no indication anything is wrong.&lt;/p&gt;

&lt;p&gt;For a live commerce stream, a 300ms blip during a network hiccup is invisible. A permanent freeze during a product demo is the whole session.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd check first
&lt;/h2&gt;

&lt;p&gt;If you see this in the wild, log three things on reconnect: the FLV header offset where the new connection started, the first timestamp after reconnect, and whether it's lower than the last one you appended. That one comparison tells you whether you're looking at a generation problem or something else entirely.&lt;/p&gt;

&lt;p&gt;I build a live selling widget for Shopify/WooCommerce stores, which is where most of these reconnect cases showed up: &lt;a href="https://durianlive.com" rel="noopener noreferrer"&gt;https://durianlive.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>video</category>
      <category>webdev</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Paid live streams are an access-control problem, not a streaming problem</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:07:28 +0000</pubDate>
      <link>https://dev.to/durianlive/paid-live-streams-are-an-access-control-problem-not-a-streaming-problem-1n8c</link>
      <guid>https://dev.to/durianlive/paid-live-streams-are-an-access-control-problem-not-a-streaming-problem-1n8c</guid>
      <description>&lt;p&gt;A merchant messaged me last week asking which app could stream a cooking class to Shopify, YouTube, Zoom and Instagram at the same time.&lt;/p&gt;

&lt;p&gt;The streaming half of that question is basically solved. StreamYard, OBS, Zoom Webinar — pick one, it fans out. What nobody warns them about is the other half: once someone pays, who is allowed to watch, for how long, and what happens when the link gets forwarded.&lt;/p&gt;

&lt;p&gt;That part is not a streaming problem. It's access control, and it's usually a single boolean (&lt;code&gt;has_paid&lt;/code&gt; ) doing work it can't do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four places paid access leaks
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;One link, many viewers. If the same meeting URL goes into the order confirmation email, the first buyer can forward it to five people. You sold one seat and got six attendees. You will never know.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The link lives only in an email. People buy ten minutes before the class, then can't find the email. Your support inbox fills up with "where's my link" at exactly the wrong moment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replay rights are never defined. The live seat is sold. The recording then gets sent to whoever asks, because nobody decided whether the recording was part of the purchase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Late buyers and refunds. Someone buys after the class started. Someone else refunds on day two. With a boolean, both cases are undefined.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Model an entitlement, not a flag
&lt;/h2&gt;

&lt;p&gt;Each purchase should create a row with a window and a revocation timestamp:&lt;/p&gt;

&lt;p&gt;create table entitlements (&lt;br&gt;
  id            text primary key,&lt;br&gt;
  order_id      text not null,&lt;br&gt;
  product_id    text not null,&lt;br&gt;
  email         text not null,&lt;br&gt;
  token         text not null unique,&lt;br&gt;
  live_starts   timestamptz not null,&lt;br&gt;
  live_ends     timestamptz not null,&lt;br&gt;
  replay_until  timestamptz,&lt;br&gt;
  revoked_at    timestamptz&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;The token is the buyer's private key to the stream. It's cheap to generate and it gives you a per-buyer audit trail, which a shared meeting URL never will.&lt;/p&gt;

&lt;p&gt;Checking it is a window comparison, not a lookup of a boolean:&lt;/p&gt;

&lt;p&gt;func allowWatch(e Entitlement, now time.Time) bool {&lt;br&gt;
    if e.RevokedAt != nil {&lt;br&gt;
        return false&lt;br&gt;
    }&lt;br&gt;
    if now.Before(e.LiveStarts.Add(-15 * time.Minute)) {&lt;br&gt;
        return false // too early to join&lt;br&gt;
    }&lt;br&gt;
    if now.Before(e.LiveEnds) {&lt;br&gt;
        return true // live window, plus 15 min grace to join&lt;br&gt;
    }&lt;br&gt;
    return e.ReplayUntil != nil &amp;amp;&amp;amp; now.Before(*e.ReplayUntil)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Two details that matter more than they look:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A grace window before start. Without it, people who arrive early get a 403 and email you.&lt;/li&gt;
&lt;li&gt;Replay as a separate expiry.&lt;code&gt;replay_until&lt;/code&gt; lets you bundle the recording, sell it separately, or give it a 7-day window — without changing the live logic.
## Rotate the ingest key after each session
If buyers ever get near the ingest side (self-hosted streaming, a custom player), rotate the stream key per session. A forwarded ingest key is worse than a forwarded watch link, because it doesn't just let someone watch — it lets them broadcast into your room.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rotating per session means a leaked key is dead by the next class, and you never have to chase it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd skip
&lt;/h2&gt;

&lt;p&gt;Don't reach for DRM or per-viewer watermarking on a cooking class. The realistic threat model is "one buyer shares the link with a friend", not a piracy ring. A per-buyer token plus a defined replay window solves the actual problem for a fraction of the work.&lt;/p&gt;

&lt;p&gt;If you've sold access to a live stream: what did you end up enforcing — the link, the session, or the person? I'm curious whether anyone has found a lighter-weight pattern than per-buyer tokens.&lt;/p&gt;

&lt;p&gt;I build a live selling widget for Shopify/WooCommerce stores, which is where most of these edge cases showed up: &lt;a href="https://durianlive.com" rel="noopener noreferrer"&gt;https://durianlive.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>ecommerce</category>
      <category>showdev</category>
    </item>
    <item>
      <title>What I learned building a live-streaming widget with Go + SRS (and one iframe)</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Sun, 15 Nov 2026 11:59:52 +0000</pubDate>
      <link>https://dev.to/durianlive/what-i-learned-building-a-live-streaming-widget-with-go-srs-and-one-iframe-49li</link>
      <guid>https://dev.to/durianlive/what-i-learned-building-a-live-streaming-widget-with-go-srs-and-one-iframe-49li</guid>
      <description>&lt;p&gt;I run a small live-selling widget for Shopify and WooCommerce stores. Not a startup — one person, one Go binary, SRS for media. A few decisions turned out to matter more than the feature list, so I'm writing them down.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Iframe instead of a script tag
&lt;/h2&gt;

&lt;p&gt;The first version was &lt;code&gt;&amp;lt;script src=".../shell.js" data-key="..."&amp;gt;&lt;/code&gt;. It injected a floating player into the merchant's page.&lt;/p&gt;

&lt;p&gt;It broke constantly. Theme CSS leaked in, my CSS leaked out, and every third-party script on the page fought with mine. Worse: the API key sat in the DOM of a public storefront page.&lt;/p&gt;

&lt;p&gt;What I ship now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/embed?shop_id=6"&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"375"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"667"&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"position:fixed;right:20px;bottom:20px;border:0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same iframe, one public shop id, zero secrets in the markup. The merchant pastes four lines. If they break their theme, they don't break the player.&lt;/p&gt;

&lt;p&gt;Trade-off: iframe can't inherit the store's fonts. For a player that's fine — isolation is worth more than pixel-matching.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. SRT for the ingest path, not just RTMP
&lt;/h2&gt;

&lt;p&gt;RTMP is everywhere and everyone supports it. It's also TCP with fixed latency and handles packet loss badly — which is the normal condition for a merchant streaming from a phone on store wifi.&lt;/p&gt;

&lt;p&gt;SRT gives you loss recovery and configurable latency for maybe 200ms more delay. For live selling, 200ms of extra delay costs nothing; a frozen frame costs the sale.&lt;/p&gt;

&lt;p&gt;I still expose RTMP for compatibility, but the default config in my docs is SRT, and the bitrate defaults are deliberately conservative (1500–2000 kbps, 2s keyframe). Cross-border upload can't sustain 6 Mbps and the failure mode is a black player.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Enforce limits on the server, never in the widget
&lt;/h2&gt;

&lt;p&gt;Viewer caps, stream keys, tier upgrades — all of it lives in the Go backend. The widget only renders.&lt;/p&gt;

&lt;p&gt;Early on I had a cap check in the frontend so it would "respond faster". It took one person with devtools to watch a 200-viewer room on a 20-viewer plan. Anything that costs money has to be a server-side decision, even if the client shows a cached number.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The bug that taught me the most was caching
&lt;/h2&gt;

&lt;p&gt;I deploy static assets by scp'ing them into place and restarting nginx. Everything under &lt;code&gt;/static&lt;/code&gt; was served with &lt;code&gt;Cache-Control: max-age=604800, immutable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The day I added a feature that needed new i18n keys, every returning user got the new HTML with the old dictionary — and saw raw keys like &lt;code&gt;lc_title&lt;/code&gt; on screen instead.&lt;/p&gt;

&lt;p&gt;Now every asset reference carries a build version. &lt;code&gt;immutable&lt;/code&gt; is only safe if the URL changes when the content does. Obvious in hindsight; not obvious at 2am.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's still hard
&lt;/h2&gt;

&lt;p&gt;Payments. If you're a solo developer outside the US/EU, merchant onboarding is the real boss fight — not the media pipeline. I've been through two providers' review processes and neither outcome was about code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;p&gt;The whole thing is at &lt;a href="https://durianlive.com" rel="noopener noreferrer"&gt;https://durianlive.com&lt;/a&gt; — happy to hear what I got wrong, especially from anyone who has run live video at small scale.&lt;/p&gt;

</description>
      <category>go</category>
      <category>showdev</category>
      <category>webdev</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>How do small stores handle live selling without commission?</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Sat, 14 Nov 2026 10:44:37 +0000</pubDate>
      <link>https://dev.to/durianlive/how-do-small-stores-handle-live-selling-without-commission-2g11</link>
      <guid>https://dev.to/durianlive/how-do-small-stores-handle-live-selling-without-commission-2g11</guid>
      <description></description>
    </item>
    <item>
      <title>Live selling shouldn't cost you 10% of every order</title>
      <dc:creator>Cao Wen</dc:creator>
      <pubDate>Fri, 13 Nov 2026 12:54:17 +0000</pubDate>
      <link>https://dev.to/durianlive/live-selling-shouldnt-cost-you-10-of-every-order-10dc</link>
      <guid>https://dev.to/durianlive/live-selling-shouldnt-cost-you-10-of-every-order-10dc</guid>
      <description>&lt;p&gt;I'm the founder of DurianLive. This is the business problem we ran into,&lt;br&gt;
and what we changed — not a technical deep dive.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern
&lt;/h2&gt;

&lt;p&gt;Almost every live shopping tool asks the merchant to do the same thing:&lt;br&gt;
move the sale to the tool's platform. You get a spike in orders, then a&lt;br&gt;
bill for the commission, and the customer — their email, their purchase&lt;br&gt;
history, their attention — stays with the platform.&lt;/p&gt;

&lt;p&gt;The second problem is the catalog. You have to rebuild your products&lt;br&gt;
inside the tool: same photos, same descriptions, uploaded a second time.&lt;/p&gt;

&lt;p&gt;The third is the redirect. The shopper was on a product page, ready to&lt;br&gt;
buy. Now they're in another tab, and your checkout is three clicks away.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we changed
&lt;/h2&gt;

&lt;p&gt;The show runs on the merchant's own website. A small player sits in the&lt;br&gt;
corner of the store. A shopper browsing a product page can open it, watch,&lt;br&gt;
ask a question, and click a product card — which takes them to the product&lt;br&gt;
page they already have, with the checkout they already use. They never leave.&lt;/p&gt;

&lt;p&gt;What that means in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You keep the sale.&lt;/strong&gt; Payments run through the existing checkout —
Shopify, WooCommerce, whatever the store has. We never touch the money
and never take a percentage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You keep the customer.&lt;/strong&gt; Orders, emails, and browsing behaviour stay in
the merchant's dashboard and email tool, not ours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You keep your catalog.&lt;/strong&gt; Product cards link to the pages the merchant
already maintains. Nothing to re-upload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setup is one line.&lt;/strong&gt; Paste it into the theme, save, open the store.
No plugin, no app install, no developer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The price is flat.&lt;/strong&gt; Merchants pay for how many people can watch at
once, not for how much they sell. Free up to 100 concurrent viewers;
paid plans start at $2 per day or $49 per month.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What a show looks like
&lt;/h2&gt;

&lt;p&gt;Boring on purpose: open the player ten minutes early, show three to five&lt;br&gt;
products instead of the whole catalog, keep the product card pinned while&lt;br&gt;
talking about it, run 20–30 minutes, and finish with a discount code for&lt;br&gt;
people who stayed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who this is not for
&lt;/h2&gt;

&lt;p&gt;If most of a store's reach comes from TikTok or Instagram, they want that&lt;br&gt;
algorithm and that audience; a widget on their own site won't manufacture&lt;br&gt;
demand. This is for stores that already have traffic — from search, ads,&lt;br&gt;
email, or a physical shop — and want to turn it into sales with a human on&lt;br&gt;
camera.&lt;/p&gt;

&lt;p&gt;The trade-off is honest: you give up the platform's built-in audience, and&lt;br&gt;
in exchange you keep the customer, the margin, and the data.&lt;/p&gt;




&lt;p&gt;If you want the step-by-step setup, it's here — Shopify and WooCommerce,&lt;br&gt;
about 15 minutes end to end: &lt;a href="https://durianlive.com/blog/shopify-live-selling" rel="noopener noreferrer"&gt;https://durianlive.com/blog/shopify-live-selling&lt;/a&gt;&lt;/p&gt;

</description>
      <category>woocommerce</category>
      <category>ecommerce</category>
      <category>saas</category>
      <category>shopify</category>
    </item>
  </channel>
</rss>
