Player APIs (BrightScript & Ja...
JavaScript APIs
cec
9min
the cec object lets you send messages over cec (consumer electronics control) cec idl interface receiveevent { attribute string type; attribute array\<byte> data; }; callback receiveeventcallback = void (receiveevent event); interface cec { promise\<void> send(array\<byte> data); void addeventlistener(string type, receiveeventcallback callback); void removeeventlistener(string type, receiveeventcallback callback); }; object creation to create a cec object, load the @brightsign/cec module using the require() method const cecclass = require('@brightsign/cec'); const cec = new cecclass(); set the specific hdmi port for players with more than one output as follows const cecclass = require("@brightsign/cec"); const cec = new cecclass("hdmi 2"); //modify this to be 'hdmi 1', 'hdmi 2', 'hdmi 3', and 'hdmi 4' as needed cec event receiveevent the cec reception path is implemented as a receive event the receive message has two generic fields type the event type "receive" data array cec frame method send() promise\<void> send(array\<byte> data) sends messages over cec data array\<byte> array\<byte> the cec frame port name () promise\<void> the parameters for this optional argument are default the default output for the platform, normally hdmi 1 hdmi x x is a number from 1 up to the number of hdmi ® outputs on the platform earc the default for the au335 as of brightsignos 8 2 55, the cec implementation for au series 5 products will reply to these messages with the correct data, without involving the script cec msg get cec version cec msg abort cec msg give device power status cec msg give osd name cec msg give device vendor id cec msg give features cec msg give physical addr cec msg user control pressed cec msg user control released cec msg report physical addr example see the following example to send or receive cec messages see bscectransmitter docid\ ma pnb9n4i6nin ixnr0r for an example that turns a display on and off const cecclass = require('@brightsign/cec'); const cec = new cecclass(); var initiatoraddress = 0x40; var opcodegetversion = 0x9f; var opcodeversion = 0x9e; var version = ""; function onrxevent(packet) { let frame = packet data; let opcode = frame\[1]; console log("frame opcode " + opcode); console log(json stringify(frame)); if (opcode == opcodeversion) { version = frame\[2] tostring(16); console log("version " + version); } } function cecversion() { return new promise(async (resolve) => { version = ""; let buffer =\[]; buffer\[0] = initiatoraddress; buffer\[1] = opcodegetversion; cec send(buffer) then(async function() { await (async () => new promise(resolve => settimeout(resolve, 1000)))(); console log("version received " + version); resolve(); }) catch (function(error) { console log("ooops " + error); resolve(); }); }); } async function runtest() { cec addeventlistener("receive", onrxevent); await cecversion(); }