Player APIs (BrightScript & Ja...
...
Networking Objects
roHttpServer
13 min
this object allows for processing of restful http/https requests from remote urls to the embedded web server of the brightsign player many of the requests are provided to the script as rohttpevent objects for handling the javascript equivalent is node js object creation the rohttpserver object is created with an roassociativearray createobject("rohttpserver", parameters as roassociativearray) the associative array can contain the following parameters port int int the port number of the embedded web server https roassociativearray roassociativearray a set of https configuration parameters key file string string the name of a file containing the private key in pem format if neither the passphrase nor obfuscated passphrase are passed, then the key file must be unencrypted certificate file string string the name of a file containing the certificate in pem format passphrase string string the passphrase to decrypt the key file obfuscated passphrase string string the obfuscated passphrase to decrypt the key file contact mailto\ support\@brightsign biz to learn more about generating a key for obfuscation and storing it on the player bind to interface string string or int int accept connections on the specified network interface only using a string interface name (e g “eth0” for ethernet, “wlan0” for wifi, “lo” for loopback) is preferred an integer is supported for backward compatibility with 0 for ethernet, 1 for wifi and 32767 for loopback this is available as of bos 9 1 92 if the key and certificate are contained in a single file, it may be passed as the certificate file (and the key file can be omitted) example server = createobject("rohttpserver", { port 443, https { certificate file "cert pem", passphrase "sekrit" } }) ifhttpserver each “add” handler method described below takes an associative array as its parameter values in the associative array specify how the handler behaves see the table at the end of this section for common key\ value pairs getfailurereason() as string yields additional useful information if an rohttpserver method fails addgetfromstring(parameters as roassociativearray) as boolean causes any http get requests for the specified url path to be met directly with the contents of the "body" member of the parameter associative array the mime type (and potentially the entire character set) should be specified if the request is expected to come from a web browser the request is handled entirely within the rohttpserver method; no events are sent to the message port addgetfromfile(parameters as roassociativearray) as boolean causes any http get requests for the specified url path to be met directly from the specified file you should always specify the mime type (and possibly the character set) if you expect the request to come from a web browser the request is handled entirely within the rohttpserver method; no events are sent to the message port addgetfromfolder(parameters as roassociativearray) as boolean constructs a dynamic handler that serves up static files, which will appear as children of the defined storage folder this method accepts an associative array with the following parameters folder the file path of the folder that will act as the root directory of the server if this parameter is absent, everything on the storage device will be served url prefix the url prefix under which files will be served if this parameter is absent, the url will match from root filters an array of filters each filter is an associative array with the following parameters note that if "re" and "ext" parameters are absent, the filter will match everything re the regular expression to match against the request url ext the extension to match against the leaf file of the request url headers an associative array containing arbitrary headers to be included with the automatic response content type the contents of the "content type" header included with the automatic response this cannot be set in the same filter as the headers the mime type and character set can be specified together (e g "text/plain; charset=utf 8") you must define all of the folder content types for the folder to be correctly uploaded to the server for example mimetypes = \[{ext " html", content type "text/html;charset=utf 8"},{ext " js", content type "text/javascript;charset=utf 8"},{ext " css", content type "text/css;charset=utf 8"},{ext " png", content type "image/png"},{ext " otf", content type "font/otf"}] server addgetfromfolder({ url prefix "/getfolder", folder "example", filters mimetypes}) addgetfromevent(parameters as roassociativearray) as boolean requests that an event of type rohttpevent be sent to the configured message port this occurs when an http get request is made for the specified url path addposttostring(parameters as roassociativearray) as boolean requests that an event of type rohttpevent be sent to the configured message port this occurs when an http post request is made for the specified url path use the rohttpevent getrequestbodystring() method to retrieve the posted body addposttofile(parameters as roassociativearray) as boolean requests that, when an http post request is made to the specified url path, the request body be stored in a temporary file according to the parameters\["destination directory"] value in the associative array when this request is complete, an rohttpevent event is sent to the configured message port use the rohttpevent getrequestbodyfile() method to retrieve the name of the temporary file if the file still exists at the time the response is sent, it will be automatically deleted however, if the player reboots or loses power during the post process, the file will not be deleted for this reason, we recommend using a dedicated subdirectory as the "destination directory" and wiping this subdirectory during startup (using deletedirectory() ) before adding handlers that refer to it addposttoformdata(parameters as roassociativearray) as boolean requests that, when an http post request is made to the specified url path, an attempt be made to store form data (passed as application/x www form urlencoded or multipart/form data ) in an associative array that can be retrieved by calling the rohttpevent getformdata() method addmethodfromevent(parameters as roassociativearray) as boolean requests that an event of type rohttpevent be sent to the configured message port unlike addgetfromevent() , this method can support arbitrary http methods the http method is specified using the method member in the associative array addmethodtofile(parameters as roassociativearray) as boolean requests that, when an arbitrary http request is made to the specified url path, the request body be stored in a temporary file according to the parameters\["destination directory"] value in the associative array the http method is specified using the method member in the associative array when the request is complete, an rohttpevent event is sent to the configured message port use the rohttpevent getrequestbodyfile() method to retrieve the name of the temporary file if the file still exists at the time the response is sent, it will be automatically deleted addmethodtostring(parameters as roassociativearray) as boolean attempts to support an arbitrary http method the request body is placed in a string and an event is raised this makes the request body available via the rohttpevent getrequestbodystring() method a response can be sent in the same manner as the addgettoevent() method setupdwslink(title as string) as boolean generates a tab in the docid\ qxt4yhey7iej m9dh73wm that links directly to the base \<ip address\ port> of the rohttpserver instance the passed string specifies the title of the tab example server1 setupdwslink("my aws link") server2 setupdwslink("my other aws link") parameters for "add" handler methods the following table describes common key\ value pairs for "add" handler methods true 100,219,100left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type ifmessageport setport(port as romessageport) posts messages of type rohttpevent to the attached message port