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

Extend shared worker #3276

Merged
merged 52 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2fe969e
Global auth management inside shared worker
bastianjoel Feb 3, 2024
526bdb0
WIP: WorkerHttpStream
bastianjoel Feb 6, 2024
37d0d7c
Merge branch 'main' into icc-to-shared-worker
bastianjoel Feb 14, 2024
f48f28c
Add http subscription abstraction for longpolling
bastianjoel Feb 14, 2024
bc5adea
Use http subscription in stream
bastianjoel Feb 15, 2024
0450af2
Merge branch 'main' into icc-to-shared-worker
bastianjoel Feb 21, 2024
283e8e8
Use HttpStream in AutoupdateStream
bastianjoel Feb 22, 2024
94c9c1b
Longpolling
bastianjoel Feb 22, 2024
2f1da01
Longpolling stream abort
bastianjoel Feb 29, 2024
bec15cb
Longpolling error recovery
bastianjoel Feb 29, 2024
9f3ae12
Longpolling subscription tests
bastianjoel Feb 29, 2024
d2ad679
Linter fixes
bastianjoel Feb 29, 2024
53d07e0
Error handling tests
bastianjoel Mar 1, 2024
12dce66
WIP: SSE test
bastianjoel Mar 1, 2024
585951a
Test stream
bastianjoel Mar 4, 2024
686d754
Fix test sse abort
bastianjoel Mar 4, 2024
a9ac43e
SSE subscription tests
bastianjoel Mar 4, 2024
b60fd43
Define http stream test cases
bastianjoel Mar 4, 2024
2bb20c8
Stop logging token
bastianjoel Mar 4, 2024
c8f8cb7
Http stream tests
bastianjoel Mar 4, 2024
c979504
Http stream tests
bastianjoel Mar 5, 2024
feb0451
Autoupdate connection check
bastianjoel Mar 5, 2024
de7526a
Fix tests
bastianjoel Mar 5, 2024
eddf543
Fix streamStartRace
bastianjoel Mar 6, 2024
d4e0ca2
Set hideWhenUnauthenticated as default
bastianjoel Mar 6, 2024
0902ac7
Resolve handling
bastianjoel Mar 6, 2024
c0d4b1e
Longpolling warning banner
bastianjoel Mar 6, 2024
d5ef84f
Fix longpolling not passing errors
bastianjoel Mar 6, 2024
a37432a
Improve sse error handling
bastianjoel Mar 6, 2024
bf3b67b
Cleanup
bastianjoel Mar 7, 2024
1d153bb
Fix user change detection to unauthorized
bastianjoel Mar 7, 2024
02a026a
Use broadcast channel for au stream pool sendToAll
bastianjoel Mar 7, 2024
7c5b3bb
Move shared worker new-user into own worker
bastianjoel Mar 7, 2024
6bce617
Simplify auth service
bastianjoel Mar 7, 2024
a1f462d
Cleanup
bastianjoel Mar 8, 2024
d281255
Cleanup broadcast handler registration
bastianjoel Mar 8, 2024
84b0ee6
Add abstract http stream pool
bastianjoel Mar 8, 2024
fd6e4c8
Fix broadcasts in window mode
bastianjoel Mar 11, 2024
06428bf
Improve au resolve retry amount check
bastianjoel Mar 11, 2024
91e96f1
Icc via shared worker
bastianjoel Mar 11, 2024
f73f539
Fix icc stream abort not called
bastianjoel Mar 11, 2024
408a335
Fix icc endpoint urls
bastianjoel Mar 11, 2024
c8606fd
Fix unneccessary health checks
bastianjoel Mar 11, 2024
b82029d
Cleanup
bastianjoel Mar 11, 2024
7f0b233
Add auth tests
bastianjoel Mar 11, 2024
277d648
Fix connection status test spamming console
bastianjoel Mar 11, 2024
c97c5ed
Cleanup
bastianjoel Mar 11, 2024
a085bfc
Cleanup
bastianjoel Mar 11, 2024
ce8c5e9
Merge branch 'main' into icc-to-shared-worker
bastianjoel Mar 18, 2024
65b86fb
Do not send icc requests in fallback mode
bastianjoel Mar 18, 2024
2e033fe
Add stream pool endpoint check tests
bastianjoel Mar 19, 2024
0c51ec5
Merge branch 'main' into icc-to-shared-worker
bastianjoel Mar 28, 2024
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
158 changes: 158 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-simple-import-sort": "^8.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"fetch-mock": "^9.11.0",
"jasmine-core": "~4.0.0",
"js-yaml": "^4.1.0",
"karma": "~6.4.1",
Expand Down
96 changes: 67 additions & 29 deletions client/src/app/gateways/base-icc-gateway.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Directive, inject } from '@angular/core';
import { filter, Observable } from 'rxjs';

import { HttpMethod } from '../infrastructure/definitions/http';
import { SharedWorkerService } from '../openslides-main-module/services/shared-worker.service';
import { ActiveMeetingIdService } from '../site/pages/meetings/services/active-meeting-id.service';
import { CommunicationManagerService } from '../site/services/communication-manager.service';
import { WorkerResponse } from '../worker/interfaces';
import { HttpService } from './http.service';
import { HttpStreamEndpointService, HttpStreamService } from './http-stream';

const ICC_ENDPOINT = `icc`;

Expand All @@ -29,19 +29,11 @@ export abstract class BaseICCGatewayService<ICCResponseType> {
*/
protected abstract readonly sendPath: string;

private readonly healthPath: string = `${ICC_PATH}/health`;

private connectionClosingFn: (() => void) | undefined;

private get iccEndpointName(): string {
return ICC_ENDPOINT + `_` + this.serviceDescription;
}

private httpService = inject(HttpService);
private httpStreamService = inject(HttpStreamService);
protected activeMeetingIdService = inject(ActiveMeetingIdService);
private communicationManager = inject(CommunicationManagerService);
private httpEndpointService = inject(HttpStreamEndpointService);
private sharedWorker = inject(SharedWorkerService);

/**
* Can be called in the subclasses constructor after the super call.
Expand All @@ -58,35 +50,45 @@ export abstract class BaseICCGatewayService<ICCResponseType> {
}

public async connect(meetingId: number): Promise<void> {
console.log(`${this.serviceDescription}: Connect to ICC service with: meeting_id=${meetingId}`);
console.log(`${this.serviceDescription}: Subscribe to ICC service with: meeting_id=${meetingId}`);
if (!meetingId) {
throw new Error(`Cannot connect to ICC, no meeting ID was provided`);
throw new Error(`Cannot subscribe to ICC, no meeting ID was provided`);
}

if (!this.receivePath) {
throw new Error(`Cannot connect to ICC, no path was provided`);
throw new Error(`Cannot subscribe to ICC, no path was provided`);
}

this.disconnect();
this.sendConnectToWorker(meetingId);

const iccMeeting = `${ICC_PATH}${this.receivePath}?meeting_id=${meetingId}`;
this.httpEndpointService.registerEndpoint(this.iccEndpointName, iccMeeting, this.healthPath, HttpMethod.GET);
const buildStreamFn = () =>
this.httpStreamService.create<ICCResponseType>(this.iccEndpointName, {
onMessage: (response: ICCResponseType) => this.onMessage(response),
description: this.serviceDescription
});
const { closeFn } = this.communicationManager.registerStreamBuildFn(buildStreamFn);
this.connectionClosingFn = closeFn;
const onReastartSub = this.sharedWorker.restartObservable.subscribe(() => {
this.sendConnectToWorker(meetingId);
});
const msgSub = this.messageObservable(meetingId).subscribe(resp => this.onMessage(resp.content?.data));
const onClosedSub = this.closedObservable(meetingId).subscribe(() => {
this.connectionClosingFn = undefined;
onReastartSub.unsubscribe();
msgSub.unsubscribe();
onClosedSub.unsubscribe();
});
this.connectionClosingFn = () => {
onReastartSub.unsubscribe();
msgSub.unsubscribe();
onClosedSub.unsubscribe();
this.sharedWorker.sendMessage(`icc`, {
action: `disconnect`,
params: {
type: this.receivePath,
meetingId
}
} as any);
};
}

public disconnect(): void {
if (this.connectionClosingFn) {
try {
this.connectionClosingFn();
} catch (e) {
console.warn(`Was not able to properly close previous ICC connection: `, e);
}
this.connectionClosingFn();
this.connectionClosingFn = undefined;
}
}
Expand All @@ -112,4 +114,40 @@ export abstract class BaseICCGatewayService<ICCResponseType> {
await this.httpService.post<unknown>(`${ICC_PATH}${this.sendPath}`);
}
}

private sendConnectToWorker(meetingId: number): void {
this.sharedWorker.sendMessage(ICC_ENDPOINT, {
action: `connect`,
params: {
type: this.receivePath,
meetingId
}
} as any);
}

private messageObservable(meetingId: number): Observable<WorkerResponse> {
return this.sharedWorker
.listenTo(ICC_ENDPOINT)
.pipe(
filter(
data =>
data?.action === `receive-data` &&
data.content?.type === this.receivePath &&
data.content?.meeting_id === meetingId
)
);
}

private closedObservable(meetingId: number): Observable<WorkerResponse> {
return this.sharedWorker
.listenTo(ICC_ENDPOINT)
.pipe(
filter(
data =>
data?.action === `closed` &&
data.content?.type === this.receivePath &&
data.content?.meetingId === meetingId
)
);
}
}
16 changes: 0 additions & 16 deletions client/src/app/gateways/http-stream/http-stream.service.spec.ts

This file was deleted.

Loading
Loading