This is section dives deeper into how the plugin system works, this is mostly useful if you want to build your own plugins or controls.
Plugins are Svelte components that implement the plugin interface and add some functionality/feature to the player. They are managed by the
PluginsManager whose responsible for validating, adding, removing, rendering and registering them. It can be accessed through the player by calling
Validate the plugin to make sure it implements the plugin interface.
Mount the plugin on the DOM using
The rendered instance is registered with the managers
Registry (more on this later).
Registry dispatches an event to the root so the player can attach the plugin to itself.
When it's time (player/plugin is being destroyed) the plugin is unmounted from the DOM.
Registry is notified via a callback that the component has been destroyed and deregisters it.
Registry dispatches an event to the root so the player can deattach the plugin.
Plugins and their child values are registered using a
Registry. A registry is essentially a container who holds unique id references to values. Majority of time, these values are rendered plugin instances (the result of mounting a Svelte component to the DOM), or other registries (known as subregistries).
The problem that the registry solves is, how do we access and communicate between semi-unrelated component trees that are dynamically rendered and removed. Basically, if we create a plugin called
MySuperDuperPlugin, then how does
OtherSuperDuperPlugin listen for when it becomes available and get a reference to it.
The registry pattern is the approach used in Vime to solve the mentioned problem.
All you need to know is:
In Vime, there is a global object called a registry in which all shared values are stored.
These objects can be nested in one another to create subregistries.
Subregistries are created by plugins.
You access subregistries through the root registry, stored under their respective plugin
The only "special" subregistry is the
vPlugins registry which holds all plugin instances.
You can access the root registry by calling
You can access the plugins subregistry by calling
Player creates a root
Registry on initialization.
Once the player has mounted, the
PluginsManager is mounted and creates a subregistry (the
PluginsManger renders plugins and registers their instances in its subregistry.
Finally, each plugin may decide to create its own subregistry to register child components or anything else.
Now that you understand how the plugin system works, you can start building your very own plugin.