-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjs.go
executable file
·57 lines (55 loc) · 1.67 KB
/
js.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
//
// Code generated by: scripts/embed_js/main.go
// DO NOT EDIT. Run go generate instead.
//
//
package modulir
// Source: websocket.js
const websocketJS = "function connect() {\n" +
" var url = \"ws://localhost:{{.Port}}/websocket\";\n" +
"\n" +
" console.log(`Connecting to Modulir: ${url}`);\n" +
" var socket = new WebSocket(url);\n" +
"\n" +
" socket.onclose = function(event) {\n" +
" console.log(\"Websocket connection closed or unable to connect; starting reconnect timeout\");\n" +
"\n" +
" // Allow the last socket to be cleaned up.\n" +
" socket = null;\n" +
"\n" +
" // Set an interval to continue trying to reconnect periodically until we\n" +
" // succeed.\n" +
" setTimeout(function() {\n" +
" connect();\n" +
" }, 5000)\n" +
" }\n" +
"\n" +
" socket.onmessage = function(event) {\n" +
" console.log(`Received event of type '${event.type}' data: ${event.data}`);\n" +
"\n" +
" var data = JSON.parse(event.data);\n" +
"\n" +
" switch(data.type) {\n" +
" case \"build_complete\":\n" +
" // 1000 = \"Normal closure\" and the second parameter is a human-readable\n" +
" // reason.\n" +
" socket.close(1000, \"Reloading page after receiving build_complete\");\n" +
"\n" +
" console.log(\"Reloading page after receiving build_complete\");\n" +
" location.reload(true);\n" +
"\n" +
" break;\n" +
"\n" +
" default:\n" +
" console.log(`Don't know how to handle type '${data.type}'`);\n" +
" }\n" +
" }\n" +
"\n" +
" socket.onopen = function(event) {\n" +
" console.log(\"Websocket connected\");\n" +
" }\n" +
"}\n" +
"\n" +
"connect();\n" +
""