@budibase/server 2.6.19-alpha.52 → 2.6.19-alpha.54

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.6.19-alpha.52",
4
+ "version": "2.6.19-alpha.54",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -46,12 +46,12 @@
46
46
  "license": "GPL-3.0",
47
47
  "dependencies": {
48
48
  "@apidevtools/swagger-parser": "10.0.3",
49
- "@budibase/backend-core": "2.6.19-alpha.52",
50
- "@budibase/client": "2.6.19-alpha.52",
51
- "@budibase/pro": "2.6.19-alpha.52",
52
- "@budibase/shared-core": "2.6.19-alpha.52",
53
- "@budibase/string-templates": "2.6.19-alpha.52",
54
- "@budibase/types": "2.6.19-alpha.52",
49
+ "@budibase/backend-core": "2.6.19-alpha.54",
50
+ "@budibase/client": "2.6.19-alpha.54",
51
+ "@budibase/pro": "2.6.19-alpha.54",
52
+ "@budibase/shared-core": "2.6.19-alpha.54",
53
+ "@budibase/string-templates": "2.6.19-alpha.54",
54
+ "@budibase/types": "2.6.19-alpha.54",
55
55
  "@bull-board/api": "3.7.0",
56
56
  "@bull-board/koa": "3.9.4",
57
57
  "@elastic/elasticsearch": "7.10.0",
@@ -195,5 +195,5 @@
195
195
  }
196
196
  }
197
197
  },
198
- "gitHead": "77a332e4cedddef2472c9aa5aa28e206ae560090"
198
+ "gitHead": "289e75e4a571a8276dcb2776ea66dcef76184785"
199
199
  }
@@ -5,7 +5,7 @@ import http from "http"
5
5
  import Koa from "koa"
6
6
  import { Datasource, Table, SocketSession, ContextUser } from "@budibase/types"
7
7
  import { gridSocket } from "./index"
8
- import { clearLock } from "../utilities/redis"
8
+ import { clearLock, updateLock } from "../utilities/redis"
9
9
  import { Socket } from "socket.io"
10
10
  import { BuilderSocketEvent } from "@budibase/shared-core"
11
11
 
@@ -16,7 +16,7 @@ export default class BuilderSocket extends BaseSocket {
16
16
 
17
17
  async onConnect(socket?: Socket) {
18
18
  // Initial identification of selected app
19
- socket?.on(BuilderSocketEvent.SelectApp, async (appId, callback) => {
19
+ socket?.on(BuilderSocketEvent.SelectApp, async ({ appId }, callback) => {
20
20
  await this.joinRoom(socket, appId)
21
21
 
22
22
  // Reply with all users in current room
@@ -26,7 +26,8 @@ export default class BuilderSocket extends BaseSocket {
26
26
  }
27
27
 
28
28
  async onDisconnect(socket: Socket) {
29
- // Remove app lock from this user if they have no other connections
29
+ // Remove app lock from this user if they have no other connections,
30
+ // and transfer it to someone else if possible
30
31
  try {
31
32
  // @ts-ignore
32
33
  const session: SocketSession = socket.data
@@ -36,9 +37,26 @@ export default class BuilderSocket extends BaseSocket {
36
37
  return _id === otherSession._id && sessionId !== otherSession.sessionId
37
38
  })
38
39
  if (!hasOtherSession && room) {
40
+ // Clear the lock from this user since they had no other sessions
39
41
  // @ts-ignore
40
42
  const user: ContextUser = { _id: socket.data._id }
41
43
  await clearLock(room, user)
44
+
45
+ // Transfer lock ownership to the next oldest user
46
+ let otherSessions = sessions.filter(x => x._id !== _id).slice()
47
+ otherSessions.sort((a, b) => {
48
+ return a.connectedAt < b.connectedAt ? -1 : 1
49
+ })
50
+ const nextSession = otherSessions[0]
51
+ if (nextSession) {
52
+ const { _id, email, firstName, lastName } = nextSession
53
+ // @ts-ignore
54
+ const nextUser: ContextUser = { _id, email, firstName, lastName }
55
+ await updateLock(room, nextUser)
56
+ this.io.to(room).emit(BuilderSocketEvent.LockTransfer, {
57
+ userId: _id,
58
+ })
59
+ }
42
60
  }
43
61
  } catch (e) {
44
62
  // This is fine, just means this user didn't hold the lock
@@ -15,7 +15,7 @@ export default class GridSocket extends BaseSocket {
15
15
 
16
16
  async onConnect(socket: Socket) {
17
17
  // Initial identification of connected spreadsheet
18
- socket.on(GridSocketEvent.SelectTable, async (tableId, callback) => {
18
+ socket.on(GridSocketEvent.SelectTable, async ({ tableId }, callback) => {
19
19
  await this.joinRoom(socket, tableId)
20
20
 
21
21
  // Reply with all users in current room
@@ -24,7 +24,7 @@ export default class GridSocket extends BaseSocket {
24
24
  })
25
25
 
26
26
  // Handle users selecting a new cell
27
- socket.on(GridSocketEvent.SelectCell, cellId => {
27
+ socket.on(GridSocketEvent.SelectCell, ({ cellId }) => {
28
28
  this.updateUser(socket, { focusedCellId: cellId })
29
29
  })
30
30
  }
@@ -77,6 +77,7 @@ export class BaseSocket {
77
77
  firstName,
78
78
  lastName,
79
79
  sessionId: socket.id,
80
+ connectedAt: Date.now(),
80
81
  }
81
82
  next()
82
83
  }
@@ -173,7 +174,9 @@ export class BaseSocket {
173
174
  )
174
175
  const prunedSessionIds = sessionIds.filter((id, idx) => {
175
176
  if (!sessionsExist[idx]) {
176
- this.io.to(room).emit(SocketEvent.UserDisconnect, sessionIds[idx])
177
+ this.io.to(room).emit(SocketEvent.UserDisconnect, {
178
+ sessionId: sessionIds[idx],
179
+ })
177
180
  return false
178
181
  }
179
182
  return true
@@ -216,7 +219,9 @@ export class BaseSocket {
216
219
  }
217
220
 
218
221
  // Notify other users
219
- socket.to(room).emit(SocketEvent.UserUpdate, user)
222
+ socket.to(room).emit(SocketEvent.UserUpdate, {
223
+ user,
224
+ })
220
225
  }
221
226
 
222
227
  // Disconnects a socket from its current room
@@ -242,7 +247,7 @@ export class BaseSocket {
242
247
  )
243
248
 
244
249
  // Notify other users
245
- socket.to(room).emit(SocketEvent.UserDisconnect, sessionId)
250
+ socket.to(room).emit(SocketEvent.UserDisconnect, { sessionId })
246
251
  }
247
252
 
248
253
  // Updates a connected user's metadata, assuming a room change is not required.