frondeus / fvtt-syrin-control

Syrinscape Online Control plugin for FoundryVTT
MIT License
13 stars 4 forks source link

Errors in console and no sound played #98

Closed farling42 closed 1 year ago

farling42 commented 1 year ago

Describe the bug

I've just installed module, and imported some sound sets. No errors/warnings during import.

When I press play on one of the soundsets I get the error reported in the image.

Details

OS: Node server on Ubuntu (Oracle Cloud) Browser: Chrome 112.0.5615.138 on Windows 11 Foundry: 10.241 Module: 0.4.3

Logs

image

farling42 commented 1 year ago

Expanded error:

image

farling42 commented 1 year ago

I have https://syrinscape.com/online/cp/ open and see the "Started mood" for the selected mood appear in the Activity Log.

Rubengam3r commented 1 year ago

When trying to play elements from a mood I get the following error in the console. Console works fine for the global

Workaround: I imported again and it seems to work fine

egonil commented 1 year ago

At least for me, the issue is that the call to the syrinscape.com API is using the wrong auth token when trying to play elements.

Ex:

 :authority: syrinscape.com
 :method: GET
 :path: /online/frontend-api/elements/2942/play/
 :scheme: https
 accept: */*
 accept-encoding: gzip, deflate, br
 accept-language: en-US
 authorization: Token cb8d5a2c3ff741b69e16c33a5f9d021a
 origin: http://localhost:30000
 referer: http://localhost:30000/
 sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="104"
 sec-ch-ua-mobile: ?0
 sec-ch-ua-platform: "Windows"
 sec-fetch-dest: empty
 sec-fetch-mode: cors
 sec-fetch-site: cross-site
 user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) FoundryVirtualTabletop/10.303.0 Chrome/104.0.5112.102 Electron/20.1.0 Safari/537.36
Request URL: https://syrinscape.com/online/frontend-api/elements/2942/play/
Request Method: GET
Status Code: 403 
Remote Address: 104.26.4.213:443
Referrer Policy: strict-origin-when-cross-origin

{"detail": "User cannot play Witch tower collapse. Not authorised."}
Uncaught (in promise) StatusError: request returned a 403 status
    at headlessPlayer.88c4c86b231dc842cc3d.js:136:809
    at Object.authorizedFetchUrl (headlessPlayer.88c4c86b231dc842cc3d.js:136:825)
(anonymous) @ headlessPlayer.88c4c86b231dc842cc3d.js:136
authorizedFetchUrl @ headlessPlayer.88c4c86b231dc842cc3d.js:136

versus

Request URL: https://syrinscape.com/online/frontend-api/moods/737/play/
Request Method: GET
Status Code: 200 
Remote Address: 104.26.4.213:443
Referrer Policy: strict-origin-when-cross-origin
:authority: syrinscape.com
:method: GET
:path: /online/frontend-api/moods/737/play/
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US
authorization: token e359c77681b8ad6b446391f3e8177f79c121ed1c
if-modified-since: Tue, 18 Jul 2023 21:24:18 GMT
if-none-match: W/"14b22a984f283d49dba1746d3d779ed5"
origin: http://localhost:30000
referer: http://localhost:30000/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="104"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) FoundryVirtualTabletop/10.303.0 Chrome/104.0.5112.102 Electron/20.1.0 Safari/537.36

{"status": "playing"}

For the elements play, authorization: Token cb8d5a2c3ff741b69e16c33a5f9d021a For the moods play, authorization: token e359c77681b8ad6b446391f3e8177f79c121ed1c The elements play call uses the wrong auth "Token" and capitalizes "token" differently. The elements call appears to be using a different code path to provide the value.

And yes, I regenerated the auth token shown above.

egonil commented 1 year ago

const t={authorizedFetchUrl:async(e,t={},n=!0)=>{t.headers={...t.headers,Authorization:`Token ${j.config.token}`}; https://github.com/frondeus/fvtt-syrin-control/blob/ef6ed3e44be99b1e484f58a9e5a12231082f6a04/libs/syrinscape/headlessPlayer.88c4c86b231dc842cc3d.js#L136

This appears to be a library from Syrinscape. It is pulling a value from j.config.token and capitalizing Token.

The issue is presumably that j.config.token is never set to use the utils.authToken value.

frondeus commented 1 year ago

First of all sorry for long waiting time for any response...

Let's see: Are you experiencing those bugs as GMs or as regular players?

There is a difference in how I trigger elements and moods. Elements are triggered via a built-in syrinscape player, while moods are triggered via manual HTTP request.

And the elements are not working correctly. But if you trigger it, you have to be a GM. Hmm...

I could replace the code that triggers elements with a manual HTTP request if that's working. Also, I guess I see a possibility that you triggered the element mood while the syrinscape player was still inactive (and had the wrong auth token). It was inactive because it needs an audio context that can be retrieved only after a while when the user moves the mouse or clicks something...

I will have to debug it properly, but it should not be that hard thanks to your investigations. Thanks!

egonil commented 1 year ago

I was checking out how the module worked with syrinscape as the GM. I haven't tried it as a player.

I believe I've tried various elements both with and without a mood being active.

Another thing I noticed was the "authorization: Token cb8d5a2c3ff741b69e16c33a5f9d021a" value was the same for element play attempts even across world restarts. I didn't find where that (seemingly fixed) value came from.

egonil commented 1 year ago

Hmm. Now I can't figure out how to reproduce the issue.

egonil commented 1 year ago

To reproduce:

Create new world (I used pf1, but I don't think it would matter) Launch world. Add SyrinControl module and restart. Add Syrinscape Auth Token to SyrinControl module settings. Go to Playlists menu. Click Import Soundsets. Find an accessible sound set with elements (I used Pathfinder 1e: The Dragon's Demand: Wizard's Estate, but unlikely to matter). Click on the Soundset Elements button. Switch to the sounset's elements tab. Play any elements. Note 403 error response to GET request to /online/frontend-api/elements/.../play/ (OPTIONS request will succeed) Note authorization Token is not the value from the module settings.

The headless players token is now set to the wrong value until the world is restarted. Moods will work, but elements will not.

To contrast with working version: Import Playlists, and play any mood before trying to play an element. Note that the headless player now uses the correct token and the elements now play.

egonil commented 1 year ago

Workaround:

Always play a mood before trying to play an element.

frondeus commented 1 year ago

Thanks for all the comments! I really appreciate detailed steps :)

frondeus commented 1 year ago

@egonil I released https://github.com/frondeus/fvtt-syrin-control/releases/tag/0.5.2 Before I publish it on foundry-vtt, I would love to hear the feedback if that helps.

To install this pre-release module, please install it manually by setting manifest link to https://github.com/frondeus/fvtt-syrin-control/releases/download/0.5.2/module.json

egonil commented 1 year ago

Elements before moods works now. Moods before elements still works.

All good.

frondeus commented 1 year ago

Great. Released officially 0.5.2 then :) Closing as done.

If you see any regressions and errors, please create new issue.