@hocuspocus/server
Advanced tools
Comparing version 2.7.1 to 2.8.0
@@ -1,2 +0,1 @@ | ||
import * as mutex from 'lib0/mutex'; | ||
import type { MessageEvent } from 'ws'; | ||
@@ -88,3 +87,2 @@ import { Event } from 'ws'; | ||
configuration: CompleteHocuspocusProviderWebsocketConfiguration; | ||
subscribedToBroadcastChannel: boolean; | ||
webSocket: HocusPocusWebSocket | null; | ||
@@ -98,3 +96,2 @@ webSocketHandlers: { | ||
identifier: number; | ||
mux: mutex.mutex; | ||
intervals: any; | ||
@@ -113,3 +110,2 @@ connectionAttempt: { | ||
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void; | ||
boundConnect: () => Promise<unknown>; | ||
cancelWebsocketRetry?: () => void; | ||
@@ -116,0 +112,0 @@ connect(): Promise<unknown>; |
@@ -22,2 +22,3 @@ /// <reference types="node" /> | ||
unloadImmediately: boolean; | ||
stopOnSignals: boolean; | ||
}; | ||
@@ -32,3 +33,3 @@ /** | ||
debugger: Debugger; | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => void; | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any; | ||
constructor(configuration?: Partial<Configuration>); | ||
@@ -35,0 +36,0 @@ /** |
@@ -120,2 +120,8 @@ /// <reference types="node" /> | ||
/** | ||
* the server will gracefully stop if SIGINT, SIGQUIT or SIGTERM is received. | ||
* | ||
* Set this to false if you don't want that. | ||
*/ | ||
stopOnSignals: boolean; | ||
/** | ||
* options to pass to the ydoc document | ||
@@ -122,0 +128,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
export declare const useDebounce: () => (id: string, func: Function, debounce: number, maxDebounce: number) => void; | ||
export declare const useDebounce: () => (id: string, func: Function, debounce: number, maxDebounce: number) => any; |
{ | ||
"name": "@hocuspocus/server", | ||
"description": "plug & play collaboration backend", | ||
"version": "2.7.1", | ||
"version": "2.8.0", | ||
"homepage": "https://hocuspocus.dev", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hocuspocus/common": "^2.7.1", | ||
"@hocuspocus/common": "^2.8.0", | ||
"async-lock": "^1.3.1", | ||
@@ -35,0 +35,0 @@ "kleur": "^4.1.4", |
@@ -46,2 +46,3 @@ import { IncomingMessage } from 'http' | ||
unloadImmediately: true, | ||
stopOnSignals: true, | ||
} | ||
@@ -120,2 +121,3 @@ | ||
onLoadDocument: this.configuration.onLoadDocument, | ||
afterLoadDocument: this.configuration.afterLoadDocument, | ||
beforeHandleMessage: this.configuration.beforeHandleMessage, | ||
@@ -129,2 +131,3 @@ beforeBroadcastStateless: this.configuration.beforeBroadcastStateless, | ||
onRequest: this.configuration.onRequest, | ||
afterUnloadDocument: this.configuration.afterUnloadDocument, | ||
onDisconnect: this.configuration.onDisconnect, | ||
@@ -174,2 +177,13 @@ onDestroy: this.configuration.onDestroy, | ||
if (this.configuration.stopOnSignals) { | ||
const signalHandler = async () => { | ||
await this.destroy() | ||
process.exit(0) | ||
} | ||
process.on('SIGINT', signalHandler) | ||
process.on('SIGQUIT', signalHandler) | ||
process.on('SIGTERM', signalHandler) | ||
} | ||
return new Promise((resolve: Function, reject: Function) => { | ||
@@ -291,17 +305,26 @@ this.server?.httpServer.listen({ | ||
*/ | ||
async destroy(): Promise<any> { | ||
this.server?.httpServer?.close() | ||
destroy(): Promise<any> { | ||
return new Promise(async resolve => { | ||
try { | ||
this.server?.webSocketServer?.close() | ||
this.server?.webSocketServer?.clients.forEach(client => { | ||
client.terminate() | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
this.server?.httpServer?.close() | ||
this.debugger.flush() | ||
try { | ||
await this.hooks('onDestroy', { instance: this }) | ||
this.configuration.extensions.push({ | ||
async afterUnloadDocument({ instance }) { | ||
if (instance.getDocumentsCount() === 0) resolve('') | ||
}, | ||
}) | ||
this.server?.webSocketServer?.close() | ||
this.closeConnections() | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
this.debugger.flush() | ||
await this.hooks('onDestroy', { instance: this }) | ||
}) | ||
} | ||
@@ -308,0 +331,0 @@ |
@@ -103,4 +103,9 @@ import * as decoding from 'lib0/decoding' | ||
} | ||
case MessageType.Auth: | ||
console.error('Received an authentication message on a connection that is already fully authenticated. Probably your provider has been destroyed + recreated really fast.') | ||
break | ||
default: | ||
console.error(`Unable to handle message of type ${type}: no handler defined!`) | ||
console.error(`Unable to handle message of type ${type}: no handler defined! Are your provider/server versions aligned?`) | ||
// Do nothing | ||
@@ -107,0 +112,0 @@ } |
@@ -145,2 +145,9 @@ import { | ||
/** | ||
* the server will gracefully stop if SIGINT, SIGQUIT or SIGTERM is received. | ||
* | ||
* Set this to false if you don't want that. | ||
*/ | ||
stopOnSignals: boolean, | ||
/** | ||
* options to pass to the ydoc document | ||
@@ -147,0 +154,0 @@ */ |
@@ -18,3 +18,3 @@ export const useDebounce = () => { | ||
timers.delete(id) | ||
func() | ||
return func() | ||
} | ||
@@ -21,0 +21,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
834616
145
9868
Updated@hocuspocus/common@^2.8.0