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