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

Feature Request: Long-lived connections Support #3

Open
HereOrCode opened this issue Mar 20, 2024 · 1 comment
Open

Feature Request: Long-lived connections Support #3

HereOrCode opened this issue Mar 20, 2024 · 1 comment

Comments

@HereOrCode
Copy link

Hi,

This library is excellent; using it has greatly improved the efficiency of developing.

Is there any plan support for long-lived connections?

Some scenarios require the use of long-lived connections.


https://developer.chrome.com/docs/extensions/develop/concepts/messaging#connect

// content-script.js:

var port = chrome.runtime.connect({name: "knockknock"});
port.postMessage({joke: "Knock knock"});
port.onMessage.addListener(function(msg) {
  if (msg.question === "Who's there?")
    port.postMessage({answer: "Madame"});
  else if (msg.question === "Madame who?")
    port.postMessage({answer: "Madame... Bovary"});
});

// background.js
chrome.runtime.onConnect.addListener(function(port) {
  console.assert(port.name === "knockknock");
  port.onMessage.addListener(function(msg) {
    if (msg.joke === "Knock knock")
      port.postMessage({question: "Who's there?"});
    else if (msg.answer === "Madame")
      port.postMessage({question: "Madame who?"});
    else if (msg.answer === "Madame... Bovary")
      port.postMessage({question: "I don't get it."});
  });
});
@sneas
Copy link
Contributor

sneas commented Mar 20, 2024

Hey mate, thank you for your kind words. I'm glad that this library is helping not only me but also others.

I created it to scratch my itch. I have never needed long-lived connections. But I love TS and type-safety, so adding this functionality will be a lovely exercise 😋

I can't promise to add it quickly because I'm on vacation right now, but I'll try to dedicate some time to it in the upcoming weeks.

Thanks for starring this lib ❤️

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

No branches or pull requests

2 participants