Awareness docs clarification

Hey there, can anybody help me understand this from the Awareness docs please?

Awareness CRDT updates work similarly to Yjs updates. First, you sync with a client. Then you exchange incremental updates with that client using the update event

What does “First, you sync with client” actually look like?

Context: I’m trying to create a custom provider with Firestore, lifting somebody else’s solution from a Github issue comment. The YDoc is syncing but I can’t get any Awareness information to propagate, code below - please excuse any stupid mistakes - I have trawled through the docs but I’m coming up with nothing.


@Injectable({ providedIn: 'root' })
export class FirebaseProvider extends Observable<string> {
  public awareness: Awareness;
  public doc: Y.Doc;

  constructor(private db: AngularFireDatabase) {

  public configure(doc: FirestoreDocument, ydoc: Y.Doc) {
    this.doc = ydoc;
    this.awareness = new Awareness(ydoc);


    this.db.database.ref('child_added', (a, b) => {
      try {
        applyUpdate(ydoc, a.val());
      } catch (e) {}

    ydoc.on('update', (update) => {

    ydoc.on('destroy', this.destroy);

  connectAwareness() {
    // Encode the complete Awareness state
    const encodedAwState = encodeAwarenessUpdate(

    // Make sure to share the complete awareness state whenever you
    // connect to a new client. Similarly to the Yjs CRDT, it doesn't
    // matter if the remote client receives the same state-updates several
    // times. What is important is that the state is distributed.
    applyAwarenessUpdate(this.awareness, encodedAwState, this);

    // Whenever the local state changes, communicate that change to all connected clients
    this.awareness.on('update', ({ added, updated, removed }) => {
      const changedClients = added.concat(updated).concat(removed);
      const update = encodeAwarenessUpdate(this.awareness, changedClients);
      applyAwarenessUpdate(this.awareness, update, this);

  disconnect() {}

  destroy() {'destroy', this.destroy);

    // TODO
    //  1 - If only one user present, update the Firestore document
    //  and then remove Yjs data from Firebase
    // 2 - removeAwarenessStates

Grateful for any input :+1: