Player APIs (BrightScript & Ja...
JavaScript APIs
registry
10 min
the registry object allows you to read from and write to the player registry (i e the persistent memory) the registry consists of named registry sections, and each registry section contains entries (key/value pairs) registry idl interface registry { promise\<string> read(string sectionname, string key); promise\<registrysection> read(string sectionname); promise\<registryobject> read(); promise\<void> write(string sectionname, string key, string value); promise\<void> write(string sectionname, registrysection section); promise\<void> write(registryobject); promise\<void> flush(); }; object creation to create a registry object, first load the brightsign/registry module using the require() method then create an instance of the registry class var registryclass = require("@brightsign/registry"); var registry = new registryclass(); registry use this interface for registry read/write operations all section and key names are canonicalized to lowercase read() promise\<string> read(string sectionname, string key) returns the string registry value associated with the specified key you must also specify the registry section where the key is stored promise\<registrysection> read(string sectionname) returns the specified registry section in the following format registrysection {entry key} promise\<registryobject> read() returns all registry sections in the following format registryobject {section name} {entry key} write() promise\<void> write(string sectionname, string key, string value) writes a single registry entry to the specified registry section promise\<void> write(string sectionname, registrysection section) writes the specified registry section to the registry if the registry section does not exist, it will be created; otherwise, the entries will be added or updated in the existing registry section (preexisting registry entries that are not specified in the write operation will be unaffected) promise\<void> write(registryobject) writes the specified registry sections/entries to the registry registry sections and entries that do not exist will be created, and existing entries will be updated (preexisting registry sections/entries that are not specified in the write operation will be unaffected) the single entry write() method will not perform well when used to write multiple entries successively for optimal performance, use the single section write() method to write multiple entries to a single section and the full registry method to write to multiple sections sixty seconds at most after a write to the registry, or before an orderly reboot, the newly written data will be automatically be written out to persistent storage if for some reason, a set of registry changes must be written immediately, then the flush() method should be called after the last one while it is possible to read the entire registry, modfiy the return value, and write it back into the registry, this is not a recommended practice it may cause race conditions among different parts of the system that are attempting to write to the registry at the same time flush() promise\<void> flush() flushes the contents of the registry immediately to persistent storage to delete a registry entry or section, assign it a null value example var registryclass = require("@brightsign/registry"); var registry = new registryclass(); //reads the entire registry to the log registry read() then(function(registry) { console log(json stringify(registry)); }); //reads the contents of the "networking" registry to the log registry read("networking") then( 	function(registry){console log(json stringify(registry));}); //writes multiple entries to multiple sections registry write({networking {ssh "22", http server "8080"}, autorun {devicesetupcomplete "1"}} ) then( 	function(){console log("write successful");}); //updates a single section registry write("networking", {ssh "22", http server "8080"}) then( 	function(){console log("write successful");}); //deletes a registry section and entry, and creates a new section registry write({networking {ssh "22", http server\ null}, autorun\ null, section1 {test "val"}} ) then( 	function(){console log("write successful");});