EphemeralEvent class

Ephemeral fluid object that broadcasts an event to other clients and a set of static event related helpers.

remarks

Applications should call on('received', (evt, local) => {}) to listen for local events sent and remote events received. Events aren't guaranteed to be delivered so you should limit their use to sending events you're ok with potentially being missed. Reactions are a good use case for EphemeralEvents. Use something like the EphemeralState class when syncing state.

Extends

DataObject<{ Events: IEphemeralEventEvents<TEvent> }>

Constructors

EphemeralEvent(IDataObjectProps<{ Events: IEphemeralEventEvents<TEvent> }>)

Properties

disposed
factory

The objects fluid type factory.

handle

Handle to a data store

id
IFluidHandle
IFluidLoadable
IFluidRouter
isStarted

Returns true if the object has been started.

TypeName

The objects fluid type/name.

Inherited Properties

addListener
off
on
once
prependListener
prependOnceListener
removeListener

Methods

getClientRoles(string)

Returns the list of roles supported for a client.

getTimestamp()

Returns the current timestamp as the number of milliseconds sine the Unix Epoch.

isNewer(IEphemeralEvent | undefined, IEphemeralEvent, undefined | number)

Returns true if a received event is newer then the current event.

remarks

Used when building new Ephemeral objects to process state change events. The isNewer() method implements an algorithm that deals with conflicting events that have the same timestamp and older events that should have debounced the current event.

  • When the received event has the same timestamp as the current event, each events clientId will be used as a tie breaker. The clientId containing the lower sort order wins any ties.
  • Older events are generally ignored unless a debounce period is specified. An older event that should have debounced the current event will be considered newer.

The algorithm employed by isNewer() helps ensure that all clients will eventually reach a consistent state with one other.

sendEvent(Partial<TEvent>)

Broadcasts an event to all other clients.

remarks

The event will be queued for delivery if the client isn't currently connected.

start(UserMeetingRole[])

Starts the object.

verifyRolesAllowed(string, UserMeetingRole[])

Verifies that a client has one of the specified roles.

Inherited Methods

dispose()

Called when the host container closes and disposes itself

emit(string | symbol, any[])
eventNames()
finishInitialization(boolean)

Call this API to ensure PureDataObject is fully initialized initialization happens on demand, only on as-needed bases. In most cases you should allow factory/object to decide when to finish initialization. But if you are supplying your own implementation of DataStoreRuntime factory and overriding some methods and need fully initialized object, then you can call this API to ensure object is fully initialized.

getDataObject(IFluidDataStoreRuntime)
getFluidObjectFromDirectory<T>(string, IDirectory, undefined | (id: string, directory: IDirectory) => IFluidHandle | undefined)

Retrieve Fluid object using the handle get

getMaxListeners()
initializeInternal(boolean)

Initializes internal objects and calls initialization overrides. Caller is responsible for ensuring this is only invoked once.

listenerCount(string | symbol)
listeners(string | symbol)
rawListeners(string | symbol)
removeAllListeners(string | symbol)
request(IRequest)
setMaxListeners(number)

Constructor Details

EphemeralEvent(IDataObjectProps<{ Events: IEphemeralEventEvents<TEvent> }>)

new EphemeralEvent(props: IDataObjectProps<{ Events: IEphemeralEventEvents<TEvent> }>)

Parameters

props

IDataObjectProps<{ Events: IEphemeralEventEvents<TEvent> }>

Property Details

disposed

boolean disposed

Property Value

boolean

factory

The objects fluid type factory.

static factory: DataObjectFactory<EphemeralEvent<IEphemeralEvent>, DataObjectTypes>

Property Value

DataObjectFactory<EphemeralEvent<IEphemeralEvent>, DataObjectTypes>

handle

Handle to a data store

IFluidHandle<this> handle

Property Value

IFluidHandle<this>

id

string id

Property Value

string

IFluidHandle

IFluidHandle<this> IFluidHandle

Property Value

IFluidHandle<this>

IFluidLoadable

this IFluidLoadable

Property Value

this

IFluidRouter

this IFluidRouter

Property Value

this

isStarted

Returns true if the object has been started.

boolean isStarted

Property Value

boolean

TypeName

The objects fluid type/name.

static TypeName: "@microsoft/live-share:EphemeralEvent" = "@microsoft/live-share:EphemeralEvent"

Property Value

"@microsoft/live-share:EphemeralEvent"

Inherited Property Details

addListener

addListener: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

off

off: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

on

on: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

once

once: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

prependListener

prependListener: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

prependOnceListener

prependOnceListener: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

removeListener

removeListener: TypedEventTransform<this, I["Events"] & IEvent>

Property Value

TypedEventTransform<this, I["Events"] & IEvent>

Method Details

getClientRoles(string)

Returns the list of roles supported for a client.

static function getClientRoles(clientId: string): Promise<UserMeetingRole[]>

Parameters

clientId

string

Client ID to lookup.

Returns

Promise<UserMeetingRole[]>

The list of roles for the client.

getTimestamp()

Returns the current timestamp as the number of milliseconds sine the Unix Epoch.

static function getTimestamp(): number

Returns

number

isNewer(IEphemeralEvent | undefined, IEphemeralEvent, undefined | number)

Returns true if a received event is newer then the current event.

remarks

Used when building new Ephemeral objects to process state change events. The isNewer() method implements an algorithm that deals with conflicting events that have the same timestamp and older events that should have debounced the current event.

  • When the received event has the same timestamp as the current event, each events clientId will be used as a tie breaker. The clientId containing the lower sort order wins any ties.
  • Older events are generally ignored unless a debounce period is specified. An older event that should have debounced the current event will be considered newer.

The algorithm employed by isNewer() helps ensure that all clients will eventually reach a consistent state with one other.

static function isNewer(current: IEphemeralEvent | undefined, received: IEphemeralEvent, debouncePeriod?: undefined | number): boolean

Parameters

current

IEphemeralEvent | undefined

Current event to compare received event against.

received
IEphemeralEvent

Received event.

debouncePeriod

undefined | number

Optional. Time in milliseconds to ignore any new events for. Defaults to 0 ms.

Returns

boolean

True if the received event is newer then the current event and should replace the current one.

sendEvent(Partial<TEvent>)

Broadcasts an event to all other clients.

remarks

The event will be queued for delivery if the client isn't currently connected.

function sendEvent(evt?: Partial<TEvent>): TEvent

Parameters

evt

Partial<TEvent>

Optional. Event to send. If omitted, an event will still be sent but it won't include any custom event data.

Returns

TEvent

The full event object that was sent, including the timestamp of when the event was sent and the clientId if known. The clientId will be undefined if the client is disconnected at time of delivery.

start(UserMeetingRole[])

Starts the object.

function start(allowedRoles?: UserMeetingRole[]): Promise<void>

Parameters

allowedRoles

UserMeetingRole[]

Optional. List of roles allowed to send events.

Returns

Promise<void>

verifyRolesAllowed(string, UserMeetingRole[])

Verifies that a client has one of the specified roles.

static function verifyRolesAllowed(clientId: string, allowedRoles: UserMeetingRole[]): Promise<boolean>

Parameters

clientId

string

Client ID to inspect.

allowedRoles

UserMeetingRole[]

User roles that are allowed.

Returns

Promise<boolean>

True if the client has one of the specified roles.

Inherited Method Details

dispose()

Called when the host container closes and disposes itself

function dispose()

emit(string | symbol, any[])

function emit(event: string | symbol, args: any[]): boolean

Parameters

event

string | symbol

args

any[]

Returns

boolean

eventNames()

function eventNames(): Array<string | symbol>

Returns

Array<string | symbol>

finishInitialization(boolean)

Call this API to ensure PureDataObject is fully initialized initialization happens on demand, only on as-needed bases. In most cases you should allow factory/object to decide when to finish initialization. But if you are supplying your own implementation of DataStoreRuntime factory and overriding some methods and need fully initialized object, then you can call this API to ensure object is fully initialized.

function finishInitialization(existing: boolean): Promise<void>

Parameters

existing

boolean

Returns

Promise<void>

getDataObject(IFluidDataStoreRuntime)

static function getDataObject(runtime: IFluidDataStoreRuntime): Promise<PureDataObject<DataObjectTypes>>

Parameters

runtime

IFluidDataStoreRuntime

Returns

Promise<PureDataObject<DataObjectTypes>>

getFluidObjectFromDirectory<T>(string, IDirectory, undefined | (id: string, directory: IDirectory) => IFluidHandle | undefined)

Retrieve Fluid object using the handle get

function getFluidObjectFromDirectory<T>(key: string, directory: IDirectory, getObjectFromDirectory?: undefined | (id: string, directory: IDirectory) => IFluidHandle | undefined): Promise<T | undefined>

Parameters

key

string

key that object (handle/id) is stored with in the directory

directory

IDirectory

directory containing the object

getObjectFromDirectory

undefined | (id: string, directory: IDirectory) => IFluidHandle | undefined

optional callback for fetching object from the directory, allows users to define custom types/getters for object retrieval

Returns

Promise<T | undefined>

getMaxListeners()

function getMaxListeners(): number

Returns

number

initializeInternal(boolean)

Initializes internal objects and calls initialization overrides. Caller is responsible for ensuring this is only invoked once.

function initializeInternal(existing: boolean): Promise<void>

Parameters

existing

boolean

Returns

Promise<void>

listenerCount(string | symbol)

function listenerCount(event: string | symbol): number

Parameters

event

string | symbol

Returns

number

listeners(string | symbol)

function listeners(event: string | symbol): Function[]

Parameters

event

string | symbol

Returns

Function[]

rawListeners(string | symbol)

function rawListeners(event: string | symbol): Function[]

Parameters

event

string | symbol

Returns

Function[]

removeAllListeners(string | symbol)

function removeAllListeners(event?: string | symbol): this

Parameters

event

string | symbol

Returns

this

request(IRequest)

function request(request: IRequest): Promise<IResponse>

Parameters

request

IRequest

Returns

Promise<IResponse>

setMaxListeners(number)

function setMaxListeners(n: number): this

Parameters

n

number

Returns

this