A conflict happens when multiple clients write to the same shared object at “the same time” so that's what you need to avoid.
You won’t have a conflict when:
Rather than communicating with a shared object, broadcast an event message to all clients in the room when something of interest occurs. p5.party supports this pattern with the partyEmit() and partySubscribe() functions.
Event messages can be used to communicate something happened (the user pressed “space”) or something should happen (a bullet should be fired).
Event messages always have a name
which describes the type of event (e.g. “playSound”, “shoot”).
Event messages may also include some data (e.g. "beep"
, {x: 10, y: 10}
)
Unlike shared data objects, event messages are transient. There is no record of past events, their data is not stored, and clients that join after an event is sent will not receive them.
Use partySubscribe()
to indicate that you want to receive messages that have a matching name
and to specify what function handles the event. Usually you will call partySubscribe()
once for each type of message you want to receive in the setup()
.
Use partyEmit()
to create and broadcast a new event message.