Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connection and context to connected hook payload #607

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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