Skip to main content
Version: v1.33.0

Stage

A class impementing the Stages SDK

Extends

  • TypedEmitter<StageEventMap>

Constructors

new Stage()

new Stage(token, strategy): Stage

Creates an instance of a Stage

Parameters

ParameterTypeDescription
tokenstringThe token to join this stage as
strategyStageStrategyThe StageStrategy to use for this Stage

Returns

Stage

Overrides

TypedEmitter<StageEventMap>.constructor

Methods

exchangeToken()

exchangeToken(newToken): Promise<void>

Exchanges the current stage token for a new one.

Allows updating token capabilities (PUBLISH/SUBSCRIBE), userId, and/or attributes without disconnecting from the stage. The SDK will automatically:

  • Unpublish if PUBLISH capability is removed
  • Unsubscribe if SUBSCRIBE capability is removed
  • Refresh the strategy to apply new capabilities

Changes are applied optimistically (immediately) and then validated by the server. If the server rejects the exchange, the stage will be left.

Parameters

ParameterTypeDescription
newTokenstringThe new JWT token string

Returns

Promise<void>

Promise that resolves when token exchange is complete

Throws

If token is invalid or exchange fails


hasListenersFor()

hasListenersFor<Event>(event): boolean

Returns a boolean indicating whether an event has actively registered listeners.

Type Parameters

Type Parameter
Event extends keyof StageEventMap

Parameters

ParameterTypeDescription
eventEventthe event to register the callback for

Returns

boolean

Inherited from

TypedEmitter.hasListenersFor


join()

join(): Promise<void>

Joins the stage

Returns

Promise<void>


leave()

leave(): void

Leaves the stage

Returns

void


off()

off<Event>(event, callback, context?): void

Deregister a new callback based on the event provided. The events enum is either linked in the EventMap type or in the root of the class.

Type Parameters

Type Parameter
Event extends keyof StageEventMap

Parameters

ParameterTypeDescription
eventEventthe event to de-register the callback for
callbackStageEventMap[Event]the callback to be de-registered
context?any-

Returns

void

Inherited from

TypedEmitter.off


on()

on<Event>(event, callback, context?): void

Register a new callback based on the event provided. The events enum is either linked in the EventMap type or in the root of the class.

Type Parameters

Type Parameter
Event extends keyof StageEventMap

Parameters

ParameterTypeDescription
eventEventthe event to register the callback for
callbackStageEventMap[Event]the callback to be invoked for the event
context?any-

Returns

void

Inherited from

TypedEmitter.on


refreshStrategy()

refreshStrategy(): void

Re-executes the StageStrategy

Returns

void


replaceStrategy()

replaceStrategy(strategy): void

Updates and re-executes the StageStrategy

Parameters

ParameterTypeDescription
strategyStageStrategyThe new StageStrategy for the stage

Returns

void