Player APIs (BrightScript & Ja...
JavaScript APIs
htmlwidget
17min
the htmlwidget object allows you to instantiate additional html browsers htmlwidget idl interface htmlwidgetevent { attribute string type; \[optional] attribute string url; }; callback htmlwidgeteventcallback = void (htmlwidgetevent event); \[ constructor(htmlwidgetparams params) ] interface htmlwidget { void postmessage(object data); void close(); void raise(); void lower(); void addeventlistener(string type, htmlwidgeteventcallback callback); void removeeventlistener(string type, htmlwidgeteventcallback callback); }; interface htmlwidgetparams { attribute htmlwidgetrect rect; attribute string url; \[optional] attribute nodeparams node; \[optional] attribute javascriptinjection javascriptinjection; \[optional] attribute bool bsobjects; \[optional] attribute storage storage; \[optional] attribute string inspectorserver; \[optional] attribute bool inputenabled; \[optional] attribute security security; \[optional] attribute string transform; \[optional] attribute string hwzdefault; \[optional] attribute bool interceptreloads; }; interface htmlwidgetrect { attribute long x; attribute long y; attribute long width; attribute long height; }; interface nodeparams { attribute bool enabled; \[optional] attribute array\<string> arguments; }; interface javascriptinjection { \[optional] attribute javascriptinjectiondetaillist documentcreation; \[optional] attribute javascriptinjectiondetaillist documentready; \[optional] attribute javascriptinjectiondetaillist deferred; }; interface javascriptinjectiondetail { \[optional] attribute string world; \[optional] attribute string source; \[optional] attribute string uri; \[optional] attribute string code; }; interface storage { attribute string path; attribute long quota; attribute bool forcesharedstorage; attribute bool forceunsharedstorage; }; interface security { \[optional] attribute bool insecureoriginenabled; \[optional] attribute bool cameraenabled; \[optional] attribute bool desktopcaptureenabled; \[optional] attribute bool audiocaptureenabled; \[optional] attribute bool insecurehttpsenabled; }; object creation to create a htmlwidget object first load the brightsign/htmlwidget module using the require() method then create an instance of the htmlwidget class var htmlwidgetclass = require("@brightsign/htmlwidget"); var htmlwidget = new htmlwidgetclass({ rect {x 0, y 0, w 640, h 480 }, url "https //brightsign biz" }); htmlwidgetevent available as of bos 9 0 168 see javascript event handling docid\ surgnnhz666sb1wh6pbd9 the cause of the event can be one of the following "load started" the html widget has started loading a page "load finished" the html widget completed loading a page "load error" the html widget failed to load a page use the url key to identify the failing resource and the message key to retrieve some explanatory text htmlwidget postmessage() void postmessage(object data) sends an asynchronous message to the child browser process if the child process has an @brightsign/messageport object open, this message will generate a "bsmessage" event on that object the payload can be any javascript object but must be only one level deep (that is, it cannot include other nested objects) close() void close() shuts down the child browser process this is equivalent to calling window\ close() from inside the child browser node js® parent processes won't exit automatically and the html widget can't be garbage collected until the widget is closed raise() void raise() changes the stacking order of html widgets lower() void lower() changes the stacking order of html widgets htmlwidgetparams this interface contains the html widget parameters rect htmlwidgetrect htmlwidgetrect contains the set parameters of the size and positioning of the widget url string string the url to use for display node nodeparams nodeparams optional optional contains the parameters used to specify added node js functionality javascriptinjection javascriptinjection javascriptinjection optional optional contains the parameters that specify javascript code to inject at different initialization points bsobjects bool bool optional optional enables or disables brightscript javascript objects docid\ urrxhu7l v9ea zhy0jv3 this value is disabled by default storage storage storage optional optional used to configure html storage inspectorserver string string optional optional enables the debugging webpages docid 4qlk1krr1cnx7xypwxry5 , which allows you to debug javascript applications while a webpage is running starting in bos 8 5 31 you will need to also set the enable web inspector registry key (in the "html" section) to enable the javascript console to access the console, navigate to the player ip address at the specified port number see this page https //trac webkit org/wiki/webinspector for documentation relating to the javascript console in “enable web inspector”, "1" will allow the inspector and "0" or not present will disable it a reboot will be needed for these changes to take effect (if you enable/disable this through the ldws ui, it may trigger a reboot to apply the change) for security reasons, enable web inspector should only be used in non production presentations make sure to disable javascript console before publishing to a production environment in the chromium version found in bos 8 5 31 and beyond, the javascript console will log information in memory even when you are not connected to the inspector this will consume memory until the player runs out, which will result in a crash inputenabled bool bool optional optional enables mouse/touchscreen events this value is false by default security security security optional optional override chromium security checks transform string string optional optional sets the screen orientation of content in the widget (note that the coordinates and dimensions of the rorectangle containing the widget are not affected by rotation) the following values are accepted "identity" there is no transform (i e the widget content is oriented as landscape) this is the default setting "rot90" the widget content is rotated to portrait at 90 degrees (clockwise) "rot180" the widget content is rotated to portrait at 180 degrees (clockwise) "rot270" the widget content is rotated to portrait at 270 degrees (clockwise) hwzdefault string string optional optional specifies the default html video docid\ e6ujleh69q0jmmv8kytrp behavior this value is off by default to enable it, set it to on interceptreloads bool bool optional optional prevents window\ location reload() or similar constructs from taking effect in the browser instead the parent will receive a reloadrequested event htmlwidgetrect this interface allows you to set the size and positioning of the widget rectangle x long specifies the x coordinate for the widget y long specifies the y coordinate for the widget width long sets the width of the widget in pixels height long sets the height of the widget in pixels nodeparams this interface allows you to enable node js and define the parameters of the node js command line arguments enabled bool bool enables node js docid\ vlskfvzequ04pd58rvxam on the widget the value is false by default arguments array array optional optional an array specifying command line arguments javascriptinjection use this interface to inject user scripts into the javascript engine documentcreation javascriptinjectiondetaillist javascriptinjectiondetaillist optional optional the script will run as soon as the document is created this behavior is not suitable for any dom operation documentready javascriptinjectiondetaillist javascriptinjectiondetaillist optional optional the script will run as soon as the dom is ready this behavior is equivalent to the domcontentloaded event firing in javascript deferred javascriptinjectiondetaillist javascriptinjectiondetaillist optional optional the script will run when the page load finishes javascriptinjectiondetail this interface defines the user scripts that are used by the javascriptinjection interface exactly one of the source , uri , or code fields must be defined world string string optional optional isolates user scripts into different worlds this string can be assigned one of the following values application , user , or main (see this page https //doc qt io/archives/qt 5 6/qwebenginescript html#scriptworldid enum for more details); if the world parameter is not included in the array, " application " is selected by default source string string optional optional deprecated use uri or code instead uri string string optional optional if defined, this must contain either a "file" uri, or a "data" uri with one of the following supported formats "data\ text/javascript;charset=utf 8;" "data\ text/javascript;charset=utf 8;base64," "data\ text/javascript;charset=us ascii;" "data\ text/javascript;charset=us ascii;base64," code string string optional optional if defined, the content will be executed as javascript code storage this interface allows you to define the following html storage parameters path string string the folder used by local storage applications such as the javascript storage class quota long long the size (in bytes) allotted to all local storage applications (including indexeddb) if the storage path is specified without a storage quota, chromium defaults to reserving 1gb plus 10% of the total size of the storage device forcesharedstorage bool bool allows http/https loaded urls to share local storage if they are loaded from the same domain forceunsharedstorage bool bool prevents file loaded urls from sharing storage data can be corrupted if two html widgets access the database at the same time, but some applications rely on this type of access use the force unshared storage flag to avoid sharing on local urls if you experience data problems, or use the force shared storage flag to allow sharing on http/https sites (if both flags are set, file storage is separated and http storage is not ) security overrides chromium security checks for these parameters insecureoriginenabled bool bool optional optional ignore insecure origins and treat them as enabled cameraenabled bool bool optional optional enables webpage access to usb cameras connected to the player (access is disabled by default) this allows support for webrtc applications desktopcaptureenabled bool bool optional optional enables desktop capture audiocaptureenabled bool bool optional optional enables audio capture insecurehttpsenabled bool bool optional optional ignore security errors when connecting to insecure https hosts (insecure https is disabled by default) enabling this feature makes the player insecure; it is not suitable for production environments and should only be used for testing with bos 8 2 and later (chromium69 and later), several new cors checks have been added security params websecurity or enablesecurity(false) do not disable all these checks use the following registry setting instead registry write html disable web security 1 this flag will take effect on all htmlwidget instances, as opposed to previous flags which are only effective on the instance they are called on to write this to the registry using roregistrysection docid\ ffm73tjd bthw4 p 0jvg reghtml = createobject("roregistrysection", "html") reghtml write("disable web security", "1") reghtml flush()