The Livepeer Token Gating MVP gates new viewers of video, pending on a webhooks response. Applications can configure a webhook to receive events on any new, incoming viewers. A webhook response of 2XXwill allow a new viewer to see the stream while any other response will deny a viewer.

Currently, webhooks are set across all streams. This means once you enable token gating, it’s enabled for all streams in your account.

How to configure an webhook endpoint

Webhook endpoints are specific for each event. Once the event is registered, all streams for this account will trigger the specific event. Here is an example of registering for the playback.user.new endpoint:

curl \
    -X POST \
    -H "authorization: Bearer {api_key}" \
    -H "content-type: application/json" \
    --data-raw '{
      "events": ["playback.user.new"],
      "url": "{webhook_url}",
      "name": "test webhooks"
  }' \
  <https://livepeer.com/api/webhook>

Example payload and gate logic

This is an example of the payload of this webhook trigger, assuming the request URL is https://playback.livepeer.engineering/hls/PLAYBACK_ID/index.m3u8?proof=ETH_SIG where ETH_SIG is an Ethereum wallet signature:

{
  "timestamp": 1651480121,
  "payload": {
    "requestUrl": "<http://playback.livepeer.engineering:8081/hls/PLAYBACK_ID/index.m3u8?stream=b135bpp8yefanya8&proof=ETH_SIG>"
  }
}

This is an example implementation where your receiving application can recover the signature in the proof parameter and allow or disallow the playback on any condition regarding the user wallet address (e.g. If the user hold a particular NFT or token).

Sessions are cached for approximately ten minutes, after which a user is considered new again.

Webhook response behavior

A response to a trigger is considered positive if it starts with any of the following: 1, yes, true, cont. It is considered negative in all other cases.

The behavior of the playback is determined by the response to this webhook trigger:

Status code Response Body Playback
2XX true or yes or 1 or cont Allowed
Any false or no or 0 Not allowed
4XX Any Not allowed
5XX Any Not allowed

Ingest and Playback URLs

As a result of this product being an early MVP, please use these URLs for ingest and playback for any stream that you have configured to trigger the playback.user.new endpoint. Using the normal ingest and playback will not work yet.