aboutsummaryrefslogtreecommitdiff
path: root/src/server/Message.ts
blob: 01a42fc688e2fb14fa51f9c82e8a064427217e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as uuid from 'uuid';
import { Point } from '../pen-gestures/ndollar';
import { serverOpType } from '../fields/ObjectField';

function GenerateDeterministicGuid(seed: string): string {
    return uuid.v5(seed, uuid.v5.URL);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class Message<T> {
    private _name: string;
    private _guid: string;

    constructor(name: string) {
        this._name = name;
        this._guid = GenerateDeterministicGuid(name);
    }

    get Name(): string {
        return this._name;
    }
    get Message(): string {
        return this._guid;
    }
}

export interface Reference {
    readonly id: string;
}

export interface Diff extends Reference {
    readonly diff: serverOpType;
}

export interface GestureContent {
    readonly points: Array<Point>;
    readonly bounds: { right: number; left: number; bottom: number; top: number; width: number; height: number };
    readonly width?: string;
    readonly color?: string;
}

export interface RoomMessage {
    readonly message: string;
    readonly room: string;
}

export namespace MessageStore {
    export const Foo = new Message<string>('Foo');
    export const Bar = new Message<string>('Bar');
    export const GetDocument = new Message<string>('Get Document');
    export const DeleteAll = new Message<unknown>('Delete All');
    export const ConnectionTerminated = new Message<string>('Connection Terminated');

    export const GesturePoints = new Message<GestureContent>('Gesture Points');

    export const GetRefField = new Message<string>('Get Ref Field');
    export const GetRefFields = new Message<string[]>('Get Ref Fields');
    export const UpdateField = new Message<Diff>('Update Ref Field');
    export const CreateDocField = new Message<Reference>('Create Ref Field');
    export const DeleteField = new Message<string>('Delete field');
    export const DeleteFields = new Message<string[]>('Delete fields');

    export const UpdateStats = new Message<string>('updatestats');
}