CharlesHolbrow / synk

support syncing data with browser
0 stars 0 forks source link

Allow user-agents to send messages to the simulation #9

Closed CharlesHolbrow closed 6 years ago

CharlesHolbrow commented 7 years ago

Simulations like eternal-action need to listen for messages from clients. We need a standardized way of allowing clients to communicate with simulation loops.

There are four libraries involved here:

  1. synk has the Client type and the Handler type that manages WebSocket communication
  2. The main library such as eternal that defines the data structures we will be working with.
  3. The http/websocket executable. This is where we handle messages from user-agent clients.
  4. Simulation loop are updating structures.

Needs:

We need a way to send messages from '3' to '4'.

Using Redis as a message broker is probably easiest.

Needs a way to handle and identify incoming messages

If we use Redis as a communication protocol, we will need serialize messages from '3' to '4'.

CharlesHolbrow commented 6 years ago

Solution:

The first argument of CustomClient.OnMessage is a *synk.Client.

This object has a .Publish(channel string, message []byte) method which will be pumped to redis.