Skip to content

Commit

Permalink
Allow creating HocuspocusProvider without passing a websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
janthurau committed Mar 27, 2023
1 parent 69b6ebe commit d93200e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/provider/src/HocuspocusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ import {
onSyncedParameters,
WebSocketStatus,
} from './types'
import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket'
import {
CompleteHocuspocusProviderWebsocketConfiguration,
HocuspocusProviderWebsocket,
} from './HocuspocusProviderWebsocket'
import { StatelessMessage } from './OutgoingMessages/StatelessMessage'
import { CloseMessage } from './OutgoingMessages/CloseMessage'
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.'

export type HocuspocusProviderConfiguration =
Required<Pick<CompleteHocuspocusProviderConfiguration, 'name' | 'websocketProvider'>>
& Partial<CompleteHocuspocusProviderConfiguration>
Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>>
& Partial<CompleteHocuspocusProviderConfiguration> & (
Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> |
Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>
)

export interface CompleteHocuspocusProviderConfiguration {
/**
Expand Down Expand Up @@ -206,6 +212,10 @@ export class HocuspocusProvider extends EventEmitter {
}

public setConfiguration(configuration: Partial<HocuspocusProviderConfiguration> = {}): void {
if (!configuration.websocketProvider && (configuration as CompleteHocuspocusProviderWebsocketConfiguration).url) {
this.configuration.websocketProvider = new HocuspocusProviderWebsocket({ url: (configuration as CompleteHocuspocusProviderWebsocketConfiguration).url })
}

this.configuration = { ...this.configuration, ...configuration }
}

Expand Down

0 comments on commit d93200e

Please sign in to comment.