I can confirm this code is working for me using a “baseURL”.
This is an example URL that is sent to Multi System Reactor to run a “Global Reaction” (Scene).
http://192.168.1.101:8111/api/v1/reaction/re-kofxitkx/run
This is the value I have specified for the button in its EventTrigger (Reaction ID).
This is the code for the HTTP script:
plugin.Name = "HTTPMSRGlobalReactions";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;
var http = new HTTPClient();
var baseUrl = "http://192.168.1.101:8111/api/v1/reaction/";
function onChangeRequest(device, attribute, value) {
console.log("Sending " + value + " for " + device.Name);
switch (attribute) {
case "HttpCommand":
http.get(baseUrl + value + "/" + "run");
break;
default:
break;
}
}
function onConnect() {
}
function onDisconnect() {
}
function onPoll() {
}
function onSynchronizeDevices() {
var switch1 = new Device();
switch1.Id = "1";
switch1.DisplayName = "Switch 1";
switch1.Capabilities = ["Switch"];
switch1.Attributes = [];
plugin.Devices[switch1.Id] = switch1;
}
So now I no longer need to specify the full URL in each buttons EventTrigger, I just have to now specify the Multi System Reactor’s “Reaction” ID only.