lightninglabs / lnc-web

Lightning Node Connect npm module for web
https://docs.lightning.engineering/lightning-network-tools/lightning-terminal/lnc-npm
48 stars 18 forks source link

Is it possible to use lnc-web inside a Service Worker? #88

Closed secondl1ght closed 1 year ago

secondl1ght commented 1 year ago

My use-case would be to use subscribeInvoices inside the worker to show Notifications to the user when they receive a new invoice. I have read that placing Notification functionality inside the Service Worker might be good so that the Notifications are shown even when the web app is not visible.

jamaljsr commented 1 year ago

This is a good question. I believe it should work but have not tested this scenario explicitly. If you give it a shot and run into any issues, please let us know so we can work on getting it resolved.

secondl1ght commented 1 year ago

Ok I did a bit more research and it looks like you can't use websockets inside a Service Worker so I don't think the current stream methods will work. It does looks like there is a way to 'push' updates to a web app from a server using the Push API inside the SW. Some more details about this are here: https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Tutorials/js13kGames/Re-engageable_Notifications_Push

LNC is entirely based on websockets though right? So maybe it is not possible to use it inside a SW without a major upgrade to support websocket and non-websocket requests to the server, in order to support advanced PWA functionality like push message notifications.

jamaljsr commented 1 year ago

Ah, yes the LNC communication is done over websockets. It will not work without that. It would likely be a pretty substantial overhaul to support non-websocket requests to the backend. That would need to be done in the lightning-node-connect repo.

secondl1ght commented 1 year ago

Ok sounds good, maybe something to consider adding to the potential roadmap if you guys think it is worth the effort. For now devs can build their LNC Web apps without this functionality and add it later on if it becomes supported.