All the stuff I wrote trying to get websockets to livesplitone timer commands working on my machine.
I'm playing Super Mario 64 Coop Deluxe. I've previously tried to play sm64 on a Speedrun.com approved emulator, but found the memory address search to be too challenging. Sm64coopdx thankfully has a Lua API, so I used that to avoid need to search memory. It seems to me that the you can not use any file access commands from the modding API, so I just print relevant events to the console. This isn't really related to websockets, but I wanted to include it as an example of something easy that I was able to get working.
In order for the other files to work the game needs to get started like so:
./sm64coopdx | grep --line-buffered "split" > log.txt
This was my first attempt at an autosplitter for the game. Unfortunately I found that ydotool failed to trigger the timer from time to time so I abandoned this approach.
For whatever reason the python websockets library did not work. I could get connections started, but they would fail
sometime before the 10 minute mark. The error I got was
Lost the connection to the server: keepalive ping timeout
I have no idea why. As far as I can tell the library should be handling everything about the underlying connection.
I have a few files I included that were experiments to see if I could write anything that wouldn't disconnect.
One of the experiments to see if I could get something in python to work. It did not. Websockets had something about being able to use either async or callbacks, so this was me trying to use not async.
This was my first attempt at writing the program. Since I'm just reading a log file, and I've used Inotify in the past
I combined some stuff from my earlier file and the ls1-hotkeys code. I hadn't written any async code before. There
are a few functions still in there that I used for testing, however they aren't called as they don't get gathered in
the async def main() function. This code isn't very good. But it should have worked.
This is the python code I was happy with! I moved my now single function into the serve command and my async code no longer checks the content each line. I was able to take that out by grepping the output before writing to a file. This felt very clean to me and was very disappointing when it still disconnected.
This is a file from thearst3rd. This was really helpful for getting off the ground in communicating with livesplit. And I'm not sure where else I would have found the {"command" : "splitOrStart"} thing
There was a pervious attempt at a js file, but it didn't work at all. so. Looking through the livesplitone code at the websockets client implementation, I didn't see anything funky at all. It looked to me like they also just use the main websockets library from Typescript. So I figured it might work better if I also use typescript. I didn't/don't know anything about javascript programming though, so I still don't really understand how you use mjs, js, or ts. I ended up just doing the thing that I saw in the example code. Thankfully I was able to find where someone had ported Inotify to node, so I was able to use the exact same strategy as the python attempts. This was as simple as mashing together the Websocket quickstart code and the Inotify code together.