bbc / VideoContext

An experimental HTML5 & WebGL video composition and rendering API.
http://bbc.github.io/VideoContext/
Apache License 2.0
1.33k stars 157 forks source link

Add a way to register new node types #115

Closed germain-gg closed 5 years ago

germain-gg commented 6 years ago

Hi,

VideoContext has a few node types and some node accept multiple types of inputs. But I think everyone would benefit from having a way to register new node types.

What's the use case?

A user wants to create play an HLS video back. What we currently need to do is to import a library like hls.js, get the MediaSourceExtension object it will generate and pass that as the source of a VideoNode.

How would it work?

It would work by adding a static method to register a new node type

VideoContext.registerNodeType(nodeName: string, nodeClass: object)

Currently the recommended way to create a node is to call

const videoNode = vc.video(source);

When using custom types we should not attach the new type to VideoContext's prototype. for that reason I think we need to introduce a new method called node


VideoContext.registerNodeType("hls", HLSNode);

const hlsNode = vc.hls(manifestUrl); // bad because the library becomes vulnerable to prototype pollution

const hlsNode = vc.node("hls", manifestUrl); // yay \o/

Node interface

I'm not too sure on how to approach this one yet. For most of the use cases I can think one, the plan would be to create a new type that will extend an existing node type.

Like: create an HLSVideoNode, or a new destination node that does not output the content but register it using a MediaRecorder...

Do you think we need to define a strong interface for people to create a new node from scratch? Can something NOT extend from GraphNode at the bare minimum?

Devtools

Using new node types will not break the devtools or the render graph that is generated by it will be labeled as "Unknown". We need to find a way to find a way to access all the node types available to be able to label them correctly on the devtools

PTaylour commented 6 years ago

Like it.

What are your thoughts on registering classes or factories vs importing factory functions, like this:

import { createHlsNode } from 'my-nodes'

const hlsNode = createHlsNode(vc, manifestUrl)

pros

cons

germain-gg commented 6 years ago

Definitely prefer your factory approach. Makes a lot of sense. I'm all in if it helps to catch dead code automatically

Thanks for your input