Widevine License Acquisition Reverse Proxy Server

Widevine Reverse Proxy Server working design

📃 Table of Contents:

  1. Analysis
  2. Setting up Shaka Player
  3. Reverse Proxy Server
  4. Playback & Optimization

1️⃣ Analysis

2️⃣ Setting Up Shaka Player

3️⃣ Creating the Reverse Proxy Server

  1. axios: For HTTP request handling
  2. body-parser: A middleware for handling data in POST body.
  1. Since the data in the post request body is an array buffer we need to ensure that Express doesn’t modify it as we could lose the data. So, we will set up a body parser for the raw data in the body as an octet-stream (Array with 8-bit integer data). Refer to line 10 here in the code.
  2. The data that needs to be passed to the new request should not be sent directly, The licensing servers accept data either an ArrayBuffer or ArrayBufferView (Reference from Shaka Player Issue, Joe Parrish). So we need to convert the data into an array buffer using new Int8Array. Refer to line 28 here in code.
  3. Just like the request, the response also always contains the array buffer, binary data. So, we also need to tell axios about this, to make sure it processes it that way, so we add a new key responseType in axios config and set its value to arraybuffer.

4️⃣ Testing the Playback

Media playback using our Reverse Proxy Server
Server Certificate Request
Server Certificate Request

TL;DR: The code is available here on my Github Repository

🔨 Optimization / #FollowUP:

  1. For better performance, we can also bring http2 (SPDY) into view.
  2. Making it work over text or UTF-8 type response.
  3. Bringing a cache layer as middleware which serves the access tokens to request license if being used. (Optional)
  4. Keep connection alive with server for clients who are requesting license again and again.
  5. Testing with other DRM Providers, the Concept remains the same.

--

--

--

Full Stack Web Developer | Open Source Contributor | Development Operations

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

WHAT’S THAT FUNCTION ?

TypeScript infer Keyword

Getting started with the protractor

Premature Reusability

5 JavaScript Features That You Might Not Know About

Must-Know JS Syntax For React.Js Developer Part — 2

Jewels and Stones

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rohan Gupta

Rohan Gupta

Full Stack Web Developer | Open Source Contributor | Development Operations

More from Medium

How to run docker inside docker container

How to Install GlitchTip on Ubuntu 18.04

Part 1. Install TypeScript + Node.js

How to access EC2 Private IP address from Private API endpoint