2.4.0 • Published 14 days ago

@dytesdk/plugin-sdk v2.4.0

Weekly downloads
-
License
-
Repository
-
Last release
14 days ago

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 event | true |
EventsDescription
newChatMessageEmmited when someone sends a new chat message
pluginDataEmitted when data is sent from meeting to plugin
peerJoinedEmitted when a new peer joins the meeting
peerLeftEmitted 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

    ParamTypeValueRequired
    peerIdstringId of the peer you want to enable the plugin for.true
    await plugin.enablePluginForUser(peerId);
  • Disable plugin for a user

    ParamTypeValueRequired
    peerIdstringId 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 default | false |

    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 default | false |

    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 * as key to 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 peerId is 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 ID

    NOTE: Returns undefined if the initiator has left the meeting.

    const peerId = await plugin.getPluginInitiatorId();
  • Get plugin initiator's User ID

    const userId = await plugin.getPluginInitiatorUserId();
  • Get meeting title

    const title = plugin.getDisplayTitle();
  • Send a chat message

    ParamTypeValueRequired
    messagestringbody of the text messagetrue
    typestringtexttrue
    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.

2.4.0

14 days ago

2.3.3

15 days ago

2.3.2

17 days ago

2.3.1

17 days ago

2.2.0

10 months ago

2.1.3

10 months ago

2.1.2

11 months ago

2.1.1

11 months ago

2.1.0

11 months ago

1.10.5

1 year ago

1.10.4

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.10.6

1 year ago

2.0.3

2 years ago

2.0.4

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.4.4

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago