@casual-simulation/aux-vm-client
Version:
A set of utilities required to securely run an AUX as a client.
52 lines • 2.78 kB
JavaScript
import { createAuxPartition, createMemoryPartition, iteratePartitions, createOtherPlayersClientPartition, createYjsPartition, createRemoteClientYjsPartition, } from '@casual-simulation/aux-common';
import { BaseAuxChannel } from '@casual-simulation/aux-vm/vm';
import { createOtherPlayersRepoPartition, createRemoteYjsPartition, createRemoteYjsSharedDocument, createTimeSyncController, } from '../partitions';
import { createSharedDocument } from '@casual-simulation/aux-common/documents/SharedDocumentFactories';
import { createYjsSharedDocument } from '@casual-simulation/aux-common/documents/YjsSharedDocument';
export class RemoteAuxChannel extends BaseAuxChannel {
constructor(config, options) {
super(config, options);
}
async _createPartition(config, services) {
return await createAuxPartition(config, services, createMemoryPartition, (config) => createOtherPlayersClientPartition(config, services.authSource), (config) => createOtherPlayersRepoPartition(config, services.authSource), (config) => createYjsPartition(config), (config) => createRemoteYjsPartition(config, services.authSource), (config) => createRemoteClientYjsPartition(config, services.authSource));
}
async _createSharedDocument(config, services) {
return await createSharedDocument(config, services, (config, services) => createRemoteYjsSharedDocument(config, services.authSource), createYjsSharedDocument);
}
_createTimeSyncController() {
var _a, _b, _c;
if ((_b = (_a = this._config) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.timesync) {
return ((_c = createTimeSyncController(this._config.config.timesync, this._authSource)) !== null && _c !== void 0 ? _c : super._createTimeSyncController());
}
return super._createTimeSyncController();
}
_handleError(error) {
if (error instanceof Error) {
super._handleError({
type: 'general',
message: error.toString(),
});
}
else {
super._handleError(error);
}
}
_handleLocalEvents(e) {
for (let event of e) {
if (event.type === 'set_offline_state') {
for (let [key, partition] of iteratePartitions(this._partitions)) {
if ('forcedOffline' in partition) {
partition.forcedOffline = event.offline;
}
}
}
}
super._handleLocalEvents(e);
}
_createSubChannel(runtime, config) {
const channel = new RemoteAuxChannel(config, this._options);
channel._runtime = runtime;
return channel;
}
}
//# sourceMappingURL=RemoteAuxChannel.js.map