MemberAPI

Interface MemberAPIExperimental

The Member API provides methods to interact with members in the current space. Members represent users connected to the space. You can retrieve information about members, manage custom data associated with them, and perform actions on them.

Every member has an ID, which is a continuous number starting from 0. The local member (the user of the current client) always has the ID 0. Other members are assigned IDs in the order they join the space.

// Get the webvis context
const context = await webvis.getContext();

// Get the IDs of all members in the current space
const memberIds = context.getMembers();

// Request properties for the local member, which always has ID 0
const localMemberProps = await context.requestMemberProperties(0);

// Request properties for another member
const otherMemberProps = await context.requestMemberProperties(1);

// Set/get the name of the local member
context.setMemberName("John Doe");
const memberName = context.getMemberName();

You can manage custom data at the profile entries of a member using the setMemberProfileEntry and deleteMemberProfileEntry methods. This data is stored in the profile field of the MemberProperties object and will be available to other members in the same space.

// Set/get custom data at the profile entries of the local member
await context.setMemberProfileEntry("status", "online");
await context.setMemberProfileEntry("age", 30);
const status = localMemberProps.profile["status"]; // "online"
const age = localMemberProps.profile["age"]; // 30

// Delete a profile entry of the local member
await context.deleteMemberProfileEntry("age");

You can request and use actions available on a member using the requestMemberActions and useMemberAction methods. Member actions allow you to perform predefined operations on members, see MemberAction for a list of available actions.

// Request available actions on another member
const actions = await context.requestMemberActions(1);

// Use an action on another member
if (actions.includes(webvis.MemberAction.PROMOTE)) {
  await context.useMemberAction(1, webvis.MemberAction.PROMOTE);
}

The Member API emits the following events:

interface MemberAPI {
    deleteMemberProfileEntry(key: string): Promise<void>;
    getMemberName(): string;
    getMembers(): number[];
    requestMemberActions(memberId: number): Promise<MemberAction[]>;
    requestMemberProperties(id: number): Promise<MemberProperties>;
    setMemberName(name: string): void;
    setMemberProfileEntry(key: string, value: Serializable): Promise<void>;
    useMemberAction<A extends MemberAction>(
        memberId: number,
        action: A,
        options?: MemberActionsToOptionsMap[A],
    ): Promise<void>;
}

Hierarchy (View Summary)

Methods

  • Experimental

    Deletes a profile entry of the local member.

    Parameters

    • key: string

      The key of the profile entry to delete.

    Returns Promise<void>

    A promise that resolves when the profile entry has been deleted.

  • Experimental

    Gets the name of the local member.

    Returns string

    The name of the local member, or undefined if not set.

  • Experimental

    Gets a list of all member IDs in the current space.

    Returns number[]

    An array of member IDs.

  • Experimental

    Requests the actions available on a member.

    Parameters

    • memberId: number

      The ID of the member to request actions for.

    Returns Promise<MemberAction[]>

    A promise that resolves to an array of member actions.

  • Experimental

    Requests the properties of a member.

    Parameters

    • id: number

      The ID of the member to request the properties for.

    Returns Promise<MemberProperties>

    A promise that resolves to the member properties, or undefined if the member does not exist.

  • Experimental

    Sets the name of the local member.

    Parameters

    • name: string

      The new name for the local member.

    Returns void

  • Experimental

    Sets a profile entry of the local member.

    Parameters

    • key: string

      The key of the profile entry to set.

    • value: Serializable

      The value to set for the profile entry.

    Returns Promise<void>

    A promise that resolves when the profile entry has been set.

  • Experimental

    Uses an action on a member.

    Type Parameters

    Parameters

    • memberId: number

      The ID of the member to use the action on.

    • action: A

      The action to use.

    • Optionaloptions: MemberActionsToOptionsMap[A]

      Optional parameters for the action.

    Returns Promise<void>

    A promise that resolves when the action has been used.