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

- ConvergenceEventEmitter<IActivityEvent>
  - Activity

## Index

### Methods

- addListener
- clearState
- events
- id
- isJoined
- leave
- off
- on
- once
- participant
- participants
- participantsAsObservable
- removeAllListeners
- removeListener
- removeListeners
- removeState
- session
- setState
- state

### Object literals

- Events

## Methods

### addListener

- addListener(event: string, listener: ConvergenceEventListener<IActivityEvent>): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.addListener

  Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.

  #### Parameters

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IActivityEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### clearState

- clearState(): void

- Removes all local state from this Activity.

  #### Returns void

### events

- events(): Observable<IActivityEvent>

- Inherited from ConvergenceEventEmitter.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 unique id of this Activity.

  #### Returns string

  The Activity id.

### isJoined

- isJoined(): boolean

- Determines if the Activity is still joined.

  #### Returns boolean

  True if the Activity is joined, false otherwise.

### leave

- leave(): 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 void

### off

- off(event: string, listener: ConvergenceEventListener<IActivityEvent>): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.off

  Removes a single event listener for a specific event.

  #### Parameters

  - ##### event: string

    The name of the event to remove the listener for.

  - ##### listener: ConvergenceEventListener<IActivityEvent>

    The listener callback to unregister.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### on

- on(event: string, listener: ConvergenceEventListener<IActivityEvent>): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.on

  Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.

  #### Parameters

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IActivityEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### once

- once(event: string, listener: ConvergenceEventListener<IActivityEvent>): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.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

  - ##### event: string

    The name of the event to add the listener for.

  - ##### listener: ConvergenceEventListener<IActivityEvent>

    The listener callback to register.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### participant

- participant(sessionId: string): ActivityParticipant

- Gets an ActivityParticipant by their sessionId.

  #### Parameters

  - ##### sessionId: string

    The sessionId of the participant to get.

  #### Returns ActivityParticipant

  The ActivityParticipant corresponding to the supplied id, or undefined if no such participant exists.

### participants

- participants(): ActivityParticipant[]

- Gets all participants presently joined to this Activity.

  #### Returns ActivityParticipant[]

  An array of ActivityParticipant objects, one for each joined participant.

### participantsAsObservable

- participantsAsObservable(): Observable<ActivityParticipant[]>

- Gets the participants as an Observable stream.

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

  #### Returns Observable<ActivityParticipant[]>

  An Observable array of participants.

### removeAllListeners

- removeAllListeners(): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.removeAllListeners

  Removes all listeners for all events. This is useful for cleanup before disposing of this particular event emitter.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### removeListener

- removeListener(event: string, listener: ConvergenceEventListener<IActivityEvent>): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.removeListener

  Removes a single event listener for a specific event.

  #### Parameters

  - ##### event: string

    The name of the event to remove the listener for.

  - ##### listener: ConvergenceEventListener<IActivityEvent>

    The listener callback to unregister.

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### removeListeners

- removeListeners(event: string): ConvergenceEventEmitter<IActivityEvent>

- Inherited from ConvergenceEventEmitter.removeListeners

  Removes all listeners bound on the given event.

  #### Parameters

  - ##### event: string

    the name of the event to remove listeners for

  #### Returns ConvergenceEventEmitter<IActivityEvent>

  This object, in support of a fluent API.

### removeState

- removeState(key: string): void
- removeState(keys: string[]): void

- Removes a single local state entry from the Activity.

      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.

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

  #### Parameters

  - ##### keys: string[]

    The keys of the local state to remove.

  #### Returns void

### session

- session(): ConvergenceSession

- Gets the session that this activity is a part of.

  #### Returns ConvergenceSession

  The session that this Activity is a part of.

### setState

- setState(key: string, value: any): void
- setState(state: StringMapLike): void

- Sets a single key-delta pair within this Activity's local state.

      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-delta 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.

      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 map containing the key-delta 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.

## Object literals

### StaticEvents

Events: object

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

### 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 = ActivityStateRemovedEvent.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.