Refinitiv Data Platform Library for TypeScript

Session events

Session Event provides a set of events that can be emitted by the Session object. Session events can be registered on a session using the session.on method. The method accepts two arguments: the event name to listen, and a callback function that will be fired once the specified event is emitted by session.

Syntax

session.on(event: Session.Event, callback: (...args: any[]) => void)

Depending on the event type, the callback function can receive different arguments.

Session.Event.Error

Emits whenever an error occurs. The error is passed as a parameter to the callback function.

Callback parameters

Value Description Data type Optional Default value
error Object that contains the error message and the event name Error - -

Session.Event.StateChanged

Emits whenever the state of a session changes. It includes the new state as a parameter.

Callback parameters

Value Description Data type Optional Default value
error Object that contains the error message and the event name Error - -
state The state of the session Session.State - -

Session.Event.EventReceived

Emits on every authentication event.

Callback parameters

Value Description Data type Optional Default value
error Object that contains the error message and the event name Error - -
state The state of the session Session.State - -

Usage

import { Session } from '@refinitiv-data/data';

const session = Session.Desktop.Definition({ appKey: process.env.APP_KEY! }).getSession();

session.on(Session.Event.StateChanged, (session, state) => console.log('Session state:', state));
session.on(Session.Event.EventReceived, (session, event) => console.log('Event received:', event));
session.on(Session.Event.Error, err => console.log(err));

Session State