Skip to content

Commit fdef7d1

Browse files
committed
mention the "appSender" flags in the shared state chapter
1 parent d767576 commit fdef7d1

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

src-docs/shared_state/conflicts.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ both a Total Order of messages and a "single source of truth" can not be assumed
2929
Many webxdc applications are incapable of producing conflicts,
3030
either because they do not use the network communication APIs,
3131
or because any given data structure can only have one writer.
32+
Alternatively, an application can designate a "central" authority
33+
by checking [`webxdc.appSenderAddr`](../spec/selfAddr_and_selfName.html#appsenderaddr)
34+
to identify the user who shared the app.
35+
This peer could then authoritatively resolve conflicts or coordinate state updates.
36+
However, developers should be aware that if the app depends entirely on the sender being online,
37+
the app's availability will be limited when the sender is offline.
38+
3239
For example, many of the available [webxdc games](https://webxdc.org/apps/) offer a high-score table
3340
and how users scored will typically be reported back to the chat.
3441
Such a gaming app will simply post their user's highscore

src-docs/shared_state/crdts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ This enables peers to queue updates while entirely offline,
146146
and to merge their local state with others' when they are once again able to communicate.
147147
While this behaviour can be very helpful for application developers,
148148
it may not free you entirely from having to think about network conditions.
149-
_Eventually-consistent_ application state should generally be treated as
150149
subjective, which can be a significant shift if you are used to having a server acting as an authority.
150+
While you can use [`webxdc.appSenderAddr`](../spec/selfAddr_and_selfName.html#appsenderaddr) to nominate a peer
151+
(the app sender) to act as a kind of server, this introduces a dependency on that peer being online.
151152
That means that conditional behaviour that you'd usually treat as _yes_ and _no_,
152153
may instead behave more like _currently_ and _not yet_.
153154

155+
154156
This section has discussed attributes of CRDTs that are mostly theoretical.
155157
The next section will give more concrete examples using **Yjs**,
156158
with a particular focus on how it can be used to accomplish common

src-docs/shared_state/practical.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,26 @@ As for the matter of duplicate ids in the `order` array,
473473
the rendering code which constructs the app's UI from this data
474474
could ignore repeated elements when iterating over them.
475475

476+
## Centralized coordination
477+
478+
While CRDTs are designed for peer-to-peer operation,
479+
you may sometimes want to designate one client as a "coordinator".
480+
By comparing [`webxdc.appSenderAddr`](../spec/selfAddr_and_selfName.html#appsenderaddr)
481+
with `webxdc.selfAddr`,
482+
an app can identify whether it is running for the peer
483+
that initially shared the app.
484+
This "sender" instance can then take on special roles,
485+
such as authoritatively resolving state conflicts,
486+
for example by letting the app sender's updates always win.
487+
488+
However, use this model with care:
489+
if your app logic requires the sender to be online to function,
490+
it will be unusable whenever the sender is offline or has left the chat.
491+
One further complication occurs if the app sender
492+
has multiple devices running the app simultaneously,
493+
with each device possibly regarding itself as the central coordinator
494+
and producing conflicting application states.
495+
476496
## Learning more
477497

478498
Many more examples can be found throughout

src-docs/webxdc.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ interface Webxdc<T> {
7474
selfName: string;
7575
/** The address of the peer who initially shared this webxdc app. */
7676
appSenderAddr: string;
77-
/** True if the current user can send updates to all peers.
78-
* If false, updates sent by this peer will only be received by the app sender. */
79-
canSendUpdatesToAllPeers: boolean;
77+
/** True if updates sent by this peer will only be received by the app sender.
78+
* If false, the current user can send updates to all peers. */
79+
canOnlySendUpdatesToAppSender: boolean;
8080
/**
8181
* set a listener for new status updates.
8282
* The "serial" specifies the last serial that you know about (defaults to 0).

0 commit comments

Comments
 (0)