samcf / ogres

Free online virtual tabletop that runs in your browser. No sign ups, no ads, no nonsense.
https://ogres.app
GNU Affero General Public License v3.0
94 stars 9 forks source link

Invite players to join the host in a multiplayer lobby #24

Closed samcf closed 2 years ago

samcf commented 2 years ago

Sharing the player view window over Discord or Zoom is a decent, effective way to create a collaborative experience. There are some pretty serious limitations, however.

Many other virtual tabletops allow hosts to invite players to participate in a multiplayer lobby through the browser. This story represents the first step towards a more collaborative tabletop experience.

samcf commented 2 years ago
sequenceDiagram
    participant Host
    participant Server
    participant Conns

    Note over Host,Conns: Solid lines are HTTP requests, dashed are WebSocket messages

    Host->>+Server: connect ws://host/ws
    Server->>-Host: upgraded protocol
    Server-->>Host: room key (abc)
    Note over Host,Server: Messages are EDN encoded with type, params

    Conns->>+Server: connect ws://host/ws?key=abc
    Server->>-Conns: upgraded protocol

    loop initial connection
        Conns-->>Server: initial connection
        Server-->>Conns: initial connection
        Server-->>Host: initial connection
        Host-->>Server: initial state
        Server-->>Conns: initial state
    end

    loop broadcast state changes
        Conns-->>Server: operation & params
        Server-->>Conns: operation & params

        Note over Server,Conns: Messages are mirrored to all clients
    end

    loop request image data
        Conns-->>Server: checksum
        Server-->>Host: checksum
        Host-->>Server: data:image/jpg#59;base64,...
        Server-->>Conns: data:image/jpg#59;base64,...
    end
samcf commented 2 years ago

Example WebSocket message (EDN)

{:type   :event
 :name   :initial-connection
 :args   {}
 :sender "1e51189b-e3ea-4e0d-b669-d7c8c1f8b637"}
samcf commented 2 years ago

Server message sent to client upon connecting

{:type :event
 :name :connection-received
 :args {:uuid "1e51189b-e3ea-4e0d-b669-d7c8c1f8b637"}}
samcf commented 2 years ago

DataScript transaction example

{:type   :transaction
 :name   :camera/translate
 :args   [230 400]
 :sender "3e584c31-41c3-4dbd-8498-e5ffc5d94c1a"}
samcf commented 2 years ago

Resolved in #28