跳到主要内容

IEventListenerPlugin

The plugin that is given the access to the portal events.

Example​

The plugin class implements IEventListenerPlugin and registers a listener for the room creation event in the constructor. ONLYOFFICE Apps calls getEventListenerItems to subscribe the handlers to the portal events.

import {
type IEventListenerItem,
type IEventListenerPlugin,
Events,
Actions,
ToastType,
} from "@onlyoffice/docspace-plugin-sdk";

class Plugin implements IEventListenerPlugin {
eventListenerItems: Map<string, IEventListenerItem> = new Map();

constructor() {
this.addEventListenerItem({
key: "room-create-listener",
eventType: Events.ROOM_CREATE,
eventHandler: () => {
return {
actions: [Actions.showToast],
toastProps: [{
type: ToastType.success,
title: "A new room has been created"
}]
};
}
});
}

addEventListenerItem = (item: IEventListenerItem): void => {
this.eventListenerItems.set(item.key, item);
};

getEventListenerItems = (): Map<string, IEventListenerItem> => {
return this.eventListenerItems;
};
}

Methods​

addEventListenerItem()​

addEventListenerItem(item: IEventListenerItem): void;

Add a new event listener item to the collection.

Parameters​

ParameterTypeDescription
itemIEventListenerItemThe event listener item to add, containing key, eventType, and eventHandler

Returns​

void

getEventListenerItems()​

getEventListenerItems(): Map<string, IEventListenerItem>;

Get all registered event listener items.

Returns​

Map<string, IEventListenerItem>

A Map containing all registered event listener items, where keys are item identifiers

Properties​

PropertyTypeDescription
eventListenerItemsMap<string, IEventListenerItem>Stores a collection of elements where the keys are the key parameters from the EventListenerItem objects. A list of event listeners is generated based on this collection.