Closed jbjjbjjbj closed 2 years ago
Okay i could maybe use some input here. I'm currently mapping method calls and returns to json objects which are sent over the websocket.
So the status call will become:
{"method": "Status", "token": 0, "value": {"queue_max": 1, "autoplay_max": 1}}
{
"type": "return",
"token": 0,
"value_type": "Status.Info",
"value": {
"current": {
"title": "",
"artist": "",
"album": ""
},
"length": 1,
"progress": 0,
"queue_length": 0,
"queue_hash": 5740354900026072000,
"queue": [],
"autoplay": []
}
}
Here the first object is the call message and the second is the response.
The way I'm doing this currently is not very automated, and the status mapping above can be seen below. I'm not a big fan, but it's seems like the simplest solution.
@api_method("Status", {"queue_max": int, "autoplay_max": int})
def status(sonica, socket, value):
resp = sonica.Status(pb2.Status.Query(**value))
return "Status.Info", dict_from_msg(resp, [
("current", dict_from_song),
(["length", "progress", "queue_length", "queue_hash"], None),
(["queue", "autoplay"], lambda x: [dict_from_song(s) for s in x])
])
Does this seem reasonable? Or should we try to find a more automatic way of mapping between grpc and websocket.
{"method": "Status", "token": 0, "value": {"queue_max": 1, "autoplay_max": 1}}
What is the token value here?
Does this seem reasonable? Or should we try to find a more automatic way of mapping between grpc and websocket.
We've already tried with both OpenAPI and gRPC Gateway to map it automatically, but it hasn't worked so far, and the Sonica API is not super big, so manual mapping is fine for me unless we actively know some way to map it.
{"method": "Status", "token": 0, "value": {"queue_max": 1, "autoplay_max": 1}}
What is the token value here?
The idea is that the client can choose a token when running a method. The same token is then used in the return value, such that the client knows which return values map to which method calls.
So i can call 10 commands at the same time, and still distinguish the results.
So i can call 10 commands at the same time, and still distinguish the results.
Is this not something that would normally be handled client-side? All calls to grpc are blocking, so i think the same idea goes for the api?
Ahh, this is a websocket and not a rest interface, gotcha!
TODO: