ets2-local-radio icon indicating copy to clipboard operation
ets2-local-radio copied to clipboard

Add linux port

Open jthistle opened this issue 3 years ago • 20 comments

So, I sort of went and ported this to Linux... it seems to work pretty well.

The one thing that doesn't work is the 'commands' route on the web server - I'm not sure what that's meant to do, maybe you could give some advice @Koenvh1 ? :)

This is based on v3.1.0, but I have to PR into a branch rather than a tag, so master it is then. It may work with master, I haven't tested it.

Work-in-progress.

jthistle avatar Mar 20 '21 01:03 jthistle

The "official" server window has a couple of options, e.g. it detects which game is running (ETS2 or ATS), determines the language (en-GB, nl-NL, he-IL, etc.), and supports global keyboard/controller bindings for e.g. changing the volume and station. To pass these settings to the browser, the browser polls the server for "commands"* and checks for differences (this is what the id is for, can be as simple as a timestamp of change or hash of the object). If there is a difference, it executes the action, changes the language, and switches between ATS and ETS2 (if there is a difference).

* Originally it just passed the keyboard presses to control the playback, thus the name commands

Koenvh1 avatar Mar 20 '21 02:03 Koenvh1

https://github.com/Koenvh1/ets2-local-radio/blob/master/server/ETS2%20Local%20Radio%20desktop/Commands.cs

That's what the commands object looks like.

What the action and amount look like is something you can find in the function named writeFile (I believe because it used to write an actual JSON file to disk) here https://github.com/Koenvh1/ets2-local-radio/blob/master/server/ETS2%20Local%20Radio%20desktop/Main.cs#L516

Just search for writeFile in that class, and you can see what it is called with.

Koenvh1 avatar Mar 20 '21 02:03 Koenvh1

That's great, thanks for the help.

jthistle avatar Mar 20 '21 09:03 jthistle

So, this is pretty much working minus the feature to use commands, allthough it feeds the commands route the data it expects to prevent errors. I do need to write some more docs for it though, and probably add some better installation / setup scripts.

Up to you @Koenvh1 whether you want to merge this or not once that's done, do let me know what you think :)

jthistle avatar Mar 20 '21 16:03 jthistle

I will test it (and so will a couple of other people who I know have asked for a Linux version before), and if it works, then I don't see why not. The only thing I am not sure about are the JavaScript additions, but that's something I would have to look into.

Koenvh1 avatar Mar 20 '21 19:03 Koenvh1

Sure, I can remove that if you want. I just wanted to see if I could make it so that when I turned the engine off, the radio would also stop (immersion!)

Rest of that sounds good, thanks for feedback on this :)

jthistle avatar Mar 20 '21 20:03 jthistle

Are you sure that your read_line keeps working? Someone had issues where it would work initially, but break after some time (and no longer switched stations when crossing a border)

Koenvh1 avatar Mar 23 '21 22:03 Koenvh1

That's possible. I may need to add something to catch if the read_util dies or the pipe breaks, and to restart it if that happens.

jthistle avatar Mar 24 '21 10:03 jthistle

@Koenvh1 I've made some improvements to how errors are handled. Let me know if that helps.

jthistle avatar Mar 24 '21 18:03 jthistle

Okay so I'm the mystical person that has asked for a linux version before. Pulled the latest commit and the one main issue still persists. The stations don't automatically switch when crossing a border nor do they start playing when you first open up the app/website. Also after the commit it's screaming at me with this error:

Traceback (most recent call last):
  File "/usr/lib/python3.9/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.9/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.9/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/kaperios/Games/ETS2 Local Radio/linux/server/main.py", line 59, in __init__
    super().__init__(*args, directory="../../web/")
  File "/usr/lib/python3.9/http/server.py", line 653, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/lib/python3.9/socketserver.py", line 720, in __init__
    self.handle()
  File "/usr/lib/python3.9/http/server.py", line 427, in handle
    self.handle_one_request()
  File "/usr/lib/python3.9/http/server.py", line 415, in handle_one_request
    method()
  File "/home/kaperios/Games/ETS2 Local Radio/linux/server/main.py", line 102, in do_GET
    super().do_GET()
  File "/usr/lib/python3.9/http/server.py", line 660, in do_GET
    self.copyfile(f, self.wfile)
  File "/usr/lib/python3.9/http/server.py", line 859, in copyfile
    shutil.copyfileobj(source, outputfile)
  File "/usr/lib/python3.9/shutil.py", line 208, in copyfileobj
    fdst_write(buf)
  File "/usr/lib/python3.9/socketserver.py", line 799, in write
    self._sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe

Remyrios avatar Mar 24 '21 18:03 Remyrios

@Kaperios I see, thanks for testing it out. I think I know how to fix that one, and I'll look into the border crossing thing - I imagine I need to send the correct command. I'll ping you again once I've tried to sort it.

jthistle avatar Mar 24 '21 22:03 jthistle

@Kaperios what is the expected behaviour when first opening the website? Which station do you expect to start playing automatically? I'm asking because I can't test this in Windows. Thanks.

jthistle avatar Mar 25 '21 17:03 jthistle

@Kaperios @Koenvh1 Hi, I think I've fixed it now. Please give it a go and let me know if it works!

jthistle avatar Mar 25 '21 19:03 jthistle

I recently found out about this ETS2 plugin, unfortunately, there was no official Linux release. I found this PR here, pulled the latest commit, built it and tried it out for a couple of hours. It works really well. Had no problems so far.

I'd love to see this as an official release soon!

Lezurex avatar Aug 11 '21 17:08 Lezurex

Good to hear - unfortunately comms went dark after my last comment in this PR. I too would like to see this merged if possible :)

jthistle avatar Aug 12 '21 18:08 jthistle

The thing is that I do not have a computer to test it on currently, hence I asked @Kaperios to test it for me. If he experiences issues, then probably something needs fixing.

Koenvh1 avatar Aug 12 '21 19:08 Koenvh1

@Koenvh1 I understand, it's just that after the issues were reported I fixed them and said so, but I didn't recieve any further communication after that.

jthistle avatar Aug 15 '21 13:08 jthistle

I have added a link to here on the releases page. Just as a heads-up, I am planning a version 4 which will lead to some breaking changes.

Koenvh1 avatar Aug 15 '21 14:08 Koenvh1

I released the beta version of 3.3, which serves a lot of files locally again due to some policy changes with Google Chrome. I would recommend checking whether your Linux version supports that as well, otherwise it will stop working with starting from Chrome 93 (due to be released on 31 August).

Koenvh1 avatar Aug 23 '21 23:08 Koenvh1

I made only one insignificant change to the web part of the code, so it should be fine, I would think.

jthistle avatar Aug 29 '21 15:08 jthistle