Options
Menu

Class Activity

The Activity class represents a activity that the users of a collaboration are participating in together. The activity allows developer to indicate what user are doing within a collaborative application. The activity has a set of participants that indicate which users are part of that activity. Each ActivityParticipant can share state which indicates what they are doing within the Activity.

Hierarchy

Index

Methods

addListener

clearState

  • clearState(): void
  • Clears all local state from this Activity. This will fire a single "state_cleared" event for other joined participants to listen for.

    Returns void

createdTime

  • createdTime(): Date
  • Gets the time this Activity was created.

    Returns Date

    The Activity created time.

events

  • Provides the events emitted by this object as an Observable stream.

    example
    
    eventEmitter.events()
      .filter(e => e.name === "myevent")
      .subscribe(e => console.log(e));
    

    Returns Observable<IActivityEvent>

    An Observable stream of all events emitted by this object.

id

  • id(): string
  • Gets the id of this Activity, which is unique within its user defined type.

    Returns string

    The Activity id.

isEphemeral

  • isEphemeral(): boolean
  • Determines if this Activity is ephemeral. If so, it will be deleted when the last participant leaves.

    Returns boolean

    True if the Activity is ephemeral, false otherwise.

isJoined

  • isJoined(): boolean
  • Determines if the Activity is still joined.

    Returns boolean

    True if the Activity is joined, false otherwise.

leave

  • leave(): Promise<void>
  • Causes the local session to leave the Activity. All other participants of this activity will be notified that this session has left. The state associated with this session will be removed from eh Activity. After calling leave, the Activity object becomes non-functional. The local user can rejoin the activity from the ActivityService but will receive a new Activity object.

    Returns Promise<void>

off

on

once

  • Adds a single shot event listener for the specified event. The listener will be called the first time the specified event is fired after the event registration occurs, after which the registration will be removed and no further events will be passed to the listener.

    Parameters

    Returns ConvergenceEventEmitter<IActivityEvent>

    This object, in support of a fluent API.

participant

participants

participantsAsObservable

  • Gets the participants as an Observable stream.

    activity
      .participantsAsObservable()
      .subscribe(p => console.log(p));
    

    Returns Observable<ActivityParticipant[]>

    An Observable array of participants.

permissions

removeAllListeners

removeListener

removeListeners

removeState

  • removeState(key: string): void
  • removeState(keys: string[]): void
  • Removes a single local state entry from the Activity. This will fire a single "state_removed" event for other joined participants to listen for.

    activity.removeState("pointer");
    

    Parameters

    • key: string

      The key of the local state to remove.

    Returns void

  • Removes one or more local state entries from the Activity. This will fire a multiple "state_removed" event for other joined participants to listen for; one for each key removed.

    activity.removeState(["pointer", "viewport"]);
    

    Parameters

    • keys: string[]

      The keys of the local state to remove.

    Returns void

session

setState

  • setState(key: string, value: any): void
  • setState(state: StringMapLike): void
  • Sets a single key-value pair within this Activity's local state. This will result in a single "state_set" event being emitted for other joined participants to listen for.

    activity.setState("key1", "delta");
    

    Parameters

    • key: string

      The key of the delta to set.

    • value: any

      The delta to set for the supplied key.

    Returns void

  • Sets multiple key-value pairs within this Activity's local state. This method does not replace all state; that is, keys not supplied in the map will not be altered. This method will result in multiple "state_set" events being fired for other joined participants to list for; one for each key set.

    const state = {
      key1: "v1",
      key2: false
    };
    activity.setState(state);
    

    or

    const state = new Map();
    state.set("key1", "v1");
    state.set("key2", false);
    activity.setState(state);
    

    Parameters

    • state: StringMapLike

      A mapping containing the key-value pairs to set.

    Returns void

state

  • state(): Map<string, any>
  • Gets the local session's state within this Activity.

    Returns Map<string, any>

    The local sessions state.

type

  • type(): string
  • Gets the user defined type of this Activity.

    Returns string

    The Activity type.

Object literals

Events

Events: object

Holds the constants for the event names that are fired by the Activity class.

DELETED

DELETED: string = ActivityLeftEvent.EVENT_NAME

Fired when a the activity was deleted while joined.

FORCE_LEAVE

FORCE_LEAVE: string = ActivityForceLeaveEvent.EVENT_NAME

Fired when the server forces the local session to leave the activity.

LEFT

LEFT: string = ActivityLeftEvent.EVENT_NAME

Fired when a the activity is left by the local session. The resulting event will be an ActivityLeftEvent.

SESSION_JOINED

SESSION_JOINED: string = ActivitySessionJoinedEvent.EVENT_NAME

Fired when a remote session joins the activity. The resulting event will be an ActivitySessionJoinedEvent.

SESSION_LEFT

SESSION_LEFT: string = ActivitySessionLeftEvent.EVENT_NAME

Fired when a remote session leaves the activity. The resulting event will be an ActivitySessionLeftEvent.

STATE_CLEARED

STATE_CLEARED: string = ActivityStateClearedEvent.EVENT_NAME

Fired when a remote session clears state within the Activity. The resulting event will be an ActivityStateClearedEvent.

STATE_DELTA

STATE_DELTA: string = ActivityStateDeltaEvent.EVENT_NAME

Fired when a remote session makes any changes to state within Activity. The resulting event will be a ActivityStateDeltaEvent.

This is a batch event whereas ActivityStateClearedEvent and ActivityStateSetEvent are fired for individual properties.

STATE_REMOVED

STATE_REMOVED: string = ActivityStateRemovedEvent.EVENT_NAME

Fired when a remote session clears state within the Activity. The resulting event will be an ActivityStateRemovedEvent.

STATE_SET

STATE_SET: string = ActivityStateSetEvent.EVENT_NAME

Fired when a remote session sets state within the Activity. The resulting event will be an ActivityStateSetEvent.