Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-afj-0-4-0
Browse files Browse the repository at this point in the history
  • Loading branch information
genaris authored Sep 28, 2023
2 parents 973eaeb + 7bd3e43 commit cb8a4f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
7 changes: 7 additions & 0 deletions packages/transport-ble/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

### [0.2.1](https://www.github.com/hyperledger/aries-framework-javascript-ext/compare/transport-ble-v0.2.0...transport-ble-v0.2.1) (2023-09-18)


### Bug Fixes

* loosen types on ble inbound and outbound transport and session ([#226](https://www.github.com/hyperledger/aries-framework-javascript-ext/issues/226)) ([17c6203](https://www.github.com/hyperledger/aries-framework-javascript-ext/commit/17c6203b398ad2fd613bc237e2c852a86f44c444))

## [0.2.0](https://www.github.com/hyperledger/aries-framework-javascript-ext/compare/transport-ble-v0.1.0...transport-ble-v0.2.0) (2023-06-29)


Expand Down
2 changes: 1 addition & 1 deletion packages/transport-ble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@aries-framework/transport-ble",
"main": "build/index",
"types": "build/index",
"version": "0.2.0",
"version": "0.2.1",
"files": [
"build"
],
Expand Down
18 changes: 9 additions & 9 deletions packages/transport-ble/src/transports/BleInboundTransport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Central } from '@animo-id/react-native-ble-didcomm'
import type { Ble } from '@animo-id/react-native-ble-didcomm'
import type { Agent, InboundTransport, Logger } from '@aries-framework/core'
import type { EmitterSubscription } from 'react-native'

Expand All @@ -8,22 +8,22 @@ import { BleTransportSession } from './BleTransportSession'

export class BleInboundTransport implements InboundTransport {
public supportedSchemes: string[] = ['ble']
private central: Central
private messenger: Ble
private messageListener?: EmitterSubscription
private session!: BleTransportSession
private disconnectionListener?: EmitterSubscription
private logger?: Logger

public constructor(central: Central) {
this.central = central
public constructor(messenger: Ble) {
this.messenger = messenger
}

public async start(agent: Agent): Promise<void> {
this.logger = agent.config.logger
this.logger.debug('Starting BLE inbound transport')

const sessionId = utils.uuid()
this.session = new BleTransportSession(sessionId, this.central, agent)
this.session = new BleTransportSession(sessionId, this.messenger, agent.context)

const messageListener = async (data: { message: string }) => {
const message = data.message
Expand All @@ -37,11 +37,11 @@ export class BleInboundTransport implements InboundTransport {
session: this.session,
})
} catch (error) {
agent.config.logger.error(`Error processing message: ${error}`)
this.logger?.error(`Error processing message: ${error}`)
}
}

this.messageListener = this.central.registerMessageListener(messageListener)
this.messageListener = this.messenger.registerMessageListener(messageListener)

const disconnectionListener = async (data: { identifier: string }) => {
this.logger?.debug('BLE disconnection detected', { data })
Expand All @@ -50,14 +50,14 @@ export class BleInboundTransport implements InboundTransport {
transportService.removeSession(this.session)
}

this.disconnectionListener = this.central.registerOnDisconnectedListener(disconnectionListener)
this.disconnectionListener = this.messenger.registerOnDisconnectedListener(disconnectionListener)
}

public async stop(): Promise<void> {
this.logger?.debug('Stopping BLE inbound transport')

this.messageListener?.remove()
this.disconnectionListener?.remove()
await this.central.shutdown()
await this.messenger.shutdown()
}
}
14 changes: 7 additions & 7 deletions packages/transport-ble/src/transports/BleOutboundTransport.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { Peripheral } from '@animo-id/react-native-ble-didcomm'
import type { Ble } from '@animo-id/react-native-ble-didcomm'
import type { Agent, Logger, OutboundPackage, OutboundTransport } from '@aries-framework/core'

import { AriesFrameworkError } from '@aries-framework/core'

export class BleOutboundTransport implements OutboundTransport {
public supportedSchemes: string[] = ['ble']
private peripheral: Peripheral
private messenger: Ble
private logger?: Logger

public constructor(peripheral: Peripheral) {
this.peripheral = peripheral
public constructor(messenger: Ble) {
this.messenger = messenger
}

public async start(agent: Agent): Promise<void> {
this.logger = agent.config.logger

agent.config.logger.debug('Starting BLE outbound transport')
this.logger.debug('Starting BLE outbound transport')
}

public async sendMessage(outboundPackage: OutboundPackage): Promise<void> {
Expand All @@ -31,11 +31,11 @@ export class BleOutboundTransport implements OutboundTransport {
const serializedMessage = JSON.stringify(payload)

this.logger?.debug('Sending BLE outbound message')
await this.peripheral.sendMessage(serializedMessage)
await this.messenger.sendMessage(serializedMessage)
}

public async stop(): Promise<void> {
this.logger?.debug('Stopping BLE outbound transport')
await this.peripheral.shutdown()
await this.messenger.shutdown()
}
}
21 changes: 11 additions & 10 deletions packages/transport-ble/src/transports/BleTransportSession.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import type { Central } from '@animo-id/react-native-ble-didcomm'
import type { Agent, AgentContext, EncryptedMessage, TransportSession } from '@aries-framework/core'
import type { Ble } from '@animo-id/react-native-ble-didcomm'
import type { AgentContext, EncryptedMessage, TransportSession } from '@aries-framework/core'

import { utils } from '@aries-framework/core'

export class BleTransportSession implements TransportSession {
public readonly type = 'ble'
public id: string
private agent: Agent
private central: Central

public constructor(id: string, central: Central, agent: Agent) {
private agentContext: AgentContext
private messenger: Ble

public constructor(id: string, messenger: Ble, agentContext: AgentContext) {
this.id = id ?? utils.uuid()
this.agent = agent
this.central = central
this.messenger = messenger
this.agentContext = agentContext
}

public async send(agentContext: AgentContext, encryptedMessage: EncryptedMessage): Promise<void> {
const serializedMessage = JSON.stringify(encryptedMessage)

this.agent.config.logger.debug('Sending BLE inbound message via session')
await this.central.sendMessage(serializedMessage)
agentContext.config.logger.debug('Sending BLE inbound message via session')
await this.messenger.sendMessage(serializedMessage)
}

public async close(): Promise<void> {
this.agent.config.logger.debug('Stopping BLE inbound session')
this.agentContext.config.logger.debug('Stopping BLE inbound session')
}
}

0 comments on commit cb8a4f5

Please sign in to comment.