Skip to content

rapidmidiex-ws-protocol v0.0.1 spec #17

Description

@hansvb

For v0.0.1 the proposal is to start with json text-messages over websocket.
The goal is to have a minimal working proof of concept.
We don't care about time-synchronisation or any other details.
We do want to measure latency as to have an idea what anti-jitter-mechanisms would be necessary for future upgrades of the protocol.

Client to server-messages

Connect-message

type Connect struct {
    Type    string     // a hard-coded string in each client to identify the
                       // kind of client, e.g. `tuicli v0.0.1` or `jscli-v0.0.1`,
                       // cannot be empty
}
  • Initiated by client
  • server responds with a UpdateClientList-message

SendNoteOn-message

type SendNoteOn struct {
    Note    int         // encoded as a (MIDI-compatible) number, e.g. `60` = `C-4`
}

SendNoteOff-message

type SendNoteOff struct {
    Note    int
}

Server to client-messages

UpdateClientList-message

type Client struct {
    ClientId    string      // a unique (UUID?) representation for each client,
                            // shared and visible by all connected clients 
    Nick        string      // A nickname chosen by the connecting client, can be empty
    Type        string      // a hard-coded string in each client to identify
                            // the kind of client, e.g. `tuicli v0.0.1` or `jscli v0.0.1`,
                            // cannot be empty
    IP          string      // no need for a `net.IP`?
    Latency     int         // roundtrip-time in milliseconds, measured and
                            // updated by the server at regular intervals with low-level
                            // websocket-ping/pong-messages
} 
type UpdateClientList struct {
    ClientList  []Client
}
  • sent by the server to all connected clients on receiving a Connect-message
  • sent at regular intervals (TBD: minimum refresh interval)

ForwardNoteOn-message

  • sent by the server to all connected client on receiving a NoteOn-message
type ForwardNoteOn struct {
    ClientId    string
    Note        int
}

ForwardNoteOff-message

  • sent by the server to all connected clients on receiving a NoteOff-message
type ForwardNoteOff struct {
    ClientId    string
    Note        int
}

LatencyUpdate-message

Although the UpdateClientList-message also sends this information already, maybe it's still interesting to define this message. The server can then still decide to use this or opt for the full-on UpdateClientList.

type LatencyUpdate struct {
  ClientId string
  Latency int
}

Assumptions

Some assumptions about rapidmidiex-srv v0.0.1:

  • one global session is always in progress (perhaps without connected clients)
  • no bpm- or tempo-settings, just free for all to send notes
  • the server basically acts as an echo-server for note's, forwarding all received notes to all connected clients
  • server has a Pool with all connected clients ([]Client)
  • server must send regular websocket-Ping-frames to measure latency (TBD: interval)
  • server sents a UpdateClientList-message to all connected clients every time a new client connects or a client-connection is obviously lost
  • a server needs to update all clients with the latest latency information. It can use UpdateClientList-messages or LatencyUpdate-messages for this purpose. The exact details are up to the specific server-implementation.

Some assumptions about v0.0.1-clients:

  • Clients can send SendNoteOn- and SendNoteOff-messages to the server in any order and at the same time.
    • The Note is encoded as a (MIDI-compatible) number, e.g. 60 = C-4.
    • It's up to the client how to generate the note-numbers.
  • Clients can receive an UpdateClientList-message (with []Client).
    • In an extreme situation a client could choose to ignore this message completely
    • Clients can store the ClientId, for example to give visual feedback on which client generated a note-event (perhaps using color or other visual hints)
    • Clients can choose wether or not to display the latency-information of all other connected clients
  • Clients may or may not receive LatencyUpdate-messages. They should update their own table (if they chose to remember one).
  • Clients will receive ForwardNoteOn- and ForwardNoteOff-messages with a Note and a unique ClientId
    • They should have received this ClientId earlier via a UpdateClientList-message from the server.
    • A client could choose to ignore the ForwardNoteOn.ClientId and only act on the ForwardNoteOn.Note-information.
    • A UnknownClientIdError can be generated locally if a Note with an unknown ClientId is received but the protocol doesn't do error-reporting.
    • A client can also choose to ignore UnknownClientIdError and just play (or display) the note anyway.
  • Clients must reply to incoming websocket-Ping-frames with a Pong-frame (this is usually implemented by websocket-implementations as per the websocket-RFC's)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions