diff --git a/packages/core/src/modules/routing/RecipientModule.ts b/packages/core/src/modules/routing/RecipientModule.ts index 6c60994e7c..5849556b1c 100644 --- a/packages/core/src/modules/routing/RecipientModule.ts +++ b/packages/core/src/modules/routing/RecipientModule.ts @@ -162,17 +162,20 @@ export class RecipientModule { `Websocket connection to mediator with connectionId '${mediator.connectionId}' is closed, attempting to reconnect...` ) try { - await this.openMediationWebSocket(mediator) if (mediator.pickupStrategy === MediatorPickupStrategy.PickUpV2) { // Start Pickup v2 protocol to receive messages received while websocket offline await this.sendStatusRequest({ mediatorId: mediator.id }) + } else { + await this.openMediationWebSocket(mediator) } } catch (error) { this.logger.warn('Unable to re-open websocket connection to mediator', { error }) } }) try { - await this.openMediationWebSocket(mediator) + if (mediator.pickupStrategy === MediatorPickupStrategy.Implicit) { + await this.openMediationWebSocket(mediator) + } } catch (error) { this.logger.warn('Unable to open websocket connection to mediator', { error }) } diff --git a/packages/core/src/modules/routing/services/MediationRecipientService.ts b/packages/core/src/modules/routing/services/MediationRecipientService.ts index f746d69f61..3260979940 100644 --- a/packages/core/src/modules/routing/services/MediationRecipientService.ts +++ b/packages/core/src/modules/routing/services/MediationRecipientService.ts @@ -261,8 +261,26 @@ export class MediationRecipientService { mediationRecord.assertRole(MediationRole.Recipient) //No messages to be sent - if (messageCount === 0) return null + if (messageCount === 0) { + const { message, connectionRecord } = await this.connectionService.createTrustPing(connection, { + responseRequested: false, + }) + const websocketSchemes = ['ws', 'wss'] + + await this.messageSender.sendMessage(createOutboundMessage(connectionRecord, message), { + transportPriority: { + schemes: websocketSchemes, + restrictive: true, + // TODO: add keepAlive: true to enforce through the public api + // we need to keep the socket alive. It already works this way, but would + // be good to make more explicit from the public facing API. + // This would also make it easier to change the internal API later on. + // keepAlive: true, + }, + }) + return null + } const { maximumMessagePickup } = this.config const limit = messageCount < maximumMessagePickup ? messageCount : maximumMessagePickup