Skip to content

Commit 9ed1494

Browse files
authored
feat: allow to amend Atmosphere configuration (#1959) (CP: 1.4) (#1983)
1 parent c67ef47 commit 9ed1494

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

packages/ts/frontend/src/Connect.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ export interface ConnectClientOptions {
214214
* The `middlewares` property value.
215215
*/
216216
middlewares?: Middleware[];
217+
218+
/**
219+
* The Atmosphere options for the FluxConnection.
220+
*/
221+
atmosphereOptions?: Partial<Atmosphere.Request>;
217222
}
218223

219224
export interface EndpointCallMetaInfo {
@@ -315,6 +320,10 @@ export class ConnectClient {
315320
* The Hilla endpoint prefix
316321
*/
317322
prefix = '/connect';
323+
/**
324+
* The Atmosphere options for the FluxConnection.
325+
*/
326+
atmosphereOptions: Partial<Atmosphere.Request> = {};
318327

319328
/**
320329
* The array of middlewares that are invoked during a call.
@@ -335,6 +344,10 @@ export class ConnectClient {
335344
this.middlewares = options.middlewares;
336345
}
337346

347+
if (options.atmosphereOptions) {
348+
this.atmosphereOptions = options.atmosphereOptions;
349+
}
350+
338351
// add connection indicator to DOM
339352
ConnectionIndicator.create();
340353

@@ -479,7 +492,7 @@ export class ConnectClient {
479492
*/
480493
get fluxConnection(): FluxConnection {
481494
if (!this._fluxConnection) {
482-
this._fluxConnection = new FluxConnection(this.prefix);
495+
this._fluxConnection = new FluxConnection(this.prefix, this.atmosphereOptions);
483496
}
484497
return this._fluxConnection;
485498
}

packages/ts/frontend/src/FluxConnection.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ export class FluxConnection extends EventTarget {
3535
state: State = State.INACTIVE;
3636
private pendingMessages: ServerMessage[] = [];
3737

38-
constructor(connectPrefix: string) {
38+
constructor(connectPrefix: string, atmosphereOptions?: Partial<Atmosphere.Request>) {
3939
super();
4040
if (!(window as any).Vaadin?.featureFlags?.hillaPush) {
4141
// Remove when removing feature flag
4242
throw new Error(
4343
`Push support in Hilla is not enabled. Enable it in the debug window or by adding com.vaadin.experimental.hillaPush=true to vaadin-featureflags.properties`,
4444
);
4545
}
46-
this.connectWebsocket(connectPrefix.replace(/connect$/, ''));
46+
this.connectWebsocket(connectPrefix.replace(/connect$/, ''), atmosphereOptions ?? {});
4747
}
4848

49-
private connectWebsocket(prefix: string) {
49+
private connectWebsocket(prefix: string, atmosphereOptions: Partial<Atmosphere.Request>) {
5050
const extraHeaders = getCsrfTokenHeadersForEndpointRequest(document);
5151
const callback = {
5252
onMessage: (response: any) => {
@@ -92,6 +92,7 @@ export class FluxConnection extends EventTarget {
9292
enableProtocol: true,
9393
headers: extraHeaders,
9494
...callback,
95+
...atmosphereOptions,
9596
});
9697
}
9798

0 commit comments

Comments
 (0)