@budibase/frontend-core 2.6.19-alpha.36 → 2.6.19-alpha.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "2.6.19-alpha.
|
|
3
|
+
"version": "2.6.19-alpha.38",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
7
7
|
"svelte": "src/index.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@budibase/bbui": "2.6.19-alpha.
|
|
10
|
-
"@budibase/shared-core": "2.6.19-alpha.
|
|
9
|
+
"@budibase/bbui": "2.6.19-alpha.38",
|
|
10
|
+
"@budibase/shared-core": "2.6.19-alpha.38",
|
|
11
11
|
"dayjs": "^1.11.7",
|
|
12
12
|
"lodash": "^4.17.21",
|
|
13
13
|
"socket.io-client": "^4.6.1",
|
|
14
14
|
"svelte": "^3.46.2"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "67e4eb65b65c13813fbbb5e21e180234e3328755"
|
|
17
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { get } from "svelte/store"
|
|
2
2
|
import { createWebsocket } from "../../../utils"
|
|
3
|
+
import { SocketEvent, GridSocketEvent } from "@budibase/shared-core"
|
|
3
4
|
|
|
4
5
|
export const createGridWebsocket = context => {
|
|
5
6
|
const { rows, tableId, users, focusedCellId, table } = context
|
|
@@ -10,13 +11,13 @@ export const createGridWebsocket = context => {
|
|
|
10
11
|
return
|
|
11
12
|
}
|
|
12
13
|
// Identify which table we are editing
|
|
13
|
-
socket.emit(
|
|
14
|
+
socket.emit(GridSocketEvent.SelectTable, tableId, response => {
|
|
14
15
|
// handle initial connection info
|
|
15
16
|
users.set(response.users)
|
|
16
17
|
})
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
//
|
|
20
|
+
// Built-in events
|
|
20
21
|
socket.on("connect", () => {
|
|
21
22
|
connectToTable(get(tableId))
|
|
22
23
|
})
|
|
@@ -25,25 +26,25 @@ export const createGridWebsocket = context => {
|
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
// User events
|
|
28
|
-
socket.on(
|
|
29
|
+
socket.on(SocketEvent.UserUpdate, user => {
|
|
29
30
|
users.actions.updateUser(user)
|
|
30
31
|
})
|
|
31
|
-
socket.on(
|
|
32
|
+
socket.on(SocketEvent.UserDisconnect, user => {
|
|
32
33
|
users.actions.removeUser(user)
|
|
33
34
|
})
|
|
34
35
|
|
|
35
36
|
// Row events
|
|
36
|
-
socket.on(
|
|
37
|
+
socket.on(GridSocketEvent.RowChange, async data => {
|
|
37
38
|
if (data.id) {
|
|
38
39
|
rows.actions.replaceRow(data.id, data.row)
|
|
39
40
|
} else if (data.row.id) {
|
|
40
|
-
// Handle users table edge
|
|
41
|
+
// Handle users table edge cased
|
|
41
42
|
await rows.actions.refreshRow(data.row.id)
|
|
42
43
|
}
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
// Table events
|
|
46
|
-
socket.on(
|
|
47
|
+
socket.on(GridSocketEvent.TableChange, data => {
|
|
47
48
|
// Only update table if one exists. If the table was deleted then we don't
|
|
48
49
|
// want to know - let the builder navigate away
|
|
49
50
|
if (data.table) {
|
|
@@ -56,7 +57,7 @@ export const createGridWebsocket = context => {
|
|
|
56
57
|
|
|
57
58
|
// Notify selected cell changes
|
|
58
59
|
focusedCellId.subscribe($focusedCellId => {
|
|
59
|
-
socket.emit(
|
|
60
|
+
socket.emit(GridSocketEvent.SelectCell, $focusedCellId)
|
|
60
61
|
})
|
|
61
62
|
|
|
62
63
|
return () => socket?.disconnect()
|
|
@@ -51,9 +51,9 @@ export const deriveStores = context => {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const removeUser =
|
|
54
|
+
const removeUser = sessionId => {
|
|
55
55
|
users.update(state => {
|
|
56
|
-
return state.filter(x => x.sessionId !==
|
|
56
|
+
return state.filter(x => x.sessionId !== sessionId)
|
|
57
57
|
})
|
|
58
58
|
}
|
|
59
59
|
|
package/src/utils/websocket.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { io } from "socket.io-client"
|
|
2
|
+
import { SocketEvent, SocketSessionTTL } from "@budibase/shared-core"
|
|
2
3
|
|
|
3
|
-
export const createWebsocket = path => {
|
|
4
|
+
export const createWebsocket = (path, heartbeat = true) => {
|
|
4
5
|
if (!path) {
|
|
5
6
|
throw "A websocket path must be provided"
|
|
6
7
|
}
|
|
@@ -10,7 +11,7 @@ export const createWebsocket = path => {
|
|
|
10
11
|
const proto = tls ? "wss:" : "ws:"
|
|
11
12
|
const host = location.hostname
|
|
12
13
|
const port = location.port || (tls ? 443 : 80)
|
|
13
|
-
|
|
14
|
+
const socket = io(`${proto}//${host}:${port}`, {
|
|
14
15
|
path,
|
|
15
16
|
// Cap reconnection attempts to 3 (total of 15 seconds before giving up)
|
|
16
17
|
reconnectionAttempts: 3,
|
|
@@ -23,4 +24,18 @@ export const createWebsocket = path => {
|
|
|
23
24
|
// will only work with sticky sessions which we don't have
|
|
24
25
|
transports: ["websocket"],
|
|
25
26
|
})
|
|
27
|
+
|
|
28
|
+
// Set up a heartbeat that's half of the session TTL
|
|
29
|
+
let interval
|
|
30
|
+
if (heartbeat) {
|
|
31
|
+
interval = setInterval(() => {
|
|
32
|
+
socket.emit(SocketEvent.Heartbeat)
|
|
33
|
+
}, SocketSessionTTL * 500)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
socket.on("disconnect", () => {
|
|
37
|
+
clearInterval(interval)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return socket
|
|
26
41
|
}
|