Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connection #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add connection #96

wants to merge 1 commit into from

Conversation

Kohart
Copy link

@Kohart Kohart commented Nov 29, 2024

Fixes #58

Add connection lost and connection established events to Penpal.

  • Parent Connection:

    • Add onConnectionLost and onConnection options to connectToChild in src/parent/connectToChild.ts.
    • Call onConnectionLost when the connection with the child is lost.
    • Call onConnection when the connection with the child is established or re-established.
  • Child Connection:

    • Add onConnectionLost and onConnection options to connectToParent in src/child/connectToParent.ts.
    • Call onConnectionLost when the connection with the parent is lost.
    • Call onConnection when the connection with the parent is established or re-established.
  • Documentation:

    • Update README.md to include onConnectionLost and onConnection options for connectToChild.
    • Update README.md to include onConnectionLost and onConnection options for connectToParent.
  • Tests:

    • Add tests in test/connectionManagement.spec.js to verify onConnectionLost and onConnection functionality for connectToChild.
    • Add tests in test/connectionManagement.spec.js to verify onConnectionLost and onConnection functionality for connectToParent.

For more details, open the Copilot Workspace session.

Fixes Aaronius#58

Add connection lost and connection established events to Penpal.

* **Parent Connection**:
  - Add `onConnectionLost` and `onConnection` options to `connectToChild` in `src/parent/connectToChild.ts`.
  - Call `onConnectionLost` when the connection with the child is lost.
  - Call `onConnection` when the connection with the child is established or re-established.

* **Child Connection**:
  - Add `onConnectionLost` and `onConnection` options to `connectToParent` in `src/child/connectToParent.ts`.
  - Call `onConnectionLost` when the connection with the parent is lost.
  - Call `onConnection` when the connection with the parent is established or re-established.

* **Documentation**:
  - Update `README.md` to include `onConnectionLost` and `onConnection` options for `connectToChild`.
  - Update `README.md` to include `onConnectionLost` and `onConnection` options for `connectToParent`.

* **Tests**:
  - Add tests in `test/connectionManagement.spec.js` to verify `onConnectionLost` and `onConnection` functionality for `connectToChild`.
  - Add tests in `test/connectionManagement.spec.js` to verify `onConnectionLost` and `onConnection` functionality for `connectToParent`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Aaronius/penpal/issues/58?shareId=XXXX-XXXX-XXXX-XXXX).
@Aaronius
Copy link
Owner

Aaronius commented Dec 4, 2024

Hi @Kohart, thanks for the pull request! If you don't mind me asking, how do you intend to use this new functionality? In other words, what action would you be taking in your application when onConnection or onConnectionLost is called?

connection.promise.then(() => {
document.body.removeChild(iframe);
});
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing for me because it times out after 5 seconds (5 seconds is the Jasmine test timeout period). I believe the test isn't completing in time because removing the iframe doesn't immediately (or even quickly) destroy the connection. The code that destroys the connection when the iframe is removed can be found in monitorIframeRemoval.ts. Notice that monitorIframeRemoval.ts only checks to see if the iframe is removed every 60 seconds. If the iframe is not found at that point, then it destroys the connection.

A somewhat naive or partial approach to address this problem would be either of these options:

However, there's a bigger question that needs to be addressed as part of #58, which is: What constitutes the connection being lost? I'll expound on this in a comment at the PR level. The solution to this failing test depends on the answer to that question.

@Aaronius
Copy link
Owner

Aaronius commented Dec 4, 2024

Before proceeding with this PR, we need to figure what constitutes a connection being lost. I'd like to hear your opinion, but let's continue that discussion in #58. It may be that wee need a heartbeat or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to detect if connection with child was lost?
2 participants