Player APIs (BrightScript & Ja...
JavaScript APIs
syncmanager
7 min
as of brightsignos 8 2 10, the syncmanager object provides synchronization capabilities for video walls and other deployments that require closely calibrated interaction among players syncmanager idl \[ constructor(string networkinterface, string domain, string multicast address, unsigned multicast port) ] interface syncmanager { attribute boolean leader; attribute string networkinterface; readonly attribute string domain; attribute boolean encrypted; attribute boolean encryptionkeyisobfuscated; writeonly attribute string encryptionkey; void synchronize(in string id, in unsigned long ms delay); void close() }; object creation to create an syncmanager object, first load the brightsign/syncmanager module using the require() method const bssyncmanager = require("@brightsign/syncmanager"); let sm = new bssyncmanager(network interface, domain, multicast address, multicast port); the constructor for a sync manager object takes four arguments network interface string string the network interface (for example, "eth0") domain string string the domain identifier used to distinguish among different rosyncmanager instances multicast address string string the multicast address to which synchronization messages are communicated multicast port int int the multicast port to which synchronization messages are communicated syncmanager synchronize() void synchronize(in string id, in unsigned long ms delay) broadcasts a time stamped message to other players this method is used on the leader unit only the message will be rebroadcasted every second to allow follower units that are powered on late to catch up the network message contains the sync id, as well as the domain and a timestamp the timestamp is created at the point when this method is called; however, it can be offset by passing a non zero ms delay value, allowing synchronization points to be set slightly in the future and giving the client enough time to switch video files and perform other actions the identifier parameter allows the script on the leader unit to pass a filename, or some other useful marker, to the follower units as part of the synchronization message this method returns the message that is sent out so that the leader can access the timestamp the synchronization message is sent over all available networks (including wifi), but follower units will use only the first message received because synchronization can involve follower units seeking to catch up with the playback of a leader unit, we recommend using the more efficient mov/mp4 container format when synchronizing video files transport stream files (mpeg ts) are also supported, but they must begin with a presentation timestamp (pts) of 0 program stream files (mpeg ps) are not supported close() void close() shuts down the instance, freeing the underlying sync manager syncmanager properties leader boolean boolean a read/write attribute to set/get whether the sync manager is a leader, or a follower networkinterface string string a read/write string attribute to set/get which network interface the sync manager uses (for example, " eth0 ", " wifi0 ") the networkinterface parameter can be "" to allow any network interface domain boolean boolean a read only string attribute which returns the domain for the sync manager encrypted , encryptionkey and encryptionkeyisobfuscated are used to configure the use of encryption with the sync manager encrypted boolean boolean a read/write attribute that controls whether the sync manager uses encryption if true , encryption is enabled on the unit encryptionkeyisobfuscated boolean boolean a write only string attribute which is used to set the key used for encryption contact mailto\ support\@brightsign biz to learn more about generating a key for obfuscation and storing it on the player encryptionkey string string a write only string attribute which is used to set the key used for encryption synchronizing video playback when using syncmanager for video synchronization, sync events are broadcast repeatedly ( 1 hz) to ensure all players receive them your code must track the sync id and only respond to the first occurrence of each new id to avoid reloading the video on every repeated event leader example \<html> \<video id="one" hwz="on"> \<source id="one src" src="pirates mov"> \</video> \<script> // create the sync manager with provided multicast settings var sync = new bssyncmanager("domain1", "224 0 126 10", 1539); // configure as leader sync setasleader(1); // track current sync id to avoid reloading on every event var currentsyncid = null; sync onsyncevent = function (e) { console log("leader received sync event domain ", e domain, "id ", e id, "timestamp ", e iso timestamp); // only respond to new sync ids (new sync sessions) if (e id !== currentsyncid) { currentsyncid = e id; var videoelement = document getelementbyid("one"); videoelement setsyncparams(e domain, e id, e iso timestamp); videoelement load(); videoelement play(); console log("leader video synchronized to sync id ", e id); } // subsequent events with the same id are ignored }; function starttimer() { settimeout(function () { restartleader(); }, 30000); } function restartleader() { // synchronize the videos to start playing in 1000ms // this creates a new sync session with a new id sync synchronize("sync event " + date now(), 1000); starttimer(); } restartleader(); \</script> \</html> follower example \<html> \<video id="one" hwz="on"> \<source id="one src" src="pirates mov"> \</video> \<script> // create the sync manager with provided multicast settings var sync = new bssyncmanager("domain1", "224 0 126 10", 1539); // follower does not call setasleader (defaults to follower mode) // track current sync id to avoid reloading on every event var currentsyncid = null; sync onsyncevent = function (e) { console log("follower received sync event domain ", e domain, "id ", e id, "timestamp ", e iso timestamp); // only respond to new sync ids (new sync sessions) if (e id !== currentsyncid) { currentsyncid = e id; var videoelement = document getelementbyid("one"); videoelement setsyncparams(e domain, e id, e iso timestamp); videoelement load(); videoelement play(); console log("follower video synchronized to sync id ", e id); } // subsequent events with the same id are ignored // the video element handles ongoing synchronization internally }; \</script> \</html> without tracking `currentsyncid`, the video will reload every second when repeated events arrive, disrupting playback