Controlling volume through links

I develop one of the syrinscape extensions for Fantasy Grounds. In the recent post on Roll20, Ben mentioned being able to adjust volume via links. Is this possible to trigger via the syrinscape-online:// links that the player picks up? or only through the REST API? If it is possible, can I get some information on how to format the links to do the adjustment.

thanks

Sorry @mattekure, we missed this one!

Iā€™ll ask @sonofconan to send over the details :slight_smile:

@mattekure We do not have any official API documentation to release right now. If you open Chrome dev tools while using the master interface and filter by XHR, then trigger some actions (e.g. change element volume) you will see the necessary call.

For example, changing an element volume triggers a POST request to /online/frontend-api/elements/357/set_current_volume/ with a payload {"current_volume":0.34}.

Changing the global volume triggers a PATCH request to /online/frontend-api/state/global/ with a payload {"volume":0.51}.

You could make these calls from FG, if FG is able to make POST and PATCH requests, and you add an auth_token to the URL.

I suspect that FG is unable to make these requests directly, and passing URLs to the OS to handle would open a browser window.

Our bundled (on Windows) proxy application that handles syrinscape-online:// URLs will only make a HEAD request to our server and cannot currently be used for other API calls.

Iā€™ll add this to our list as a feature request, but I donā€™t know when we might get to it. Strong integrations with 3rd parties are important to us, though.

Thanks for the info. FG currently does not have the capability to do POST or PATCH requests natively, but I have requested that functionality be added. If/when the ability gets added to either FG or the proxy application, I will be sure to add a volume control to the FG extension.

1 Like

I too have created an API for Syrinscape controls inside of Encounter+ an iOS based application. Since my integration with their application is third party, I only have access to the local cutom.js and web browser (safari) web page based integration. I can make read-only GET calls, but CORS is restricting POST when using ā€œContent-Typeā€, ā€œapplication/jsonā€ headers. In my case, just being able to set the max volume of an Element would be really nice. The reason being, is that elements remember their last played volume level, so if I want to start an element, and the volume is too low, then it seems like nothing is happening. Ideally, it would be nice to be able to control volume through a GET call, or at least have a call that can maximize the volume of an element. Is there any way to do this with a GET?

Hey never mind. I got it to work! I still have to do a post, but switching to using a content type of ā€œapplication/x-www-form-urlencodedā€ and then sending text ā€œcurrent_volume=1ā€ works!!! It gets around the CORS stuff.

For those trying to do this, my client side javascript looks like this:

var authToken=[Replace with your own];
function maxVolume(URI){
var xmlhttp = new XMLHttpRequest();
var element = URI.split(ā€™/ā€™)[6];
var authURI = ā€˜https://syrinscape.com/online/frontend-api/elements/ā€™ + element + ā€˜/set_current_volume/?auth_token=ā€™ + authToken;
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
var status = xmlhttp.status;
// if you need to do something with the returned value
}
}
xmlhttp.open(ā€œPOSTā€,authURI,true);
xmlhttp.setRequestHeader(ā€œContent-Typeā€, ā€œapplication/x-www-form-urlencodedā€);
var s = ā€˜current_volume=1ā€™
xmlhttp.send(s);
}

And the URI that is passed to the function is the URL that is found in the CSV file or the link on the controls without the ?auth_token=[your token]

This should work with all ā€œelelmentsā€ and not ā€œmoodsā€ since moods donā€™t support individual volume levels that I know of. I suspect something similar will work for the master volume control.

I donā€™t know if this helps you, but we have just released an API endpoint that controls the global volumes (and responds to GET requests). The format for the links looks like this:

https://syrinscape.com/online/frontend-api/global-volume/[Ā±]AMOUNT/?auth_token=INSERT_TOKEN_HERE

You can use the [Ā±] to make relative adjustments or leave these out to specify a volume specifically. e.g. you may want to try these:

Reduce global volume by 5%
https://syrinscape.com/online/frontend-api/global-volume/-0.05/?auth_token=INSERT_TOKEN_HERE
Increase global volume by 5%
https://syrinscape.com/online/frontend-api/global-volume/+0.05/?auth_token=INSERT_TOKEN_HERE
Set global volume to 100%
https://syrinscape.com/online/frontend-api/global-volume/1.00/?auth_token=INSERT_TOKEN_HERE

There are analogous links for /global-oneshot-volume/.

Let me know if you have any questions!

Is this API recognized through the syrinscape online client, or only through the web call? As described, I could add this to my Fantasy Grounds extension, but clicking them would open a web page each time. If the URLs can be changed to the syrinscape-online://syrinscape.com/ā€¦ format and work, then it will be much better for implementation as a new browser window will not need to be opened.

Absolutely! Anything that works as a link accessible from GET request should work with the syrinscape-online:// protocol, just replace https with syrinscape-online, and it should work great. Give it a go and let us know how it works for you :slightly_smiling_face:

This works a treat. Iā€™ve built it into my Syrinscape Extension for Fantasy Grounds and everything just works. Thanks for adding these.

2 Likes