Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google app scripts and websocket?

Can a websocket connection be made in Google app scripts? I wasn't able to find anything about these in Google's documentation, so I am unsure.

like image 845
prothan Avatar asked Dec 28 '16 23:12

prothan


2 Answers

The answer is (sadly) still NO.

However, you can star this feature on apps script's issue tracker here - https://issuetracker.google.com/issues/117437427

You can however poll server-side functions using client-side asynchronous JavaScript API using google.script.run. More on it could be found here - https://developers.google.com/apps-script/guides/html/reference/run

like image 57
Sourabh Choraria Avatar answered Nov 08 '22 19:11

Sourabh Choraria


Just adding to Sourabh's answer, although you can't directly use websocket through Google Scripts, you can use it with Javascript.

https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

In order to use this, you need to create an html in which you can create your websocket.

https://developers.google.com/apps-script/guides/html/

For example:

<!DOCTYPE html>
<html>

<head>
    <title>WebSocket demo</title>
</head>

<body>
    <script>
        let ws = new WebSocket("ws:port");
        ws.onopen = () => ws.send("some message to send); // Sending a message
        ws.onmessage = (event) => google.script.run.some_function(event.data); // Receiving a message
    </script>
</body>

</html>

So you could either make a web app with google or just an html window with google scripts and embed the websocket in it.

like image 39
Felipe Gomes Pontes Avatar answered Nov 08 '22 20:11

Felipe Gomes Pontes