diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.js b/src/core/endpoints/subscriptionUtils/receiveMessages.js index 5d259d868..b62c3acb3 100644 --- a/src/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/src/core/endpoints/subscriptionUtils/receiveMessages.js @@ -37,7 +37,7 @@ const endpoint = { } outParams.tt = params.timetoken; outParams.tr = params.region; - outParams.ee=''; + outParams.ee = ''; return outParams; }, diff --git a/src/event-engine/core/retryPolicy.ts b/src/event-engine/core/retryPolicy.ts index 0677e1b92..24de99a14 100644 --- a/src/event-engine/core/retryPolicy.ts +++ b/src/event-engine/core/retryPolicy.ts @@ -22,9 +22,9 @@ export class RetryPolicy { maximumRetry: configuration.maximumRetry, shouldRetry(error: any, attempt: number) { - if (error?.status?.statusCode === 403) { - return false; - } + if (error?.status?.statusCode === 403) { + return false; + } return this.maximumRetry > attempt; }, diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index 2b26aae5f..8b6417450 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -130,39 +130,37 @@ export class EventEngineDispatcher extends Dispatcher { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - - await delay(config.retryConfiguration.getDelay(payload.attempts)); - - abortSignal.throwIfAborted(); - - try { - const result = await handshake({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - filterExpression: config.filterExpression, - state: presenceState, - }); - - return engine.transition(events.handshakingReconnectingSuccess(result)); - } catch (error) { - if (error instanceof Error && error.message === 'Aborted') { - return; - } - - if (error instanceof PubNubError) { - return engine.transition(events.handshakingReconnectingFailure(error)); - } + asyncHandler(async (payload, abortSignal, { handshake, delay, presenceState, config }) => { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + + await delay(config.retryConfiguration.getDelay(payload.attempts)); + + abortSignal.throwIfAborted(); + + try { + const result = await handshake({ + abortSignal: abortSignal, + channels: payload.channels, + channelGroups: payload.groups, + filterExpression: config.filterExpression, + state: presenceState, + }); + + return engine.transition(events.handshakingReconnectingSuccess(result)); + } catch (error) { + if (error instanceof Error && error.message === 'Aborted') { + return; + } + + if (error instanceof PubNubError) { + return engine.transition(events.handshakingReconnectingFailure(error)); } - } else { - return engine.transition(events.handshakingReconnectingGiveup()); } - }, - ), + } else { + return engine.transition(events.handshakingReconnectingGiveup()); + } + }), ); } } diff --git a/src/event-engine/events.ts b/src/event-engine/events.ts index 21e91aff2..5495d06ed 100644 --- a/src/event-engine/events.ts +++ b/src/event-engine/events.ts @@ -45,7 +45,7 @@ export const reconnectingSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', (cur export const reconnectingFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error: PubNubError) => error); export const reconnectingGiveup = createEvent('RECEIVING_RECONNECTING_GIVEUP', () => ({})); export const reconnectingRetry = createEvent('RECONNECT', () => ({})); -export const unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', () => {}); +export const unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', () => ({})); export type Events = MapOf< | typeof subscriptionChange diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 02f86914c..c4dad0d09 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -63,11 +63,11 @@ export class EventEngine { } unsubscribe({ channels, groups }: { channels?: string[]; groups?: string[] }) { - let channlesWithPres: any = channels?.slice(0); + const channlesWithPres: any = channels?.slice(0); channels?.map((c) => channlesWithPres.push(`${c}-pnpres`)); this.channels = this.channels.filter((channel) => !channlesWithPres?.includes(channel)); - let groupsWithPres: any = groups?.slice(0); + const groupsWithPres: any = groups?.slice(0); groups?.map((g) => groupsWithPres.push(`${g}-pnpres`)); this.groups = this.groups.filter((group) => !groupsWithPres?.includes(group)); diff --git a/src/event-engine/presence/states/heartbeat_failed.ts b/src/event-engine/presence/states/heartbeat_failed.ts index 628d309ad..14fadf591 100644 --- a/src/event-engine/presence/states/heartbeat_failed.ts +++ b/src/event-engine/presence/states/heartbeat_failed.ts @@ -46,6 +46,6 @@ HeartbeatFailedState.on(disconnect.type, (context, _) => ), ); -HeartbeatFailedState.on(leftAll.type, (context,_) => +HeartbeatFailedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]), );