TinaTiel / obs-chatbot

GNU General Public License v3.0
3 stars 0 forks source link

Research Websocket protocol #12

Closed TinaTiel closed 3 years ago

TinaTiel commented 3 years ago
TinaTiel commented 3 years ago

So far have figured out websockets are generally a protocol initiated over TCP and unlike a simple HTTP request with a request and response the client needs to behave what looks like a server; the communication stays open / isn't transactional and if you look at the many examples out there you see that clients usually implement event handling methods such as onOpen, onMessage, and onClose.

A popular websocket extension I'm seeing used is STOMP, which is a sub-protocol / extension of the vanilla websocket protocol. It looks nice, and Spring natively supports it. However, looking at the websocket controller plugin for OBS (https://github.com/Palakis/obs-websocket) I can see in the source code that it depends on a C++ library called Websocket++ that does not appear to support the STOMP protocol.

So, it looks like I'll need to use generic websocket protocol to communicate with OBS. Taking a look at examples such as https://www.devglan.com/spring-boot/spring-websocket-integration-example-without-stomp Funny, "spring websocket without stomp" is the second suggestion on Google next to "spring websocket" XD

TinaTiel commented 3 years ago

Ugh, nevermind with the devglan link. Yet another example of folks writing a java server and then jumping to javascript for the client.

Taking a close look at https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/socket/client/package-summary.html since the long-term intent is to use Spring.

Not sure if I'll be able to use the existing java obs-websocket library at https://github.com/Twasi/websocket-obs-java It'd be convenient, but I'm concerned about testing:

I'm super tempted to contribute at some point (maybe fleshing out tests?), but given how I'd want to architect it I think my contributions might change their API too much. I think I will want to use the Spring WebSocketClient as it is supposed JSR-356 compliant already.

What I might consider doing is building my client as a separate maven module so that it would be possible to offer the client alone as a library to others -- we'll see, might be a lot of work to maintain a separate library rather than to keep it internal to my project for now.

TinaTiel commented 3 years ago

Cool! Finally found a example on google, using the StandardWebsocketClient implementation provided by Spring: https://idodevjobs.wordpress.com/2019/02/07/spring-websocket-client-without-stomp-example/

Learned that the WebSocketClient takes a WebSocketHandler as defined in https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/socket/handler/package-summary.html

TinaTiel commented 3 years ago

I think what I'll do is see if I can copy the example above and if I can get that working then I'll close this and create some new issues to track building a testable client.

TinaTiel commented 3 years ago

OH! This is PERFECT: https://spring.io/blog/2013/05/23/spring-framework-4-0-m1-websocket-support

TinaTiel commented 3 years ago

http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html

TinaTiel commented 3 years ago

Finally got a working example in 0106986a05122ad846cf126af5c234f4096f8f26