You have a couple of options.
Instead of an if, you can use a switch statement. It's slightly cleaner. See https://www.w3schools.com/js/js_switch.asp on how to do a switch statement.
If your incoming messages are consistently formatted, then you can just parse that message, and use that.
So if your message is always "mic_on <number> Seat <number>", you could use the split function:
Something like this:
var str = event.getBytesAsString()
// split the string on spaces
var res = str.split(" ");
// parse out each part of it.
var micCommand = res[0];
var micNumber = res[1];
var seatCommand = res[2];
var seatNumber = res[3];
// send the command
ogscript.fireGPI('Seat ' + seatNumber, '[state]', true);
Here is the link to the split command: https://www.w3schools.com/jsref/jsref_split.asp
There are multiple ways of parsing strings. Split is an easy one, but you could also look for the last space in the command and grab everything after it.
If you look here: https://www.w3schools.com/jsref/jsref_obj_string.asp, you will find all the javascript string functions that work in DashBoard. I often use a combination of indexOf() or lastIndexOf() to find things, and substring() to grab just a part of a string.
------------------------------
Ben Gatien
Ross Video
------------------------------
Original Message:
Sent: 04-19-2021 16:22
From: Martin Karlsson
Subject: Function for custom camera panel
Hi all!
I'm building a panel that will interface Panasonic AW-RP 150 and Shure DIS-CCU conferencing system with 50 + microphones.
The idea is to trigger a camera preset by activating a microphone, but the camera operator should also be able to trigger a camera position by pressing a button on the panel which will be a graphical representation of the room the microphones are in.
I've gotten this to work by frankensteining an api for the camera system I found on git hub.
function tellPTZpos(preset) { var address = ogscript.getPrivateString('hosts', 'PTZ.address'); var CGIUrl = '/cgi-bin/aw_cam?cmd='; var CGICommand = 'XPM:01:' + preset; CGICommand = CGICommand + '&res=1'; var message = 'GET ' + CGIUrl + CGICommand + ' HTTP/1.1\r\n' + 'Host: ' + address + ' \r\n' + 'Connection: close\r\n' + '\r\n?'; rosstalk.sendMessage(address, 80, message, callback); } function callback(success, sentData, resultString, exception) { ogscript.debug(resultString); } function onProductionLoad() { params.setValue('ptzaddress', 0, ogscript.getPrivateString('hosts', 'PTZ.address')); }
and a listener I found on here for the conferencing system
if (event.isConnectEvent()) {ogscript.debug("connection established");}if (event.isMessageEvent()){ogscript.debug("message received");var message = "<html>"var message = message + "host: " + event.getRemoteHost();var message = message + "<br>port: " + event.getRemotePort();var message = message + "<br>string: " + event.getBytesAsString();var message = message + "<br>bytes: " + event.getBytes();var message = message + "<br>parsed: " + event.getBytes();var message = message + "</html>"ogscript.rename("eventString", message); }if (event.isDisconnectEvent()) {ogscript.debug("connection closed");}if (event.getBytesAsString() == "mic_on 1 Seat 1"){ogscript.fireGPI('Seat 1', '[state]', true); //global = true/false to notify all of DashBoard or just this panel}
as you can se I've used an if statement to fire a GPI triggering the button corresponding to the camera preset. That will eventually be a lot of if statements. Not so pretty. Any ideas how to make this better?
Also, I would like a prompt for each position whenever a button is being triggered by activating a microphone. Is that possible?
Hope this makes sense.
/Martin