Attempt to emit events that include the originator.
This commit is contained in:
parent
78afba63de
commit
52f97fbd1f
|
@ -168,7 +168,7 @@ export async function migrate(ctx: UserCtx<MigrateRequest, MigrateResponse>) {
|
|||
let result = await sdk.tables.migrate(table, oldColumn, newColumn)
|
||||
|
||||
for (let table of result.tablesUpdated) {
|
||||
builderSocket?.emitTableUpdate(ctx, table)
|
||||
builderSocket?.emitTableUpdate(ctx, table, { includeSelf: true })
|
||||
}
|
||||
|
||||
ctx.status = 200
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import authorized from "../middleware/authorized"
|
||||
import { BaseSocket } from "./websocket"
|
||||
import { BaseSocket, EmitOptions } from "./websocket"
|
||||
import { permissions, events, context } from "@budibase/backend-core"
|
||||
import http from "http"
|
||||
import Koa from "koa"
|
||||
|
@ -100,11 +100,17 @@ export default class BuilderSocket extends BaseSocket {
|
|||
})
|
||||
}
|
||||
|
||||
emitTableUpdate(ctx: any, table: Table) {
|
||||
this.emitToRoom(ctx, ctx.appId, BuilderSocketEvent.TableChange, {
|
||||
id: table._id,
|
||||
table,
|
||||
})
|
||||
emitTableUpdate(ctx: any, table: Table, options?: EmitOptions) {
|
||||
this.emitToRoom(
|
||||
ctx,
|
||||
ctx.appId,
|
||||
BuilderSocketEvent.TableChange,
|
||||
{
|
||||
id: table._id,
|
||||
table,
|
||||
},
|
||||
options
|
||||
)
|
||||
gridSocket?.emitTableUpdate(ctx, table)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,12 @@ import { SocketSession } from "@budibase/types"
|
|||
import { v4 as uuid } from "uuid"
|
||||
import { createContext, runMiddlewares } from "./middleware"
|
||||
|
||||
export interface EmitOptions {
|
||||
// Whether to include the originator of the request from the broadcast,
|
||||
// defaults to false.
|
||||
includeSelf?: boolean
|
||||
}
|
||||
|
||||
const anonUser = () => ({
|
||||
_id: uuid(),
|
||||
email: "user@mail.com",
|
||||
|
@ -270,10 +276,17 @@ export class BaseSocket {
|
|||
|
||||
// Emit an event to everyone in a room, including metadata of whom
|
||||
// the originator of the request was
|
||||
emitToRoom(ctx: any, room: string | string[], event: string, payload: any) {
|
||||
this.io.in(room).emit(event, {
|
||||
...payload,
|
||||
apiSessionId: ctx.headers?.[Header.SESSION_ID],
|
||||
})
|
||||
emitToRoom(
|
||||
ctx: any,
|
||||
room: string | string[],
|
||||
event: string,
|
||||
payload: any,
|
||||
options?: EmitOptions
|
||||
) {
|
||||
let emitPayload = { ...payload }
|
||||
if (!options?.includeSelf) {
|
||||
emitPayload.apiSessionId = ctx.headers?.[Header.SESSION_ID]
|
||||
}
|
||||
this.io.in(room).emit(event, emitPayload)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue