zekroTJA / yuri2

Faster, harder, louder! The best Discord sound board in whole North Korea - with Web Interface!
Apache License 2.0
9 stars 5 forks source link

Webinterface rest and websocket #9

Open JackLeEmmerdeur opened 4 years ago

JackLeEmmerdeur commented 4 years ago

Hello again.

As you suggested in issue #8 to update go, my dummy-self couldn't find the time to update Go manually and managed it with this helper. The "undefined: sort.SliceStable" is gone and I possess a nice "yuri2" executable now.

What I've done:

In application.yaml:

In config.yaml:

Started the Lavalink.jar: No error.

Started yuri:

I invited yuri2 to my discord. It entered the building.

Compiled the web-folder with ng.

When I started the development-server, the userinterface is shown on localhost:4200 but it fails to connect to rest and websockets-server on port 8080. Is that the wrong port maybe? I changed it meanwhile to 2333, for testing in rest.service.ts and ws.service.ts. Chrome is giving me this:

Bildschirmfoto

This all looks very promising execpt the last step and as soon as I'm able to broadcast the first sound in my server, I make the installation permanent with pm2 (I guess).

I'm also fine without a web-interface, if I could command yuri2 via discord.

Is the latter possible or can you imagine what the root cause of the failing rest and websocket servers is?

Thanks.

yukinose commented 4 years ago

try changing the ports in rest.service.ts and ws.service.ts to 4200 in your example

JackLeEmmerdeur commented 4 years ago

Ok thanks. Now I don't get a 404 for "api/localsounds" anymore. The ws-endpoint localsounds seems to be found, but the webapp can't authenticate to the websocket (see at the bottom).

This is what I did:

Without changing port to 4200 in application.yaml and config.yaml, I get the 404 for "api/localsounds" again.

Results: Lavalink starts on port 4200 yuri2 connects to Lavalink and loads the sound files. ng serve on webapp runs the app on 8080

When opening localhost:8080 I get the UI and some ws and rest exception toast-errors.

Network looks like this: Bildschirmfoto-1

The 4 errors roughly correspond to the toast-errors:

So how do I let the webapp know the credentials of the rest and websocket services? Got no experience in Angular so I don't get how the HttpClient is injected into the constructor of RestService and where it possibly could get the credentials. In rest.service.ts your using withCredentials: true though.

Thanks for reading and possibly thinking about it.

yukinose commented 4 years ago

i am not that familiar with the bot so i can't really give you much information about how it works (i'm not zekro). i have gotten the bot to work though and here are some steps i took:

then, build the web server and move it into bin via the steps zekro provided in the previous issue:

$ cd web
$ npm install
$ npm run build --prod
$ cd ..
$ mkdir bin/web
$ cp -r web/dist/ bin/web/

after running the binary, you should be able to connect to the front end via localhost:8080. it should ask for "log in via discord", which is an oauth2 redirect... you will need to add http://localhost:8080/login/authorize to your "OAuth2 Redirects" via: discord developer portal > [your application] > OAuth2.

this should help you get it running. the bot also runs the web interface so you shouldn't have to run it via "ng serve". it seems that the cookie generated by authenticating via oAuth2 is used for restApi authentication (see the "docs" folder for more information).

JackLeEmmerdeur commented 4 years ago

Thanks so much @yukinose and @zekroTJA for the detailed instructions. The webinterface is running now and is presenting the defined songs in config.yaml->lavalink.sound_locations.

I still stumbled on one showstopper: After starting a song in the webinterface I get a "WS Request Error - command failed: unexpected end of JSON input". My bot plays nothing.

You can close this issue atm. I'll try to figure that out myself and annoy you again, if I won't figure it out.

Edit: I'll try to debug it with chrome debugger now and see where the json is mangled. Will get back with my results here.

Edit 2: I guess I have to build lavalink and debug, as it's possible that it receives unexpected JSON by discord or something. Nothing suspicious in lavalink-logs. The chrome debugger wasn't any help, as the only debuggable codepoint was in ws.service.ts->onMessage() where I get just that brief error-message posted before.

JackLeEmmerdeur commented 4 years ago

Yay! Huge Success.

TL;DR Fix:

In the go application in

It's working flawlessly now.

@zekroTJA The bot is the only discord soundbot working for me. The source code is really exceptionally clean and very well documented. A really huge effort to interconnect all the parts. I aspire to get to that level with rust or java, especially relating to oauth and websockets some day. I think where this project could improve is an interactive setup application and if you think that is feasible and you haven't done anything for that, I might volunteer for that.

A rather boring blurb of how I found the culprit codeline: