Skip to content

Plugin API

Derrick edited this page Apr 28, 2016 · 1 revision

#Plugin API Each plugin when loaded creates its own div container in the browser. This API allows for plugins running a 'persistent script' to modify its web container. These API calls are handled through web socket communications; that is, each 'persistent script' will need to utilize some web socket library to make these API calls. When a 'persistent script' is executed, the first argument provided to the binary is the protocol name that the PluginDaemon generated specifically for these external API calls. The second argument given to the script is the port number to use. Plugins are assumed to be running on the same machine as the server, so the server address is to be the localhost (127.0.0.1).

##API Call List

write <text>
    Replace plugin client div text with <text>.

innerdiv <string>
    Set plugin client div content to <data>. <data> is string data and may
    contain HTML.

clear
    Clears the content of the plugin client's div container.

setcss <string>
    Applies one or more CSS styles to the plugin-client div or its child elements. <string> is formatted as such
    'cssProperty=Value;..." and can contain multiple CSS styles with semi-colons separating each style.

getcss <string>
    Returns the value of the specified CSS styles in <string>. <string> is a comma separated list of 
    CSS attributes:
    'width,height,top,left,...'.

jsPluginCmd <json>
    Allows one to call a JavaScript function with arguments. Requires the plugin to have a JavaScript file with a
    class defined ('js-main-obj' setting in 'plugin.conf') containing the function to call. 
    <JSON> must be formatted
    as such:
        '{fn: <yourFunction>, args: <data>}'
    where <yourFunction> is the name of the function to call, and <data> is one argument of data that is passed
    to <yourFunction>. For multiple arguments, one can just pass in JSON.

##Making an API Call Once a plugin connection is made to the server, API calls can be made by sending a stringified JSON through the established socket connection.

The JSON string should be formatted as such:

{command:"<API ACTION>", data: "<ASSOCIATED DATA>"}

For example, modifying the CSS of the plugin-client div:

{command:"setcss", data:"backgroundColor='red'"}

Clone this wiki locally