Adding functionality
The <name>.plugin.js file contains all of the logic and code for the plugin. It is called upon both by the plugin state and also by user interaction.
An example plugin.js file without any functionality is shown below.
This basic plugin.js code contains multiple parts which will be explored below.
This method is used by the webapp2 application when the plugin is first instantiated. This method will be called with two observables.
participants$
This observable is used to receive updates about participants within the plugin. An example of subscribing to this observable is below.
conferenceDetails$
This observable is used to receive updates about the conference within the plugin. An example of subscribing to this observable is below.
This method is used by the webapp2 application when the plugin is unloaded. It should be used to clean up the plugin, for example, used to stop any intervals or timers that may be running.
At the bottom of the above example, there is a block of code that is used to register the plugin and map the methods inside of the plugin to be accessed by the webapp2 application. an example code block looks like below.
A breakdown of the method parameters is listed below.
- id - this is the id of the plugin from the plugin.package.json file. This must match that file.
- load - this is a mapping of the load method to expose it for the webapp2 application
- unload - this is a mapping of the unload method to expose it for the webapp2 application
In the plugin.package.js file, there is an option to call a method on a button push. An example of this is below, in this example,m there is an action that is calling the "changeConferenceLayout" method on push.
The above example from the plugin.package.json file would be paired with the following code in the plugin.js file.
In the above example, there are two parts to make this button push work. First there is a method, with the same name as the action parameter in the plugin.package.json file. In this example it is showing a message in the console that says "changeConferenceLayout was pushed".
Secondly, there is a mapping within the registerPlugin call that maps the method for access by webapp2 application. In the below example, notice the line that says changeConferenceLayout: changeConferenceLayout. This is the mapping.
Do you have any suggestions? Get in contact with us here.
