import {Message} from '@statechannels/client-api-schema'; /** * This is the handler that any messaging service implementation should call when receiving a message * The handler is responsible for pushing the message into the appropriate wallet */ export type MessageHandler = (message: Message) => Promise; /** * A MessageServiceFactory is responsible for generating a MessageService. * This is used by the Wallet to construct the messaging service that will be used. * The incomingMessageHandler will be supplied by the Wallet to handle messages. */ export type MessageServiceFactory = ( incomingMessageHandler: MessageHandler ) => MessageServiceInterface; export interface MessageServiceInterface { /** * Sends out the messages to the specified by participants. * @param messages The collection of messages to send */ send(message: Message[]): Promise; // TODO: Is a url/string too restrictive for addressing a peer? /** * Registers a peer so messages can be sent to that peer * @param peerUrl The url for the peer */ registerPeer(peerUrl: string): Promise; /** * This is called when the message service is no longer needed */ destroy(): Promise; }