diff --git a/src/MediaSharingApi.ts b/src/MediaSharingApi.ts index 7d59609..b87b3d8 100644 --- a/src/MediaSharingApi.ts +++ b/src/MediaSharingApi.ts @@ -5,7 +5,7 @@ import { MessageSender, OutboundMessageContext, } from '@aries-framework/core' -import { ShareMediaHandler } from './handlers' +import { RequestMediaHandler, ShareMediaHandler } from './handlers' import { MediaSharingRecord, SharedMediaItem, SharedMediaItemOptions } from './repository' import { MediaSharingService } from './services' @@ -49,7 +49,10 @@ export class MediaSharingApi { this.connectionService = connectionService this.agentContext = agentContext - this.agentContext.dependencyManager.registerMessageHandlers([new ShareMediaHandler(this.mediaSharingService)]) + this.agentContext.dependencyManager.registerMessageHandlers([ + new ShareMediaHandler(this.mediaSharingService), + new RequestMediaHandler(this.mediaSharingService), + ]) } /** diff --git a/src/handlers/RequestMediaHandler.ts b/src/handlers/RequestMediaHandler.ts new file mode 100644 index 0000000..5bb2c3c --- /dev/null +++ b/src/handlers/RequestMediaHandler.ts @@ -0,0 +1,18 @@ +import { MessageHandler, MessageHandlerInboundMessage } from '@aries-framework/core' +import { MediaSharingService } from '../services' +import { RequestMediaMessage } from '../messages' + +export class RequestMediaHandler implements MessageHandler { + public supportedMessages = [RequestMediaMessage] + private mediaSharingService: MediaSharingService + + public constructor(mediaSharingService: MediaSharingService) { + this.mediaSharingService = mediaSharingService + } + + public async handle(inboundMessage: MessageHandlerInboundMessage) { + inboundMessage.assertReadyConnection() + + // Nothing to do internally. Will be handled by the controller + } +} diff --git a/src/handlers/index.ts b/src/handlers/index.ts index 2c19173..fdbe1aa 100644 --- a/src/handlers/index.ts +++ b/src/handlers/index.ts @@ -1 +1,2 @@ +export * from './RequestMediaHandler' export * from './ShareMediaHandler' diff --git a/src/messages/RequestMediaMessage.ts b/src/messages/RequestMediaMessage.ts index 6d6fb31..5fbb872 100644 --- a/src/messages/RequestMediaMessage.ts +++ b/src/messages/RequestMediaMessage.ts @@ -2,36 +2,6 @@ import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-frame import { DateParser } from '@aries-framework/core/build/utils/transformers' import { Expose, Transform } from 'class-transformer' import { IsDate, IsOptional, IsString } from 'class-validator' -import { CipheringInfo } from '../repository' - -interface SharedMediaItemDescriptorOptions { - id: string - attachmentId: string - description?: string - ciphering?: CipheringInfo - metadata?: Record -} - -class SharedMediaItemDescriptor { - @Expose({ name: '@id' }) - public id!: string - - @Expose({ name: 'attachment_id' }) - public attachmentId!: string - - public ciphering?: CipheringInfo - - public metadata?: Record - - public constructor(options: SharedMediaItemDescriptorOptions) { - if (options) { - this.id = options.id - this.attachmentId = options.attachmentId - this.ciphering = options.ciphering - this.metadata = options.metadata - } - } -} export interface RequestMediaMessageOptions { id?: string