Search code examples
socketsgoogle-apps-scriptgoogle-apps

Emit data to all clients on a Google Web App


I have a Google Apps Script bound to a Google Sheet, and have published that as a Web App. It is restricted to a certain Google Workspace. That Google Sheet is kind of an improvised database for that web app and changes over time. I would like to send the updated data to all clients once the Google sheet gets changed. Is that possible? I don't need a trigger for the edit, since I know in the script when I add new data, so this is the time to send the new data.

Basically the same question can be formulated as follows: We know that we can execute a server-side function from the client with google.script.run, but is it also possible to execute a client-side function from the server i.e. the apps script?

My current workaround is a client-side setInterval which checks for server-side updates (and fetches them using successHandler) every 30 seconds or so. It works, but is not optimal.


Solution

  • Just to mark this one as answered. Cooper writes in the comments:

    "It's not possible to execute a client side function from the server unless it has been first initiated by the client and it's responding with a callback. Polling is your only option I think."