In order to keep client and server queues synchronized, the client and server are connected via socket.io. See DELTA.md
for further references on delta. There are two distinct types of connections: server-control client and server-media client. Server-control client refers to a connection between the server and a "normal" client that'll make requests to the queue and media player status. Server-media client connections accept media player state change data, and only one of these are permitted.
This project utilizes (socket.io)[https://socket.io/] for socket communications.
A media object is data that the user desires to be played. It should be expressed as an object like so:
{
"url": String,
"uid": String
}
- Where url is the URL to the media source.
- Where uid is the unique identifier of the media object.
Once the server accepts the client's connection, the client can emit "get all"
to be up to date with the master queue.
The client should emit a "register media"
, in which the server will register the media client, only if there is currently no other media client (at the moment, only one media client is allowed).
To server from client.
Client requests the entire queue and the delta number. Server should then emit "greet"
event.
To all clients from server.
Broadcast new delta to all clients. The data is a delta object.
To client from server.
"Greeting" message. Tells the client the current queue and delta number.
data:
{
"queue": [],
"delta": int
}
- Where queue is the server queue array.
- Where delta is the server delta number (int).
To server from client.
Propose a new delta. Server should emit "good delta"
if good request, otherwise "bad delta"
.
data:
{
"action": int,
"indexes": [],
"media": Object
}
See DELTA.md
for further information on deltas
To client from server.
Response to client if the proposed delta is valid and added. Server should respond with new delta number.
data:
int
To client from server.
Response to client if the proposed delta is invalid and ignored. Server responds with the same data as "delta update"
would yield to the client.
To server from client.
Request server to pause media.
To server from client.
Request server to play media.
To server from client.
Request server to skip to next media in queue.
All events here are to media client from server.
To server from client.
Play the current media.
To server from client.
Pause the current media.
All events here are to server from media client.
To client from server.
Play media.
To client from server.
Pause media.
To client from server.
Set the current media URL. Server should give a string of the URL.
data:
String
Both client and server can send/recieve.
Set the volume of the player. The given volume is in terms of percentages [0.0, 1.0].
data:
{
"volume": Float
}
To server from client.
Edit the media player volume, by adding the given value.
data:
Float
To client from server.
To be documented...
To server from client.
Update the server on the current state of the media.
data:
{
"volume": Float,
"playing": Boolean,
"url": String,
}
To server from client.
To be documented...
To server from client.
Notify the server that the media has finished playing.