Hi,
I want to know if there’s a way to make a backend canister written with motoko to call the frontend canister (built with node.js).
What I want to do is update my frontend page in real time based on some triggers reveived by the backend. So that when some data are updated on the backend it will call the frontend (like a notification message for example…).
I had to use http calls? Or there are other ways?
Thanks.
Last time I checked web sockets were not support yet therefore I don’t think you can push from backend to frontend directly at the moment.
There was a similar question on Discord recently, for such use case I personally choose to implement some kind of cronjob features in web workers that perdiodically queries the backend.
This - the http_request function - is commonly use to serve assets (html page, images, js, css etc.) on the web. It’s like the function that answer to the http request your browser do e.g. when you access your dapp with the browser on https://canister-id.ic0.app
It also don’t push data but respond to a query so it does not solve your original question in my opinion.
Maybe is usefull for me, 'cause what I really want is that a particular user do something and the frontend of another user is updated, more like a chatbot, probably I wasn’t clear on my original question.
Anyway for the frontend part I just use javascript with node.js.
Yes yes a chat is totally what I was thinking at. Don’t think this function is your solution nor that data can be pushed at the moment but again, if that’s wrong, please correct my saying.
JavaScript, well noted. Was asking if one day I ever wrote a blog post about running cronjob to query the IC in web workers. Thanks for the feedback.
I’ve found out, even without checking the source, that if you go to OpenChat and open the developer tool on the net tab there is a query every 5 seconds.
Looks like they poll from the window side through the service worker, sounds interesting. They are not open source right? I’ll be curious to see their implementation.