Get started
Embedded Studio

Collaborate live

Collaborate live

Several members can edit one itinerary at once. Each change arrives over a live stream and lands in every open studio through the same tool bus a click uses.

Opt-in

Each button above pushes one scripted frame into a session, which decodes it exactly as it decodes a live stream.

Open a session

Create a CollabEngine for the open itinerary inside MountayaStudioHost, and hand it to MountayaStudio.

import { useMountaya } from "@mountaya/client-react";
import { createCollabTransport } from "@mountaya/client/events";
import { CollabEngine } from "@mountaya/elements/collab";
import { studioCollabTools, type StudioToolContext } from "@mountaya/studio";
import { MountayaStudio, useStudioHostRegistry, useStudioToolContext } from "@mountaya/studio-react";
import { useEffect, useState } from "react";

export const CollaborativeStudio = ({ itineraryId }: { readonly itineraryId: string }) => {
  const client = useMountaya();
  const { bus } = useStudioHostRegistry();
  const ctx = useStudioToolContext<StudioToolContext>();
  const [session, setSession] = useState<CollabEngine | null>(null);

  useEffect(() => {
    const opened = new CollabEngine({
      bus,
      ctx,
      resource: { id: itineraryId, kind: "itineraries" },
      tools: studioCollabTools,
      transport: createCollabTransport(client.transport),
    });
    opened.start();
    setSession(opened);

    return () => {
      opened.dispose();
      setSession(null);
    };
  }, [bus, client, ctx, itineraryId]);

  return <MountayaStudio collabEngine={session} />;
};

The session follows the token your client holds: when a token expires, the stream reopens with the fresh one and replays what changed in between.

Show who is here

The assembled studio shows collaborators for you. In a layout of your own, place PresenceRoster for the avatars and PeerLockTooltip around a control someone else holds.

Give collaborators names

The studio knows user ids, not names. Pass behavior.resolvePeerName to read names from your own member directory.

import type { PeerNameResolver } from "@mountaya/elements/collab";
import { emailLocalPart } from "@mountaya/elements/collab";

const resolvePeerName =
  (organizationId: string | null): PeerNameResolver =>
  (userId) => {
    const member = directoryFor(organizationId).find((entry) => entry.id === userId);

    return member ? (member.name ?? emailLocalPart(member.email)) : null;
  };

Without it, collaborators show as initials, and a held control reads "A collaborator is editing this".

Next steps

Last updated