# Control Plane

> Enables participants to publish connection offers, allowing other participants to connect and communicate with them securely. It is an interface that integrates with the Affinidi Meeting Place API service.

## Install Dependency

Package: meeting_place_control_plane

```bash
dart pub add meeting_place_control_plane
```

Check the latest version on the [pub.dev registry](https://pub.dev/packages/meeting_place_control_plane) or view the source on [GitHub](https://github.com/affinidi/affinidi-meetingplace-sdk-dart/tree/main/packages/meeting_place_control_plane).

## Classes and Methods

### ControlPlaneSDK

The ControlPlaneSDK provides the libraries to enable the discovery of other participants to establish a connection and communicate securely. It enables participants to publish a connection offer to allow other participants to communicate directly or through group chat. Through discovery, organisations and AI agents can publish their connection offers to allow users to connect and start using their services.

To create an instance of ControlPlaneSDK, you can use its generative constructor.

```dart
// create instance
final controlPlaneSDK = ControlPlaneSDK(
    didManager: didManager,
    controlPlaneDid: '',
    mediatorDid: '',
    didResolver: didResolver,
    controlPlaneSDKConfig: ControlPlaneSDKOptions(
      maxRetries: 5,
      maxRetriesDelay: Duration(seconds: 2),
      connectTimeout: Duration(seconds: 10),
      receiveTimeout: Duration(seconds: 10),
    ),
);
```

#### execute

Executes a command by dispatching it to the appropriate handler based on the provided DiscoveryCommand, and returns the result as a generic type corresponding to the command.

Parameters

    command
    DiscoveryCommand<T>
    Required
  A generic command object that encapsulates the data and parameters required for a specific operation.
Each DiscoveryCommand is dispatched to its corresponding handler, which processes the command and returns a result of the expected type. See the [list](#list-of-discovery-commands) of available Discovery Commands below for more details.

Example

```dart
import 'package:meeting_place_control_plane/meeting_place_control_plane.dart';

// create an instance of DiscoverySDK
final ControlPlaneSDK controlPlaneSDK = ControlPlaneSDK(
    ...
);

// execute AcceptOfferCommand
final result = await controlPlaneSDK.execute(
    AcceptOfferCommand(
        mnemonic: mnemonic, 
        device: device, 
        offerLink: offerLink, 
        contactCard: contactCard, 
        acceptOfferDid: acceptOfferDid)
    );
```

### List of Discovery Commands

#### AcceptOfferCommand

The command for accepting a connection offer from another participant. This command initiates the acceptance process, which establishes a secure communication channel between the accepting user and the offer publisher. Upon successful execution, both parties can begin secure messaging and data exchange.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    offerLink
    string
    Required
  The id of an offer.

    contactCard
    ContactCard
    Required
  An object that represents the profile of a user.

    acceptOfferDid
    string
    Required
  The DID of the accepted offer.

#### AcceptOfferGroupCommand

The command for accepting a group offer from another participant. This command initiates the process of joining an existing group chat, establishing a secure connection with the group and enabling the user to participate in group messaging and communication.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    offerLink
    string
    Required
  The id of an offer.

    contactCard
    ContactCard
    Required
  An object that represents the profile of a user.

    acceptOfferDid
    string
    Required
  The DID of the accepted offer.

#### AuthenticateCommand

The command to authenticate with the Meeting Place service. This command validates the control plane DID and establishes the necessary credentials to perform operations such as registering offers, accepting connections, and managing group communications.

Parameters

    controlPlaneDid
    string
    Required
  The control plane DID.

#### CreateOobCommand

The command to create an Out-Of-Band invitation. This command generates an OOB invitation message that can be shared with other participants through external channels (email, QR codes, etc.) to initiate secure connection establishment.

Parameters

    oobInvitationMessage
    object
    Required
  An object that represents an Out-Of-Band invitation message.

    mediatorDid
    string
    Optional
  The mediator DID.

#### DeletePendingNotificationsCommand

The command to delete pending notifications. This command removes notifications that are no longer needed or have been processed, helping to keep the notification queue clean and manageable.

Parameters

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    notificationIds
    List<String>
    Required
  The list of notification Ids to be deleted.

#### DeregisterNotificationCommand

The command to deregister notifications. This command is used to remove a notification token from the system.

Parameters

    notificationToken
    string
    Required
  The notification token to be deregistered for notification.

#### DeregisterOfferCommand

The command to deregister an offer. This command is used to remove a previously registered offer from the system.

Parameters

    offerLink
    string
    Required
  The id of an offer.

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

#### FinaliseAcceptanceCommand

The command to finalise the acceptance of an offer. This command is used to complete the process of accepting an offer and establishing a connection.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    offerLink
    string
    Required
  The id of an offer.

    offerPublishedDid
    string
    Required
  The published offer’s DID.

    otherPartyAcceptOfferDid
    string
    Required
  The DID of the other party when they have accepted the offer.

    otherPartyPermanentChannelDid
    string
    Required
  The Channel DID of the other party that gets established upon completion of the offer to connect.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    contactCard
    ContactCard
    Optional
  An optional contact card representing the profile of a user or group.

#### GetOobCommand

The command to fetch the Out-Of-Band invitation information. This command is used to retrieve the details of an OOB invitation using its unique identifier.

Parameters

    oobId
    string
    Required
  The Out-Of-Band ID used to query the OOB invitation.

#### GetPendingNotificationsCommand

The command to fetch pending notifications. This command is used to retrieve notifications that are awaiting processing.

Parameters

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    onChatActivityCallback
    function
    Optional
  A callback function that gets invoked when receiving a notification event.

#### GroupAddMemberCommand

The command to add a member to a group. This command is used to include a new participant in an existing group chat.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    groupId
    string
    Required
  The id of the group where the member will be added.

    memberDid
    string
    Required
  The DID of the member.

    acceptOfferDid
    string
    Required
  The DID of the accepted offer.

    offerLink
    string
    Required
  The id of an offer.

    publicKey
    string
    Required
  The member’s public key.

    reencryptionKey
    string
    Required
  The re-encryption key.

    contactCard
    ContactCard
    Optional
  An optional contact card representing the profile of a user or group.

#### GroupDeleteCommand

The command to delete a group. This command is used to remove an existing group chat.

Parameters

    groupId
    string
    Required
  The id of the group chat.

#### GroupDeregisterMemberCommand

The command to remove a member in a group. This command is used to remove a participant from an existing group chat.

Parameters

    groupId
    string
    Required
  The id of the group chat.

    memberId
    string
    Required
  The id of the group member.

    message
    object
    Required
  The Plain Text Message.

#### GroupSendMessageCommand

The command to send a message to a group. This command is used to send a message to all members of a group chat.

Parameters

    offerLink
    string
    Required
  The id of an offer.

    fromDid
    string
    Required
  The DID of the sender of the group message.

    groupDid
    string
    Required
  The DID of the group.

    message
    object
    Required
  An object that represents a DIDComm v2 Plain Text Message.

    increaseSequenceNumber
    bool
    Required
  A flag that indicates whether to increase the sequence number when sending a message. This is used to track the message sequence in a group chat setting.

    notify
    bool
    Required
  A flag that indicates whether to notify the group of new messages.

    ephemeral
    bool
    Required
  A flag that indicates whether the message is supposed to be short-lived.

    forwardExpiryInSeconds
    int
    Optional
  The forward expiry notification of the message in seconds.

#### NotifyAcceptanceCommand

The command to notify that the offer has been accepted. This command is used to inform the offer publisher that their offer has been accepted by another participant.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    acceptOfferDid
    string
    Required
  The DID of the accepted offer.

    offerLink
    string
    Required
  The id of an offer.

#### NotifyAcceptanceGroupCommand

The command to notify that the offer to join a group has been accepted. This command is used to inform the group offer publisher that their offer has been accepted by another participant.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

    acceptOfferDid
    string
    Required
  The DID of the accepted offer.

    offerLink
    string
    Required
  The id of an offer.

#### NotifyChannelCommand

The command to notify a channel. This command is used to send a notification to a specific communication channel, typically to alert participants about events, messages, or status changes within the Meeting Place system.

Parameters

    notificationToken
    string
    Required
  The notification token of a channel to be notified.

    did
    string
    Required
  The DID of the recipient of the notification.

    type
    string
    Required
  The type of channel to be notified.

#### QueryOfferCommand

The command to query an offer. This command is used to retrieve information about a specific offer.

Parameters

    mnemonic
    string
    Required
  A unique identifier. This can be generated using Uuid().v4();.

#### RegisterDeviceCommand

The command to register a device. This command is used to register a user’s device for receiving notifications.

Parameters

    deviceToken
    string
    Required
  A unique string that represents a user’s device.

    platformType
    object
    Required
  Represents the Operating System of the user’s device. (Android - FCM, iOS - APNS, Web - Web Push).

#### RegisterNotificationCommand

The command to register notification. This command is used to register a notification token to enable notifications between two specific participants in a communication channel.

Parameters

    myDid
    string
    Required
  Represents the current user’s DID.

    theirDid
    string
    Required
  Represents a DID of another party.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

#### RegisterOfferCommand

The command to register an offer. This command is used to create and publish a connection offer that other participants can claim to establish a secure connection.

Parameters

    offerName
    string
    Required
  The name of the offer displayed to other users when claiming an offer.

    contactCard
    ContactCard
    Required
  An object that represents your profile in the offer.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    oobInvitationMessage
    object
    Required
  An object that represents an Out-Of-Band invitation message.

    offerDescription
    string
    Optional
  A string providing additional descriptive information about the offer.

    validUntil
    DateTime
    Optional
  The date and time until which the offer remains valid.

    maximumUsage
    int
    Optional
  The maximum number of times an offer can be claimed by other users.

    customPhrase
    string
    Optional
  A string representing the phrase that will be published with the offer.

    mediatorDid
    string
    Optional
  The mediator DID.

#### RegisterOfferGroupCommand

The command to register a group offer. This command is used to create and publish a connection offer for joining a group chat that other participants can claim to establish a secure connection.

Parameters

    offerName
    string
    Required
  The name of the offer displayed to other users when claiming a group offer.

    contactCard
    ContactCard
    Required
  An object that represents the profile of a group.

    device
    object
    Required
  An object which defines the deviceToken [string] and platformType [object].

    oobInvitationMessage
    object
    Required
  An object that represents an Out-Of-Band invitation message.

    offerDescription
    string
    Optional
  A string providing additional descriptive information about the group offer.

    validUntil
    DateTime
    Optional
  The date and time until which the offer remains valid.

    maximumUsage
    int
    Optional
  The maximum number of times an offer can be claimed by other users.

    customPhrase
    string
    Optional
  A string representing the phrase that will be published with the offer.

    mediatorDid
    string
    Optional
  The mediator DID.

    mediatorEndpoint
    string
    Optional
  The mediator’s endpoint used in the group offer to be registered.

    mediatorWSSEndpoint
    string
    Optional
  The mediator’s websocket endpoint used in the group offer to be registered.

    metadata
    string
    Optional
  Optional additional information or data associated with the group offer.

    adminDid
    string
    Optional
  The group admin’s DID.

    adminPublicKey
    string
    Optional
  The group admin’s public key.

    adminReencryptionKey
    string
    Optional
  The group admin’s re-encryption key.

#### ValidateOfferPhraseCommand

The command to validate the offer phrase. This command is used to check if a given phrase is valid for an offer.

Parameters

    phrase
    string
    Required
  A string representing the phrase to be validated.

