Syncplay / syncplay

Client/server to synchronize media playback on mpv/VLC/MPC-HC/MPC-BE on many computers
http://syncplay.pl/
Apache License 2.0
2.11k stars 214 forks source link

Syncplay Protocol v1.6.7 #417

Closed RozeFound closed 3 years ago

RozeFound commented 3 years ago

I'm trying to implement your protocol in my application, and I was confused with this thing: Server << {"Set": {"user": {"Bob": {"room": {"name": "SyncRoom"}, "file": {"duration": 0, "name": "filename", "size": 0}}}}} What the heck is this: {"user": {"Bob": How can I access data in the row if the key can be ANYTHING?

Et0h commented 3 years ago

Every Syncplay user has a username. In this example, one of the users has the name "Bob" and so this message specifies information regarding what Bob is watching.

If you want to see how this is implemented in practice, you can see the Syncplay source code at https://github.com/Syncplay/syncplay and specifically the protocol code at https://github.com/Syncplay/syncplay/blob/master/syncplay/protocols.py

What are you trying to implement the protocol for?

RozeFound commented 3 years ago

I mean, why the json key doesn't have a constant name?

Et0h commented 3 years ago

The user won't always be called "Bob". Sometimes they might be called "Alice".

See https://syncplay.pl/about/protocol/ for details on different uses of the "Set" messages. It is based on Syncplay 1.2.7, so hasn't been updated to show the protocol for chat, playlist and readiness messages but all that can be seen within the Syncplay protocols.py file.

RozeFound commented 3 years ago

I understand, but JSON keys must be constant for easy accessing data inside. Like "User":{"username":"Bob", ...}

RozeFound commented 3 years ago

JSON keys with mutable names just hard to deserialize.

What are you trying to implement the protocol for? @Et0h

Of course for what it was created, for video playback synchronization.

Et0h commented 3 years ago

I agree that the protocol is not ideal in terms of ease of re-implementation, but it's what we've got and changing it would harm forwards and backwards Syncplay combability. If you are trying to make something which is compatible with Syncplay then look at how Syncplay parses it to figure it out. If you do not need compatibility then feel free to revisit many of the protocol design decisions that we made.

RozeFound commented 3 years ago

Why just not make something like this?

if ver > 1.6.8: 
    return {"User": {"username": "Bob", ...}}
else: return {"User": {"Bob": {...}}}

Or you just don't want to make it easier to use?

Et0h commented 3 years ago

How would changing the protocol make anything easier for anyone? We want to maintain forward and backwards compatibility, so it just means every implementation would need to support both versions of the protocol, thus doubling the complexity.

RozeFound commented 3 years ago

Okay I understand your point, thanks for the answer.