-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
NodeAuxChannel.ts
102 lines (91 loc) · 2.81 KB
/
NodeAuxChannel.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { AuxCausalTree } from '@casual-simulation/aux-common';
import {
LocalRealtimeCausalTree,
RealtimeCausalTree,
ADMIN_ROLE,
RemoteAction,
DeviceInfo,
RealtimeCausalTreeOptions,
} from '@casual-simulation/causal-trees';
import {
AuxConfig,
PrecalculationManager,
BaseAuxChannel,
AuxUser,
AuxHelper,
createAuxPartition,
createLocalCausalTreePartitionFactory,
createMemoryPartition,
PartitionConfig,
AuxPartition,
filterAtomFactory,
} from '@casual-simulation/aux-vm';
import { getSandbox } from './VM2Sandbox';
import { Observable, Subject } from 'rxjs';
import { createCausalRepoPartition } from '@casual-simulation/aux-vm/partitions';
export class NodeAuxChannel extends BaseAuxChannel {
private _tree: AuxCausalTree;
private _remoteEvents: Subject<RemoteAction[]>;
private _device: DeviceInfo;
get remoteEvents(): Observable<RemoteAction[]> {
return this._remoteEvents;
}
get tree() {
return this._tree;
}
constructor(
tree: AuxCausalTree,
user: AuxUser,
device: DeviceInfo,
config: AuxConfig
) {
super(user, config, {
sandboxFactory: lib => getSandbox(lib),
});
this._tree = tree;
this._device = device;
this._remoteEvents = new Subject<RemoteAction[]>();
}
protected async _createPartition(
config: PartitionConfig
): Promise<AuxPartition> {
return await createAuxPartition(
config,
createLocalCausalTreePartitionFactory(
{
treeOptions: {
filter: filterAtomFactory(() => this.helper),
},
},
this.user,
this._device
),
createMemoryPartition,
config => createCausalRepoPartition(config, this.user)
);
}
protected async _sendRemoteEvents(events: RemoteAction[]): Promise<void> {
await super._sendRemoteEvents(events);
this._remoteEvents.next(events);
}
protected _createPrecalculationManager(): PrecalculationManager {
const manager = super._createPrecalculationManager();
manager.logFormulaErrors = true;
return manager;
}
protected async _createGlobalsBot() {
await super._createGlobalsBot();
const catchAllPartition = this._config.partitions['shared'];
if (!catchAllPartition || catchAllPartition.type !== 'causal_tree') {
return;
}
if (catchAllPartition.id === 'admin') {
const globals = this.helper.globalsBot;
await this.helper.updateBot(globals, {
tags: {
'aux.whitelist.roles': [ADMIN_ROLE],
},
});
}
}
}