feat: add base implementation for realtime communication

Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Co-authored-by: Philip Molares <philip.molares@udo.edu>
Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-04-02 23:45:46 +02:00 committed by David Mehren
parent d9ef44766d
commit ce29cc0a2e
44 changed files with 2151 additions and 65 deletions

View file

@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { EventEmitter } from 'events';
import { Mock } from 'ts-mockery';
import TypedEmitter from 'typed-emitter';
import { RealtimeNote, RealtimeNoteEvents } from '../realtime-note';
import { WebsocketAwareness } from '../websocket-awareness';
import { WebsocketDoc } from '../websocket-doc';
class MockRealtimeNote extends (EventEmitter as new () => TypedEmitter<RealtimeNoteEvents>) {
constructor(
private doc: WebsocketDoc,
private awareness: WebsocketAwareness,
) {
super();
}
public getYDoc(): WebsocketDoc {
return this.doc;
}
public getAwareness(): WebsocketAwareness {
return this.awareness;
}
public removeClient(): void {
//left blank for mock
}
}
/**
* Provides a partial mock for {@link RealtimeNote}
* @param doc Defines the return value for `getYDoc`
* @param awareness Defines the return value for `getAwareness`
*/
export function mockRealtimeNote(
doc: WebsocketDoc,
awareness: WebsocketAwareness,
): RealtimeNote {
return Mock.from<RealtimeNote>(new MockRealtimeNote(doc, awareness));
}