Plugin Introduction
Deepstream at is core is a collection of plugins, handlers and a protocol that interact with each to provide a powerful set of features that can power large realtime applications.
There are currently a total of 7 plugins that are required by deepstream to run, all of which have defaults built in. Before we dive into those, let's first look at the core PluginAPI:
interface PluginOptionsConfig {
... all options go here ...
}
interface DeepstreamPlugin {
constructor (pluginOptions: PluginOptionsConfig, services: DeepstreamServices, config: DeepstreamConfig)
// The name of plugin to be shown when loaded succesfully
public abstract description: string
// An async callback to indicate the plugin is ready to use,
// for example when setting up a connection to a database
public async whenReady (): Promise<void> {}
// An optional API that is called after whenReady. This helps
// plugins remove logic from the constructor, which is sometimes
// a useful pattern
public init? (): void
// An async call back that indicates when the connector has shutdown
// succesfully
public async close (): Promise<void> {}
}
Implementing this API is all that is needed for deepstream to register the plugin. Obviously just having this code wouldn't add any functionality! Deepstream offers a powerful set of interfaces that allow developers to modify nearly every aspect of functionality or add your own. Let's look at the different types, and remember to take a deeper dive into each section to see an example implementation!
Authentication
Authentication provides three pieces of functionality to deepstream:
- Validates whether a user is allowed to login
- It returns serverData, which is sensitive information used by deepstream to aid permissioning
- It returns clientData, which is data that is forwarded to the client on login
To see a guide of an Authentication plugin that only allows users to login with a preconfigured token please look here
Permissioning
Permissioning checks every single message that goes through the system to ensure the sender is allowed to perform the operation. Deepstream offers a powerful permissioning language called Valve that allows users to write rules that map against simplified representations. However, users can generate their own permissioning logic, which can allow you to interact with third-party APIs or implement smarter caching depending on your use case.
To see a guide of a Permission plugin that only allows users to interact with actions that have their userId in the name please look here
Cache
The cache plugin provides a way for deepstream to optimally store, retrieve and delete data in a simple (usually key/value) data store. Deepstream offers a few out of the box for most of the popular techs, like Redis, Memcache, Hazelcast and in memory. However you can easily implement your own by implementing it's simple API.
The main performance benefit you always want to implement with cache layers is to seperate the version and values so that retrieving thousands of records in one go is significantly faster!
To see a guide of a Cache plugin that stores data in memory please look here
Storage
The storage API is a subset of the Cache API. It's used alot less frequent than the cache layer, once for each write, but only once for a record thoughout the records entire lifetime!
To see a guide of a simple storage plugin that stores it's data please look here. Word of advice though, please don't use this system in production unless your okay with insanely slow speeds.