Skip to main content
Version: v1

OldestClientObserver Class

The OldestClientObserver is a utility inspect if the local client is the oldest amongst connected clients (in terms of when they connected) and watch for changes.

It is still experimental and under development. Please do try it out, but expect breaking changes in the future.

Signature

export declare class OldestClientObserver extends TypedEventEmitter<IOldestClientObserverEvents> implements IOldestClientObserver

Extends: TypedEventEmitter<IOldestClientObserverEvents

Implements: IOldestClientObserver

Remarks

### Creation

The OldestClientObserver constructor takes an IOldestClientObservable. This is most easily satisfied with either an IContainerRuntime or an IFluidDataStoreRuntime:

// E.g. from within a BaseContainerRuntimeFactory:
protected async containerHasInitialized(runtime: IContainerRuntime) {
const oldestClientObserver = new OldestClientObserver(runtime);
// ...
}
// From within a DataObject
protected async hasInitialized() {
const oldestClientObserver = new OldestClientObserver(this.runtime);
// ...
}

### Usage

To check if the local client is the oldest, use the isOldest() method.

if (oldestClientObserver.isOldest()) {
console.log("I'm the oldest");
} else {
console.log("Someone else is older");
}

### Eventing

OldestClientObserver is an EventEmitter, and will emit events when the local client becomes the oldest and when it is no longer the oldest.

oldestClientObserver.on("becameOldest", () => {
console.log("I'm the oldest now");
});
oldestClientObserver.on("lostOldest", () => {
console.log("I'm not the oldest anymore");
});

Constructors

Constructor Description
(constructor)(observable) Constructs a new instance of the OldestClientObserver class

Methods

Method Return Type Description
isOldest() boolean

Constructor Details

(constructor)

Constructs a new instance of the OldestClientObserver class

Signature

constructor(observable: IOldestClientObservable);

Parameters

Parameter Type Description
observable IOldestClientObservable

Method Details

isOldest

Signature

isOldest(): boolean;

Returns

Return type: boolean