Skip to content

Commit

Permalink
fix(routing): sending of trustping in pickup v2 (#787)
Browse files Browse the repository at this point in the history
Signed-off-by: KolbyRKunz <[email protected]>
  • Loading branch information
KolbyRKunz authored May 26, 2022
1 parent baf62dd commit 45b024d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/modules/routing/RecipientModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 45b024d

Please sign in to comment.