This extension emits API call related events.
yarn add @rc-ex/events
import RingCentral from '@rc-ex/core';
import EventsExtension, {Events} from '@rc-ex/events';
const rc = new RingCentral(...);
const eventsExtension = new EventsExtension(eventsOptions);
await rc.installExtension(eventsExtension);
eventsExtension.eventEmitter.on(Events.requestSuccess, r => {
console.log(`There is a request error: ${r}`)
})
For a working sample, please check this test case.
EventsExtension
constructor accepts optional EventsOptions
as parameter:
type EventsOptions = {
enabledEvents?: Events[];
};
enabledEvents
specifies which events are enabled:
enum Events {
beforeRequest = 'beforeRequest',
requestSuccess = 'requestSuccess',
requestError = 'requestError',
// enum values below are from
// https://github.com/ringcentral/ringcentral-js/blob/master/sdk/src/platform/Platform.ts
beforeLogin = 'beforeLogin',
loginSuccess = 'loginSuccess',
loginError = 'loginError',
beforeRefresh = 'beforeRefresh',
refreshSuccess = 'refreshSuccess',
refreshError = 'refreshError',
beforeLogout = 'beforeLogout',
logoutSuccess = 'logoutSuccess',
logoutError = 'logoutError',
rateLimitError = 'rateLimitError',
}
If you don't specify this parameter, all events are enabled by default.