Player APIs (BrightScript & Ja...
BrightScript-JavaScript Object...
BSMessagePort
6min
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 docid 5lt7hkssemqlniau7kva3 methods boolean postbsmessage(in dictionary message) 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 var bsmessage = new bsmessageport(); bsmessage onbsmessage = function(msg) { for(name in msg data) { console log('### ' + name + ' ' + msg data\[name]); } } in brightscript, the rohtmlwidget postjsmessage() method can be used to post a message to javascript widget postjsmessage({ param1 "data1", param2 "data2", param3 "data3" }) examples the following script will send a collection of properties to brightscript 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 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