@dytesdk/plugin-sdk
Plugin SDK by Dyte
Explore the docs »
Report Bug
•
Request Feature
Table of Contents
About The Project
Plugin SDK let's you build custom plugins that work with all of Dyte's core SDKs.
Built With
Getting Started
Prerequisites
- npm
Installation
npm install @dytesdk/plugin-sdk
Usage
A plugin object can be created using DytePlugin.init() method.
const plugin = await DytePlugin.init();
The plugin object provides several methods and features to interact with Dyte's core SDKs with ease.
Table of Contents
Event Emitter on DytePlugin
Listen for plugin events
Param Type Value Required event string newChatMessage
pluginData
peerJoined
peerLeft
custom eventtrue Events Description newChatMessage Emmited when someone sends a new chat message pluginData Emitted when data is sent from meeting to plugin peerJoined Emitted when a new peer joins the meeting peerLeft Emitted when a peer leaves the meeting You can also listen for custom (user defined) events
plugin.on(event, (data) => { console.log('do something') })Alias:
plugin.addListener(event, (data) => { console.log('do something') })Emit custom events to all users
plugin.emit('myAwesomeEvent', data)
Methods specific to staggered plugins
Staggered plugins are plugins that enabled only for specific users. By default these are only enabled for the user who initiated the plugin.
Enable plugin for a user
Param Type Value Required peerId string Id of the peer you want to enable the plugin for. true await plugin.enablePluginForUser(peerId);Disable plugin for a user
Param Type Value Required peerId string Id of the peer you want to disable the plugin for. true await plugin.disablePluginForUser(peerId);Enable plugin for all users
await plugin.enablePluginForAll();
Methods specific to data store
Data store is a temporary database provided with Plugin SDK. It has a lot of capabilities and features, like data history and CRDT support to help you manage your data better.
Each entry in the store is a key-pair value.
Create a store
Param Type Value Required storeName string Store Name true local string flag to specify weather the store is local or global.
Local stores are not accessible by other users.
false by default.false const newStore = await plugin.stores.create( storeName, local );Get a store
Param Type Value Required storeName string Store Name true const store = plugin.stores.get(storeName);Get all stores
Returns all stores, local and global.
const stores = plugin.stores.all();Add item to store
Param Type Value Required key string Identifier for item in store true value any data to be stored in the store true clearHistory boolean boolean flag to clear history on set action.
false by defaultfalse const store = plugin.stores.get(storeName); store.set(key, value, clearHistory);Get an item from store
Param Type Value Required key string Identifier for item in store true const store = plugin.stores.get(storeName); store.get(key);Get all data from store
const store = plugin.stores.get(storeName); store.getAll();Update item in store
Param Type Value Required key string Identifier for item in store true value any data to be stored in the store true clearHistory boolean boolean flag to clear history on update action.
false by defaultfalse const store = plugin.stores.get(storeName); store.update(key, value, clearHistory);Subscribe to store changes
Param Type Value Required key string Identifier for item in store true NOTE: pass *askeyto all changes on the store.store.subscribe(key, (data) => { console.log(data); });Unsubscribe to store changes
Param Type Value Required key string Identifier for item in store true store.unsubscribe(key);
Other Methods
Get room data
const room = await plugin.getRoomState();Get peer data
Param Type Value Required peerId string id of the peer you want to disable the plugin for. (not userId)false NOTE: Returns current peer's (self) data if no
peerIdis passed.const peer = await plugin.getPeerInfo(peerId); const self = await plugin.getPeerInfo();Get all peers
const peers = await plugin.getJoinedPeers();Get room name
const name = plugin.getRoomName();Get plugin initiator's
Peer IDNOTE: Returns undefined if the initiator has left the meeting.
const peerId = await plugin.getPluginInitiatorId();Get plugin initiator's
User IDconst userId = await plugin.getPluginInitiatorUserId();Get meeting title
const title = plugin.getDisplayTitle();Send a chat message
Param Type Value Required message string body of the text message true type string texttrue await plugin.sendChatMessage(message);Get plugin meta data
Returns the plugin meta data along with the entire plugin store.
const data = await plugin.getPluginData();
Contributing
We really appreciate contributions in the form of bug reports and feature suggestions. Help us make Dyte better with your valuable contributions on our forum .
License
All rights reserved. Dyte Inc.