Skip to content

Commit

Permalink
Add context and connectionInstance to connected payload
Browse files Browse the repository at this point in the history
  • Loading branch information
canadaduane committed May 19, 2023
1 parent 4c8d33b commit 176179b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/server/src/Hocuspocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,12 @@ export class Hocuspocus {
incoming.emit('message', input)
})

this.hooks('connected', { ...hookPayload, documentName })
this.hooks('connected', {
...hookPayload,
documentName,
context,
connectionInstance: instance,
})
}

// This listener handles authentication messages and queues everything else.
Expand Down
16 changes: 15 additions & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export interface onStatelessPayload {
payload: string,
}

// @todo Change 'connection' to 'connectionConfig' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface onAuthenticatePayload {
documentName: string,
instance: Hocuspocus,
Expand All @@ -164,6 +166,8 @@ export interface onAuthenticatePayload {
connection: ConnectionConfiguration
}

// @todo Change 'connection' to 'connectionConfig' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface onConnectPayload {
documentName: string,
instance: Hocuspocus,
Expand All @@ -174,16 +178,22 @@ export interface onConnectPayload {
connection: ConnectionConfiguration
}

// @todo Change 'connection' to 'connectionConfig', and 'connectionInstance' to 'connection' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface connectedPayload {
context: any,
documentName: string,
instance: Hocuspocus,
request: IncomingMessage,
requestHeaders: IncomingHttpHeaders,
requestParameters: URLSearchParams,
socketId: string,
connection: ConnectionConfiguration
connection: ConnectionConfiguration,
connectionInstance: Connection
}

// @todo Change 'connection' to 'connectionConfig' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface onLoadDocumentPayload {
context: any,
document: Document,
Expand All @@ -195,6 +205,8 @@ export interface onLoadDocumentPayload {
connection: ConnectionConfiguration
}

// @todo Change 'connection' to 'connectionConfig' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface afterLoadDocumentPayload {
context: any,
document: Document,
Expand Down Expand Up @@ -269,6 +281,8 @@ export interface onAwarenessUpdatePayload {

export type StatesArray = { clientId: number, [key: string | number]: any }[]

// @todo Change 'connection' to 'connectionConfig' in next major release
// see https://github.com/ueberdosis/hocuspocus/pull/607#issuecomment-1553559805
export interface fetchPayload {
context: any,
document: Document,
Expand Down

0 comments on commit 176179b

Please sign in to comment.