forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
FileOutboundTransport.ts
40 lines (32 loc) · 1.23 KB
/
FileOutboundTransport.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { Agent, Logger, FileSystem, OutboundTransport, OutboundPackage } from '@aries-framework/core'
import { AgentConfig, JsonEncoder } from '@aries-framework/core'
export class FileOutboundTransport implements OutboundTransport {
private agent!: Agent
private logger!: Logger
private agentConfig!: AgentConfig
private FileSystem!: FileSystem
private alias: string
private file: string
public supportedSchemes: string[]
public constructor({ schema, alias }: { schema: string; alias: string }) {
this.supportedSchemes = [schema]
this.file = `${schema}.json`
this.alias = alias
}
public async start(agent: Agent): Promise<void> {
this.agent = agent
this.agentConfig = agent.dependencyManager.resolve(AgentConfig)
this.logger = this.agentConfig.logger
this.FileSystem = new this.agentConfig.agentDependencies.FileSystem()
this.logger.debug('Starting File outbound transport')
}
public async stop(): Promise<void> {
this.logger.debug('Stopping File outbound transport')
}
public async sendMessage(outboundPackage: OutboundPackage) {
const data = JsonEncoder.toString({
[this.alias]: outboundPackage.payload,
})
await this.FileSystem.write(this.file, data)
}
}