clapper icon indicating copy to clipboard operation
clapper copied to clipboard

Get current state over websocket without performing action?

Open peteruithoven opened this issue 2 years ago • 1 comments

I'm trying to make a very simple remote website using the websocket that I could use from my phone to control Clapper on my laptop. When the websites opens I'd like to know the current state of Clapper, whether it's playing or paused. I receive this state when sending actions like toggle_play, but there doesn't seem to be a way to receive the state without altering the playback?

Current code: https://stackblitz.com/edit/js-uiw7vp?file=index.js

peteruithoven avatar Jun 26 '23 18:06 peteruithoven

Hi, the WebSocket server functionality is going to be changed slightly as part of undergoing Clapper code rewrite.

First of all you will be able to do a GET request anytime at http://$IP:$PORT to receive JSON data with all current values like requested in this issue.

Second, the WS messages syntax is going to be changed. Sorry. Since I do not want to write my own JSON parser nor have a build dependency on an external library just for this feature of video player, as now I am dealing with C code only and not JavaScript, so JSON is harder to read. With that, the previous message send to control the player:

JSON.stringify({ action: 'play' })

is now going to be simply:

play

Additional arguments will be separated with whitespaces, eg. to add video:

add https://example.com/video

Third, client is going to receive current playback position changes, speed, volume, etc. via WebSocket messages with same syntax as above, eg:

volume 0.86

There will also be a queue_changed messages meaning some data in playback queue (upon which new Clapper operates) got changed. In this case after receiving such message, client can fetch JSON data again to update its UI accordingly with new queue (new items, video titles, etc.).

I do hope to finally write some documentation with all possible actions, their descriptions and how to use this WebSocket communication overall after this reworked implementation is merged.

Rafostar avatar Jan 07 '24 18:01 Rafostar

Should probably mention it here, but now Clapper uses dynamic port + MDNS to announce it. This is to allow in the future multiple instances (or maybe even some other app that uses Clapper API) on single computer:

For example, using AVAHI:

avahi-browse -r _clapper._tcp -t

Rafostar avatar Apr 17 '24 17:04 Rafostar