bigbluebutton / bigbluebutton-html-plugin-sdk

BigBlueButton Plugin SDK
GNU Lesser General Public License v3.0
7 stars 5 forks source link

DOM element interaction - useChatMessageDomElements #28

Closed TiagoJacobs closed 7 months ago

TiagoJacobs commented 11 months ago

We want to create a new type of plugin hook "DOM element interaction", that will expose dom elements to a plugin, so it can interact with the element.

Example usages:

Initial hook:

The initial hook of this type will be the useChatMessageDomElements that will provide the dom element of a specified chat message id. Other hooks of this type can appear in the future.

Sample implementation:

Using the useLoadedChatMessages hook ( https://github.com/bigbluebutton/bigbluebutton-html-plugin-sdk/issues/27 ), observe chat messages that contains a word "@Tiago" and whenever it's found, add a <span style="color: red"> and </span> around it.

Pseudo-code:

const loadedChatMessages = pluginApi.useLoadedChatMessages ( );

const messagesWithMentions = loadedChatMessages.filter ( chatMsg => chatMsg.content.indexOf("@Tiago") );

const messageIds = messagesWithMentions.map(chatMsg => chatMsg.id);

const chatElements = pluginApi.useChatMessageDomElements(messageIds);

chatElements.forEach(
    chatElement => {
        chatElement.innerHtml = chatElement.innerHtml.replace("@Tiago", '<span style="color: red">Tiago</span>');
    }
);

Things to consider:

GuiLeme commented 7 months ago

As the https://github.com/bigbluebutton/bigbluebutton-html-plugin-sdk/pull/65 and https://github.com/bigbluebutton/bigbluebutton/pull/19420 are merged in, this issue is completed