Accessing the Syrinscape API with javascript

Hi guys

I already wrote @benjamin about this, but I decided to write in here, as maybe someone else had the same problem and already solved it.

I am currently trying to build a remote control for Syrinscape, that I can integrate into foundryvtt (https://foundryvtt.com/), therefore I am trying to access the API with javascript.
While I can get the play and stop functions to run without problems, I cannot read from the API remotely.

Here is my basic fetch command (replace AUTH with the Auth token)

fetch(ā€œhttps://www.syrinscape.com/online/frontend-api/soundsets/29/?format=json&auth_token=ā€+AUTH)
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
generates an error:

ā€œAccess to fetch at 'https://www.syrinscape.com/online/frontend-api/soundsets/29/?format=json&auth_token=AUTH from origin ā€˜http://127.0.0.1:5500ā€™ has been blocked by CORS policy: Response to preflight request doesnā€™t pass access control check: No ā€˜Access-Control-Allow-Originā€™ header is present on the requested resource. If an opaque response serves your needs, set the requestā€™s mode to ā€˜no-corsā€™ to fetch the resource with CORS disabled.ā€

when I now set the mode to no-cors, i only get the opaque response with no data in it.
Can anyone point me the right way, so I can access the API from a 3rd party script?

Thanks in advance.

@sonofconan Any thoughts?

When I route the request through a CORS Proxy like: https://github.com/Rob--W/cors-anywhere I can access the data just fine

I might have found a workaround. i can build all the links I need when I have the Auth key and the information provided in syrinscape_remote_control_links_Sven_.csv
Either i can use the public version, or I have to do regular updates of my scripts manually.
A Public version would of course be easier :slight_smile:

Iā€™m really glad someoneā€™s building this! Iā€™ve been putting sound links I want to use in journal entries and individual macros manually, and that works well for a scene or very often used sounds. But, Iā€™d prefer something purpose-built in the long run.

Itā€™s my first foray into proper coding. But i managed to parse the csv. So I might get a prototype running soon.

Iā€™d be happy to help test if you need a guinea pig.

1 Like

I hit a small milestone today. I managed to create a module that reads in the csv and outputs the values to the console.
Not much but baby steps :smiley:

4 Likes

Im super interested in this and your work here.

2 Likes

I was a bit busy the last few days, so I didnā€™t make much progress. I will have some time off soon though and I plan to use that to continue on the module.

Just keep in mind that this is only a remote. It wonā€™t be able to pipe audio into fvtt directly. That would need a way to add your own player and AFAIK this isnā€™t planned yet.

1 Like

Small Update:

I got the Parsing off the CSV down, now I need to create the control menus from that data:

  • Using Categories as filters for Soundsets
  • Using the Soundset as Filter for Moods
  • Generating the Links for each Mood
  • Generating a Stop Button (I think I need to use the Silence Soundset for that)
  • Building a nice Menu around all that.

I would also love to find a way, so i can add the Soundsets to Journal Entries and the like in order to start them Quickly.

I shall keep posting updates here.

3 Likes

Thanks for the update @chrome itā€™s looking really promising :slight_smile:

1 Like

Hello, Iā€™m a Senior Software Engineer. Iā€™m interested Iā€™m helping. I build APIs.

2 Likes

Heya,

Grab us at support at syrinscape dot com and weā€™ll set you up with the info you need. :slight_smile:

1 Like

Any updates on this? I am eager to try out whatever anyone might have in the works.

Unfortunately I still lack the skill to work with the API as it is right now. I placed my findings in the hands of some other Foundry Devs - hopefully they will be able to pick up th torch.

A few others have picked up the torch and eadorin (patreon ā€œFoundry Workshopā€) has a basic mod working (still in alpha), but unfortunately there is no current support for turning Foundry into a minion that broadcasts the sound output by the DMā€™s Syrinscape Online Player. One can make an interface / GUI in Foundry that allows one to duplicate the functionality of the Master Interface (so you donā€™t have to switch tabs to change sounds, though you do have to manage an additional window within Foundry). Your players, though, still have to have an Online Player downloaded and connected to your Syrinscape instance, and that Control Panel / Online Player manages things like syncronicity and runs in addition to Foundry.

Itā€™s disappointing to be sure, given the issues a lot of us have with our players struggling around the Online Player / connecting to the DM / a-sync issues / dropped-sounds, but that is where things stand at present.

Hi,

Iā€™ve been working on a custom remote much like the OP, and run into the same CORS issues. I am not a javascript developer, so Iā€™m on a bit of a learning curve - apologies if I ask a stupid question!

It seems (from the little I understand!) that any XHR request from javascript will not be able to return a response - is that right?

Is it possible to consider relaxing the CORS policy, at least for some request URLs? Iā€™m hoping that maybe @sonofconan will be able to give some pointers, if itā€™s not a bother!

Thanks,
Tom

@yamahito thatā€™s correct. Iā€™ll reply here where we have made the necessary changes on our end to relax CORS requirements. But I canā€™t say when that might be.

In the meantime, you would need to implement your own local proxy. For example a Python web server that handles your requests and then makes its own request to our server directly without CORS restrictions, or the Node.js proxy linked to earlier in this thread:

1 Like

Thanks for the quick reply!

Iā€™ll have a think about the node.js proxy, but as it may require more hosting, I may just try to be patient :wink:

1 Like