Plugins and Parsers
This page describes how to use two advanced BrightAuthor and BrightAuthor:connected features: custom autorun plugins and parser scripts. These instructions assume a certain level of familiarity with BrightScript. This is not a comprehensive guide to writing custom scripts for BrightAuthor or BrightAuthor:connected; it is meant to provide a general outline and best practices for writing those scripts.
Plugins
Plugins allow you to add script extensions to a standard presentation autorun. For example, you can use plugins to change variable values, extract information from a .txt, .csv, .xml, or .json file to display it onscreen, change the contents of a playlist, or change how the presentation responds to external input.
Plugins have two primary benefits over custom autoruns:
They can be easily inserted into multiple presentations, including newer and older versions of the same presentation.
They are not dependent on a certain autorun or firmware version, greatly reducing the complexity involved in updating custom BrightScript deployments.
BrightAuthor:connected Autorun Plugins
To designate one or more custom plugins in BrightAuthor:connected:
If you are a Content Cloud user, upload your plugin to the server through the Content upload (see Content | Scripts). If you are a Control Cloud user, skip directly to step 2 to add a plugin to the presentation.
Attach it to your presentation (see Presentation Settings | Script Plugin[inlineExtension])
If needed, refer to Plugin Message Eventto trigger state changes.
BrightAuthor Autorun Plugins
BrightAuthor (classic) versions that are older than 3.7 do not support plugins.
To designate one or more custom plugins in BrightAuthor:
Navigate to File > Presentation Properties > Autorun.
Select the Add Script Plugin button.
Give the plugin a name (which must be the same as the
<plugin_name>
described in the initialization function below).Select Browse to pick a .brs file and select Ok. Once you load the plugin, it can interact with the presentation using Plugin Message events or Send Plugin Message commands.
See the BrightSign GitHub page for BrightAuthor:connected/BrightAuthor plugin examples.
Plugin Structure
Plug-in scripts must include an initialization function in the form of <plugin_name>_Initialize()
. Actions that take a lot of time should not be done in the initialization routine, because actions in the routine are synchronous. Instead, start a timer that will be caught by the plugin event handler soon after the routine runs, and execute the longer code segment there. For example, instead of unzipping a file in the initialization routine, do it through the plugin event handler with a timer started in the routine.
The initialization function is passed three parameters:
msgPort As Object
userVariables As Object
o As Object
: This is the .bsp associative array from the autorun. It is required for the initialization function to return an associative array.
To process events, the plugin script must provide a ProcessEvent()
 function that is a member of the associative array returned by the initialization function described above. The ProcessEvent()
 function is passed a single event object. The function then returns a Boolean indicating whether or not the autorun should continue processing the event object: The function will return True if it handles the event and the standard autorun should not continue processing the event.
The associative array that defines the object must also include an objectName
 entry that defines the name of the object.
The following is an example of a script plugin file named pizza.brs:
Function pizza_Initialize(msgPort As Object, userVariables As Object, bsp As Object)
print "pizza_Initialize - entry"
print "type of msgPort is ";type(msgPort)
print "type of userVariables is ";type(userVariables)
PizzaBuilder = newPizzaBuilder(msgPort, userVariables, bsp as Object)
return PizzaBuilder
End Function
Function newPizzaBuilder(msgPort As Object, userVariables As Object, bsp as Object)
PizzaBuilder = { }
PizzaBuilder.msgPort = msgPort
PizzaBuilder.bsp = bsp
PizzaBuilder.userVariables = userVariables
PizzaBuilder.objectName = "PizzaBuilder_object"
PizzaBuilder.ProcessEvent = pizza_ProcessEvent
return PizzaBuilder
End Function
Function pizza_ProcessEvent(event As Object)
print "pizza_ProcessEvent - entry"
print "type of m is ";type(m)
print "type of event is ";type(event)
' swallows timer events - telling the autorun not to process them
if type(event)= "roTimerEvent" then
return true
else
return false
endif
End Function
Receiving a Plugin Message
The following example code shows how to write a script that receives a Send Plugin Message Command from the autorun. This code listens for a message sent to the plugin named “Pizza” and then prints the message. This example uses debug output instead of print statements. Print statements only show up in the serial console, while debug statements show up in the system log.
Function pizza_ProcessEvent(event As Object)
m.bsp.diagnostics.printdebug("@@ pizza_ProcessEvent - entry")
m.bsp.diagnostics.printdebug("@@ type of m is " +type(m))
m.bsp.diagnostics.printdebug("@@ type of event is " +type(event))
if type(event) = "roAssociativeArray" then
if type(event["EventType"]) = "roString"
if event["EventType"] = "SEND_PLUGIN_MESSAGE" then
if lcase(event["PluginName"]) = "pizza" then 'the plugin name is case sensitive'
pluginMessage$ = event["PluginMessage"]
m.bsp.diagnostics.printdebug("@@ received pluginMessage " + pluginMessage$)
return true
endif
endif
endif
endif
return false
End Function
Sending a Plugin Message
The following example code shows how to write a script that sends a message string to trigger a Plugin Message event.
print "pizza_ProcessEvent - entry"
print "type of m is ";type(m)
print "type of event is ";type(event)
if type(event) = "roTimer" then
pluginMessageCmd = CreateObject("roAssociativeArray")
pluginMessageCmd["EventType"] = "EVENT_PLUGIN_MESSAGE"
pluginMessageCmd["PluginName"] = "Pizza"
pluginMessageCmd["PluginMessage"] = "toppings"
m.msgPort.PostMessage(pluginMessageCmd)
return true
endif
return false
End Function
Parsers
Parsers can perform many of the same custom functions as plugins (for example, extracting information from a .txt, .csv, .xml, or .json file to display it onscreen or changing the contents of a playlist); however, rather than being triggered by a command or being associated with an event, parsers are associated with a downloaded data feed or a file on the SD card. This means that any function that is triggered by an event must be written as a plugin, not a parser.
A parser does not need to work exclusively with the data in the feed associated with it. Once the parser starts running, you can use it to delete a file on the storage, send a UDP command, or download another feed or file.
You can find examples of BrightAuthor parsers on the BrightSign GitHub page:
RSS Converter:Â Converts a standard RSS feed into the same format as a BSN Live Text feed, allowing you to display RSS feed items by index number in a Live Text state.
Live Text Title and Description: Allows you to display both the title and description of an RSS item in a Live Text State.
Parser Scripts – RSS
Parser scripts allow you to manipulate data sets from incoming RSS feeds. You can create RSS parser scripts for a wide array of system and presentation functions. You can designate a parser for an RSS feed in BrightAuthor:connected Presentation Settings > Support Content or in BrightAuthor File > Presentation Properties > Data Feeds.
Important
The parser file must have a .brs extension.
The following parameters can be used with an RSS parser subroutine:
xmlFileName$
: The name of the XML file. This value is provided by the presentation autorun.itemsByIndex
: An array of the descriptions. The script should fill in this array if the Live Text object is using the “item index” to display items from this feed.itemsByTitle
: An associative array of titles, descriptions. The script should fill in this array if a Live Text object is using the “item title” to display items from this feed.userVariables
: An associative array of current User Variables (which are provided by the autorun). This is provided in case you want to analyze or modify the User Variables.
The following piece of example code can be used to parse RSS text:
Parser Scripts – MRSS
You can use a script to parse non-MRSS feeds and provide the data in a format that can be used by Media RSS Feed states in BrightAuthor:connected or BrightAuthor.
To designate a parser for an MRSS feed in BrightAuthor:connected, go to Presentation Settings > Support Content > Data Feeds.
To designate a parser for an MRSS feed in BrightAuthor, go to File > Presentation Properties > Data Feeds.
Important
The parser file must have a .brs extension.
The following parameters can be used with an MRSS parser subroutine:
fileName$
: The name of the feed file to be parsed. This value is provided by the presentation autorun.items
: An array of associative arrays representing MRSS items to be played by Media RSS Feed states. This array is empty upon entry to the parser subroutine and should be filled by the script. When the parser subroutine exits, the autorun will supply the data in the array to Media RSS Feed states for playback. See the Item Array Specification section below for a list of associative-array parameters.metadata
: An associative array containing optional metadata items pertaining to the entire playlist/feed.
Items Array Specification
The parser script should add associative arrays to the items
 array–each associative array represents a single media item to be played back. The order of items in the array specifies the order of playback.
Each associative array consists of one or more key-value pairs. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:
Key | Value | Example | Notes |
---|---|---|---|
| A download URL for the file | "www.brightsign.biz/images/myfeedpic1.jpg" | Required – The item will be ignored if this value is not present. |
| video | image | audio | document | "video" | Suggested – If the |
| video/*, audio/*, image/*, text/html, application/widget | "video/*" | Suggested – If the |
| The display duration in seconds | "30" | Optional – This value applies to images only, and has no effect on other media types. If not specified, this value defaults to "15". |
| The value for the MRSS Title field | "myfeedpic1" | Optional |
| The value for the MRSS Description field | "$5.99" | Optional |
| The size of the file in bytes | "942061" | Optional |
| A unique value for the file | "ab05caf" | Optional – When this value changes, the player will re-download the file. |
| An associative array of arbitrary key-value pairs | {key1:"custom field A", key2:"custom field B"} | Optional – Use this associative array to include custom MRSS fields. |
Metadata Specification
The metadata
object is an empty associative array when the parser subroutine is entered. This associative array can accept optional key-value pairs that represent properties for the entire feed. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:
Key | Value | Example | Notes |
---|---|---|---|
| A title for the feed | "myfeed1" | |
| The time-to-live in minutes | "5" | This value represents how long the feed will be stored (whether it's utilized by the presentation or not) before being refreshed. The user will also set an Update Interval when adding the Data Feed to the BrightAuthor presentation; if the |