> ## Documentation Index
> Fetch the complete documentation index at: https://docs.iinkedsign.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Embed messaging

> Learn how to handle messages sent from an embedded signing or package editor.

## Overview

When embedding the package editor or package signing, the embedded frame will send messages to the parent window that can be used to control
your workflow and help with debugging during your integration.

## Handling embed messages

To handle messages sent from the embedded frame, you need to listen for the `message` event on the `window` object.
The event object contains information about the message, including the action being performed.

```javascript theme={null}
window.addEventListener("message", (event) => {
    // Validate origin
    if (event.origin !== "https://sign.syngrafii.com" || !event.data) return;

    // Handle action
    switch (event.data.action) {
        case "package_close":
            // User has closed the package editor. You should continue with your workflow.
            break;
        case "package_send":
            // User has sent the package and closed the package editor. You should continue with your workflow.
            break;
        case "session_expired":
            // User session has expired. The package editor will show an Expired Session message
            break;
    }
}, false);
```

<Tip>
  You should always validate the origin of the message before processing it to ensure it comes from a trusted source.
</Tip>

## Embed message

<ParamField body="source" type="string">
  The source of the message, which can be used to customize your workflow.

  | Source             | Description                                                                                                                                           |
  | :----------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- |
  | syngrafii-app      | Message was sent from the `Package Editor` or `Video Signing Room` app.                                                                               |
  | syngrafii-sign-app | Message was sent from the `Sign` app. The `Sign` app is also embedded in the `Video Signing Room` app, so you can receive messages from both sources. |
  | syngrafii-embed    | This source is used to **send** `embed_position` messages to `Video Signing Room` embedded signings.                                                  |
</ParamField>

<ParamField body="action" type="string">
  The action being performed.

  | Action               | Description                                                                                                      |
  | :------------------- | :--------------------------------------------------------------------------------------------------------------- |
  | package\_add         | User has added a new package.                                                                                    |
  | package\_cancel      | User has cancelled any changes to the package. They are still in the package editor.                             |
  | package\_close       | User has closed the package editor. You should continue with your workflow.                                      |
  | package\_open        | The package has been opened by the package editor.                                                               |
  | package\_save        | User has saved any changes to the package. They are still in the package editor.                                 |
  | package\_send        | User has sent the package and closed the package editor. You should continue with your workflow.                 |
  | meeting\_end         | Host has ended VSR meeting session.                                                                              |
  | meeting\_joining     | User is joining VSR meeting session.                                                                             |
  | meeting\_join        | User has joined VSR meeting session.                                                                             |
  | meeting\_start       | Host has started VSR meeting session.                                                                            |
  | signing\_changed     | User has modified signing; you can use this to track dirty state of signing and prevent navigation.              |
  | signing\_close       | User has closed signing and was redirected to /notsent page.                                                     |
  | signing\_finalize    | User has finalized current document.                                                                             |
  | signing\_ignore      | User has ignored save changes warning dialog.                                                                    |
  | signing\_next        | User has opened next document for signing.                                                                       |
  | signing\_open        | User has opened document for signing.                                                                            |
  | signing\_return      | User has completed or closed signing and was redirected back to packages list.                                   |
  | signing\_return\_url | User has completed or closed signing and was redirected back to returnUrl.                                       |
  | signing\_save        | User has saved signing progress; you can use this to track dirty state of signing and allow navigation.          |
  | signing\_sent        | User has completed signing all documents and was redirected to /sent page.                                       |
  | session\_expired     | User session has expired. The package editor will show an Expired Session message.                               |
  | session\_expiring    | User session is about to expire due to inactivity. They will be presented with a dialog to extend their session. |
  | session\_extended    | User session was extended by user.                                                                               |

  {/* 
    | package_convert     | The package is being converted. |
    | package_delete      | The package is being deleted. |
    | package_duplicate   | The package is being duplicated. |
    | package_rescind     | User has rescinded the package. |
    */}
</ParamField>

<ParamField body="data" type="object">
  Additional data related to the action being performed. The structure of this object may vary depending on the action.
</ParamField>

<ParamField body="failed" type="boolean">
  Indicates whether the action failed.
</ParamField>

<ParamField body="error" type="string" post={["nullable"]}>
  The error code if the action failed. This field is only present when `failed` is `true`.

  See the [Errors guide](/v4/guides/errors) for more information.
</ParamField>
