Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Conversion to new format.

 

Panel
borderColor#3D3D3D
bgColor#F4F4F4
titleColor#3D3D3D
borderWidth0
titleBGColor#3D3D3D
borderStylesolid

ON THIS PAGE

Table of Contents
indent20px

This object allows for an associative array to be passed from JavaScript to BrightScript (or vice versa). Only one BSMessagePort instance may be created per roHtmlWidget instance.

The JavaScript equivalent is messageport.

Methods

Note
Code Block
boolean PostBSMessage(in Dictionary message)
Note
title

The PostBSMessage() method does not accept nested dictionaries. The same is true for the PostJSMessage() BrightScript method.

Events

The following event occurs when a message is sent from BrightScript to JavaScript. It will appear as a MessagePortEvent event.

  • onbsmessage

MessagePortEvent

This event contains a single field:

  • readonly

  • attribute

  • any

  • data;

The following script will iterate over all the fields received in the event:

Code Block
languagejs
linenumberstrue
var bsMessage = new BSMessagePort();

bsMessage.onbsmessage = function(msg)
{
    for(name in msg.data)
    {
    	console.log('### ' + name + ': ' + msg.data[name]);
    }
}

...

Code Block
widget.PostJSMessage({ Param1: "Data1", Param2: "Data2", Param3: "Data3" })

Examples

The following script will send a collection of properties to BrightScript:

Code Block
linenumbers
languagejstrue
function myFunction()
{
    var bsMessage = new BSMessagePort();
    bsMessage.PostBSMessage({complete: true, result: "PASS"});
}

The message will appear in BrightScript as an roHtmlWidgetEvent. In this case, the GetData().reason equals "message" and GetData().message contains the roAssociativeArray.

Code Block
languagejs
linenumberstrue
while not finished
    ev = mp.WaitMessage(30000)
    if type(ev) <> "roHtmlWidgetEvent" then
        print type(ev)
        stop
    end if
    payload = ev.GetData()
    print payload
    print "Reason: "; payload.reason
    if payload.reason = "message" then
        print "Message: "; payload.message
        if payload.message.complete = invalid then
            stop
        else if payload.message.complete = "true" then
            finished = true
            if payload.message.result = "PASS" then
                print "Test passed"
            else
                print "Test failed: "; payload.message.err
                stop
            end if
        end if
    end if
end while