Hi Mark,
… it’s a long time - but today I’ve found some time to experiment if I could address the issue you’ve found differently; as my updated setup suffers from the same issue you described. I do not have the option to change the DNS configuration & I use the web interface via OH exclusively. Thus I’ve decided to updated the .html page of SqueezeBox-Server :-).
If of interest I can post more details; here a general overview:
1.) I’ve created an item and a rule to provide the MAC of the current primary player.
2.) … some JS to get the item from OH & to update the cookie (I know - not gold standard, as I misuse async API synchronously … but I was happy when it finally did what I needed
) :
var baseURL = "../";
function GetOpenHABItem(item) {
var itemUrl = baseURL.concat("rest/items/").concat(item).concat("/state/");
var itemValue = null;
$.ajax({
url : itemUrl,
data : {},
async : false,
success : function( data ) {
if (data != "NULL") {
itemValue = data;
}
}
});
return itemValue;
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
3.) Some additional js to replace the cookie:
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://HAUS:9000/index.html?player=" + GetOpenHABItem("ItemAudioCurrentPlayerId"), false ); // false for synchronous request
xmlHttp.send( null );
4.) Inserted the stuff into the SqueezeBox code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://haus:8080/static/openHAB.js"></script>
<script type="text/javascript">
baseURL = "http://haus:8080/"
</script>
<script type="text/javascript" src="http://haus:8080/static/setPlayerIdCookie.js"></script>
4.) enable CORS by setting the following line in runtime.cfg
org.eclipse.smarthome.cors:enable = true
needs some testing now - but as I took me quite some time to figure some of the stuff our I share it in the hope it saves someone else some time.
If more details are required or any comments, let me know
. Btw.: Is the a wiki for OH2, or a preferred place for examples?
with kind regards,
Patrik