Skip to content

Latest commit

 

History

History
220 lines (127 loc) · 4.16 KB

SOCKETS.md

File metadata and controls

220 lines (127 loc) · 4.16 KB

Client/Server socket communication

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.

Media Object

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.

On initial connection

Server-control client connection

Once the server accepts the client's connection, the client can emit "get all" to be up to date with the master queue.

Server-media client connection

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).

Socket events to listen for (server-control client)

"get all"

To server from client.

Client requests the entire queue and the delta number. Server should then emit "greet" event.

"delta update"

To all clients from server.

Broadcast new delta to all clients. The data is a delta object.

"greet"

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).

"propose"

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

"good delta"

To client from server.

Response to client if the proposed delta is valid and added. Server should respond with new delta number.

data:

int

"bad delta"

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.

"pause"

To server from client.

Request server to pause media.

"play"

To server from client.

Request server to play media.

"next"

To server from client.

Request server to skip to next media in queue.

Socket events to listen for (server-media client)

All events here are to media client from server.

"play"

To server from client.

Play the current media.

"pause"

To server from client.

Pause the current media.

Socket events to listen for (media-server client)

All events here are to server from media client.

"play"

To client from server.

Play media.

"pause"

To client from server.

Pause media.

"set url"

To client from server.

Set the current media URL. Server should give a string of the URL.

data:

String

"volume"

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
}

"volume edit"

To server from client.

Edit the media player volume, by adding the given value.

data:

Float

"seek"

To client from server.

To be documented...

"media state"

To server from client.

Update the server on the current state of the media.

data:

{
    "volume": Float,
    "playing": Boolean,
    "url": String,
}

"time"

To server from client.

To be documented...

"media ended"

To server from client.

Notify the server that the media has finished playing.