This is quite overdue, but here is an update on the project. In terms of what is released, I have published the plugin on npm at peertube-plugin-web-monetization, you can install it by going to the "Plugins/Themes" tab in the instance administration panel and using the search feature. I am almost ready to publish a table of contents plugin which integrates with the Web Monetization one so that sponsor segments can be marked, and will be skipped by those contributing with Web Monetization. In this post I will go over how this implementation works, and later this week I will make another pust when I put out the table of contents plugin.
Implementing Web Monetization🔗
Adding basic Web Monetization takes a single line in the
head element of a webpage. Adding the meta tag
<meta name="monetization" content="$example.org/account" /> will request that clients send money using the Interledger protocol to
$example.org/account. But since we are working with video content, we can know when the user is actually consuming the content. So, we add and remove the meta element when the user plays or pauses the video (or buffering begins or ends), and the user agent observes this and starts and stops payments. This is the current state of the plugin, but we can go a step further.
The user agent will trigger events when monetization begins or ends, and when each payment is made. The events can be subscribed to using
document.monetization.addEventListener. We can then track the status using
monetizationstop to take actions such as removing ads, or in our case, skipping sponsors within videos. We can see each payment using the
monetizationprogress, and determined how much is being paid out. Currently, it is entirely up to the user agent how much to pay. In the future, we can also use the receipt from this event to validate the payment, but there is currently no way to do so.
That's currently the extent of the Web Monetization API. The main feature I feel is missing is the ability to request a certain level of payment. The standard is still a draft, so really any of this could change.
Implementing a PeerTube plugin🔗
Like Web Monetization, PeerTube's plugin system is a recent development. Our abilities are fairly limited, so we will need to implement some features in PeerTube itself, and expand it for portions that should be implemented in a plugin. There a two sides to a PeerTube plugin, the client and server side. We provide a
register function for the server, and
register functions for different pages in the client.
First, we hook into the video edit page to register a form field for the payment pointer. The server side then must hook
action:api.video.updated to receive the form field and store it in our plugin data, and
filer:api.video.get.result to forward the payment pointer to the client. We then hook the video watch and embed pages. Here we setup Web Monetization as described above, responding to video events by enabling or disabling monetization, and responding to monetization events and logging them for now. The user agent can pay in any currency, so when each payment is made we add the amount to the total paid in that currency. When monetization ends, we print the totals.
The current shortcomings are that there are no account-wide settings accessible by the plugin. It is desirable to set a payment pointer for the entire account, rather than per-video. This is being implemented by adding video templates, so a user simply adds their payment pointer to the default video template for their account. Then it is used by default, and they can also override it per-video.